Class CommonGoogleClientRequestInitializer (2.4.1)

public class CommonGoogleClientRequestInitializer implements GoogleClientRequestInitializer

Google common client request initializer implementation for setting properties like key and userIp.

The simplest usage is to use it to set the key parameter:


 public static final GoogleClientRequestInitializer KEY_INITIALIZER =
        CommonGoogleClientRequestInitializer.newBuilder()
              .setKey(KEY)
              .build();
 

There is also a constructor to set both the key and userIp parameters:


 public static final GoogleClientRequestInitializer INITIALIZER =
 CommonGoogleClientRequestInitializer.newBuilder()
 .setKey(KEY)
 .setUserIp(USER_IP)
 .build();
 

If you want to implement custom logic, extend it like this:


 public static class MyRequestInitializer extends CommonGoogleClientRequestInitializer {

   {@literal @}Override
   public void initialize
       (AbstractGoogleClientRequest{@literal <}?{@literal>} request) throws IOException {
     // custom logic
   }
 }
 

Finally, to set the key and userIp parameters and insert custom logic, extend it like this:


 public static class MyRequestInitializer2 extends CommonGoogleClientRequestInitializer {

   public MyRequestInitializer2() {
     super(KEY, USER_IP);
   }

   {@literal @}Override
   public void initialize
       (AbstractGoogleClientRequest{@literal <}?{@literal>} request) throws IOException {
     super.initialize(request); // must be called to set the key and userIp parameters
     // insert some additional logic
   }
 }
 

Subclasses should be thread-safe.

Inheritance

java.lang.Object > CommonGoogleClientRequestInitializer

Static Methods

newBuilder()

public static CommonGoogleClientRequestInitializer.Builder newBuilder()

Returns new builder.

Returns
Type Description
CommonGoogleClientRequestInitializer.Builder

Constructors

CommonGoogleClientRequestInitializer() (deprecated)

public CommonGoogleClientRequestInitializer()

Deprecated. Please use the builder interface

CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)

protected CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)
Parameter
Name Description
builder CommonGoogleClientRequestInitializer.Builder

CommonGoogleClientRequestInitializer(String key) (deprecated)

public CommonGoogleClientRequestInitializer(String key)

Deprecated. Please use the builder interface

Parameter
Name Description
key String

API key or null to leave it unchanged

CommonGoogleClientRequestInitializer(String key, String userIp) (deprecated)

public CommonGoogleClientRequestInitializer(String key, String userIp)

Deprecated. Please use the builder interface

Parameters
Name Description
key String

API key or null to leave it unchanged

userIp String

user IP or null to leave it unchanged

Methods

getKey()

public final String getKey()

Returns the API key or null to leave it unchanged.

Returns
Type Description
String

getRequestReason()

public final String getRequestReason()

Returns the request reason or null to leave it unchanged.

Returns
Type Description
String

getUserAgent()

public final String getUserAgent()

Returns the user agent or null to leave it unchanged.

Returns
Type Description
String

getUserIp()

public final String getUserIp()

Returns the user IP or null to leave it unchanged.

Returns
Type Description
String

getUserProject()

public final String getUserProject()

Returns the user project or null.

Returns
Type Description
String

initialize(AbstractGoogleClientRequest<?> request)

public void initialize(AbstractGoogleClientRequest<?> request)

Subclasses should call super implementation in order to set the key and userIp.

Parameter
Name Description
request AbstractGoogleClientRequest<?>
Exceptions
Type Description
IOException

I/O exception