2121import com .google .maps .internal .ApiConfig ;
2222import com .google .maps .internal .ApiResponse ;
2323import com .google .maps .internal .ExceptionsAllowedToRetry ;
24+ import com .google .maps .internal .HttpHeaders ;
25+ import com .google .maps .internal .StringJoin ;
2426import com .google .maps .internal .UrlSigner ;
2527import java .io .UnsupportedEncodingException ;
2628import java .net .Proxy ;
@@ -61,6 +63,7 @@ public class GeoApiContext {
6163 private final ExceptionsAllowedToRetry exceptionsAllowedToRetry ;
6264 private final Integer maxRetries ;
6365 private final UrlSigner urlSigner ;
66+ private String experienceIdHeaderValue ;
6467
6568 /* package */
6669 GeoApiContext (
@@ -72,7 +75,8 @@ public class GeoApiContext {
7275 long errorTimeout ,
7376 ExceptionsAllowedToRetry exceptionsAllowedToRetry ,
7477 Integer maxRetries ,
75- UrlSigner urlSigner ) {
78+ UrlSigner urlSigner ,
79+ String ... experienceIdHeaderValue ) {
7680 this .requestHandler = requestHandler ;
7781 this .apiKey = apiKey ;
7882 this .baseUrlOverride = baseUrlOverride ;
@@ -82,6 +86,7 @@ public class GeoApiContext {
8286 this .exceptionsAllowedToRetry = exceptionsAllowedToRetry ;
8387 this .maxRetries = maxRetries ;
8488 this .urlSigner = urlSigner ;
89+ setExperienceId (experienceIdHeaderValue );
8590 }
8691
8792 /**
@@ -98,6 +103,7 @@ <T, R extends ApiResponse<T>> PendingResult<T> handle(
98103 String hostName ,
99104 String url ,
100105 String userAgent ,
106+ String experienceIdHeaderValue ,
101107 Class <R > clazz ,
102108 FieldNamingPolicy fieldNamingPolicy ,
103109 long errorTimeout ,
@@ -109,6 +115,7 @@ <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
109115 String url ,
110116 String payload ,
111117 String userAgent ,
118+ String experienceIdHeaderValue ,
112119 Class <R > clazz ,
113120 FieldNamingPolicy fieldNamingPolicy ,
114121 long errorTimeout ,
@@ -136,6 +143,34 @@ interface Builder {
136143 }
137144 }
138145
146+ /**
147+ * Sets the value for the HTTP header field name {@link HttpHeaders#X_GOOG_MAPS_EXPERIENCE_ID} to
148+ * be used on subsequent API calls. Calling this method with {@code null} is equivalent to calling
149+ * {@link #clearExperienceId()}.
150+ *
151+ * @param experienceId The experience ID if set, otherwise null
152+ */
153+ public void setExperienceId (String ... experienceId ) {
154+ if (experienceId == null || experienceId .length == 0 ) {
155+ experienceIdHeaderValue = null ;
156+ return ;
157+ }
158+ experienceIdHeaderValue = StringJoin .join ("," , experienceId );
159+ }
160+
161+ /** @return Returns the experience ID if set, otherwise, null */
162+ public String getExperienceId () {
163+ return experienceIdHeaderValue ;
164+ }
165+
166+ /**
167+ * Clears the experience ID if set the HTTP header field {@link
168+ * HttpHeaders#X_GOOG_MAPS_EXPERIENCE_ID} will be omitted from subsequent calls.
169+ */
170+ public void clearExperienceId () {
171+ experienceIdHeaderValue = null ;
172+ }
173+
139174 /**
140175 * Shut down this GeoApiContext instance, reclaiming resources. After shutdown() has been called,
141176 * no further queries may be done against this instance.
@@ -240,6 +275,7 @@ <T, R extends ApiResponse<T>> PendingResult<T> post(
240275 url .toString (),
241276 params .get ("_payload" ).get (0 ),
242277 USER_AGENT ,
278+ experienceIdHeaderValue ,
243279 clazz ,
244280 config .fieldNamingPolicy ,
245281 errorTimeout ,
@@ -280,6 +316,7 @@ private <T, R extends ApiResponse<T>> PendingResult<T> getWithPath(
280316 hostName ,
281317 url .toString (),
282318 USER_AGENT ,
319+ experienceIdHeaderValue ,
283320 clazz ,
284321 fieldNamingPolicy ,
285322 errorTimeout ,
@@ -312,6 +349,7 @@ public static class Builder {
312349 private ExceptionsAllowedToRetry exceptionsAllowedToRetry = new ExceptionsAllowedToRetry ();
313350 private Integer maxRetries ;
314351 private UrlSigner urlSigner ;
352+ private String [] experienceIdHeaderValue ;
315353
316354 /** Builder pattern for the enclosing {@code GeoApiContext}. */
317355 public Builder () {
@@ -533,6 +571,18 @@ public Builder proxyAuthentication(String proxyUserName, String proxyUserPasswor
533571 return this ;
534572 }
535573
574+ /**
575+ * Sets the value for the HTTP header field name {@link HttpHeaders#X_GOOG_MAPS_EXPERIENCE_ID}
576+ * HTTP header value for the field name on subsequent API calls.
577+ *
578+ * @param experienceId The experience ID
579+ * @return Returns this builder for call chaining.
580+ */
581+ public Builder experienceId (String ... experienceId ) {
582+ this .experienceIdHeaderValue = experienceId ;
583+ return this ;
584+ }
585+
536586 /**
537587 * Converts this builder into a {@code GeoApiContext}.
538588 *
@@ -548,7 +598,8 @@ public GeoApiContext build() {
548598 errorTimeout ,
549599 exceptionsAllowedToRetry ,
550600 maxRetries ,
551- urlSigner );
601+ urlSigner ,
602+ experienceIdHeaderValue );
552603 }
553604 }
554605}
0 commit comments