public class CommonGoogleClientRequestInitializer extends Object implements GoogleClientRequestInitializer
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 { @Override public void initialize(AbstractGoogleClientRequest <? > 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); } @Override public void initialize(AbstractGoogleClientRequest <? > 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.
Modifier and Type | Class and Description |
---|---|
static class |
CommonGoogleClientRequestInitializer.Builder
Builder for
CommonGoogleClientRequestInitializer . |
Modifier | Constructor and Description |
---|---|
|
CommonGoogleClientRequestInitializer()
Deprecated.
Please use the builder interface
|
protected |
CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder) |
|
CommonGoogleClientRequestInitializer(String key)
Deprecated.
Please use the builder interface
|
|
CommonGoogleClientRequestInitializer(String key,
String userIp)
Deprecated.
Please use the builder interface
|
Modifier and Type | Method and Description |
---|---|
String |
getKey()
Returns the API key or
null to leave it unchanged. |
String |
getRequestReason()
Returns the request reason or
null to leave it unchanged. |
String |
getUserAgent()
Returns the user agent or
null to leave it unchanged. |
String |
getUserIp()
Returns the user IP or
null to leave it unchanged. |
String |
getUserProject()
Returns the user project or
null . |
void |
initialize(AbstractGoogleClientRequest<?> request)
Subclasses should call super implementation in order to set the key and userIp.
|
static CommonGoogleClientRequestInitializer.Builder |
newBuilder()
Returns new builder.
|
@Deprecated public CommonGoogleClientRequestInitializer()
@Deprecated public CommonGoogleClientRequestInitializer(String key)
key
- API key or null
to leave it unchanged@Deprecated public CommonGoogleClientRequestInitializer(String key, String userIp)
key
- API key or null
to leave it unchangeduserIp
- user IP or null
to leave it unchangedprotected CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)
public static CommonGoogleClientRequestInitializer.Builder newBuilder()
public void initialize(AbstractGoogleClientRequest<?> request) throws IOException
initialize
in interface GoogleClientRequestInitializer
IOException
- I/O exceptionpublic final String getKey()
null
to leave it unchanged.public final String getUserIp()
null
to leave it unchanged.public final String getUserAgent()
null
to leave it unchanged.public final String getRequestReason()
null
to leave it unchanged.public final String getUserProject()
null
.Copyright © 2010–2021 Google. All rights reserved.