public class CommonGoogleClientRequestInitializer extends java.lang.Object implements GoogleClientRequestInitializer
The simplest usage is to use it to set the key parameter:
public static final GoogleClientRequestInitializer KEY_INITIALIZER =
new CommonGoogleClientRequestInitializer(KEY);
There is also a constructor to set both the key and userIp parameters:
public static final GoogleClientRequestInitializer INITIALIZER =
new CommonGoogleClientRequestInitializer(KEY, USER_IP);
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.
| Constructor and Description |
|---|
CommonGoogleClientRequestInitializer() |
CommonGoogleClientRequestInitializer(java.lang.String key) |
CommonGoogleClientRequestInitializer(java.lang.String key,
java.lang.String userIp) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getKey()
Returns the API key or
null to leave it unchanged. |
java.lang.String |
getUserIp()
Returns the user IP or
null to leave it unchanged. |
void |
initialize(AbstractGoogleClientRequest<?> request)
Subclasses should call super implementation in order to set the key and userIp.
|
public CommonGoogleClientRequestInitializer()
public CommonGoogleClientRequestInitializer(java.lang.String key)
key - API key or null to leave it unchangedpublic CommonGoogleClientRequestInitializer(java.lang.String key,
java.lang.String userIp)
key - API key or null to leave it unchangeduserIp - user IP or null to leave it unchangedpublic void initialize(AbstractGoogleClientRequest<?> request) throws java.io.IOException
initialize in interface GoogleClientRequestInitializerjava.io.IOException - I/O exceptionpublic final java.lang.String getKey()
null to leave it unchanged.public final java.lang.String getUserIp()
null to leave it unchanged.Copyright © 2010-2019 Google. All Rights Reserved.