Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Brantley Wells <brantleywells@gmail.com> @gitbrantley
Brett Morgan <brettmorgan@google.com> @domesticmouse
Chris Broadfoot <cbro@google.com> @broady
Dave Holmes <daveholmes@google.com> @dh--
Malcolm Windsor <malcolm@beoped.com> @mwindsor-beoped
Mark McDonald <macd@google.com> @markmcd
Nicolas Poirier <dev.nicolaspoirier@gmail.com> @NicolasPoirier
Pulkit Bhuwalka <pulkit.bosco05@gmail.com> @nutsiepully
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/google/maps/GeoApiContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class GeoApiContext {
private String apiKey;
private String clientId;
private UrlSigner urlSigner;
private String channel;
private final OkHttpClient client = new OkHttpClient();
private final RateLimitExecutorService rateLimitExecutorService;

Expand All @@ -60,6 +61,10 @@ public GeoApiContext() {

<T, R extends ApiResponse<T>> PendingResult<T> get(ApiConfig config, Class<? extends R> clazz,
Map<String, String> params) {
if(channel != null && !channel.isEmpty() && !params.containsKey("channel")){
params.put("channel", channel);
}

StringBuilder query = new StringBuilder();

for (Map.Entry<String, String> param : params.entrySet()) {
Expand All @@ -83,7 +88,11 @@ <T, R extends ApiResponse<T>> PendingResult<T> get(ApiConfig config, Class<? ext

StringBuilder query = new StringBuilder();

boolean channelSet = false;
for (int i = 0; i < params.length; i++) {
if(params[i]=="channel"){
channelSet = true;
}
query.append('&').append(params[i]).append('=');
i++;

Expand All @@ -95,6 +104,11 @@ <T, R extends ApiResponse<T>> PendingResult<T> get(ApiConfig config, Class<? ext
}
}

// Channel can be supplied per-request or per-context. We prioritize it from the request, so if it's not provided there, provide it here
if (channelSet == false && channel != null && !channel.isEmpty()) {
query.append("&channel=").append(channel);
}

return getWithPath(clazz, config.fieldNamingPolicy, config.hostName, config.path,
config.supportsClientId, query.toString());
}
Expand Down Expand Up @@ -171,6 +185,15 @@ public GeoApiContext setEnterpriseCredentials(String clientId, String cryptograp
return this;
}

/**
* Sets the default channel for requests (can be overridden by requests). Only useful for Google Maps for Work clients.
* @param channel The channel to use for analytics
*/
public GeoApiContext setChannel(String channel) {
this.channel = channel;
return this;
}

/**
* Sets the default connect timeout for new connections. A value of 0 means no timeout.
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/google/maps/PendingResultBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,15 @@ protected Map<String, String> params() {
public final A language(String language) {
return param("language", language);
}

/**
* A channel to pass with the request. channel is used by Google Maps API for Work
* users to be able to track usage across different applications with the same clientID.
* See: https://developers.google.com/maps/documentation/business/clientside/quota
*
* @param channel String to pass with the request for analytics
*/
public A channel(String channel) {
return param("channel", channel);
}
}