Skip to content

Commit 987b2c9

Browse files
authored
Adding country to V6StructuredInputQuery (#1588)
1 parent 05a7bfe commit 987b2c9

File tree

8 files changed

+25
-4
lines changed

8 files changed

+25
-4
lines changed

samples/src/main/java/com/mapbox/samples/BasicV6BatchGeocoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ private static List<V6RequestOptions> requestOptions() {
3636
.street("Pennsylvania Avenue NW")
3737
.postcode("20500")
3838
.place("Washington, DC")
39+
.country("us")
3940
.build();
4041

4142
final V6ForwardGeocodingRequestOptions structuredInputOptions = V6ForwardGeocodingRequestOptions
4243
.builder(structuredInputQuery)
43-
.country("us")
4444
.build();
4545

4646
final V6ReverseGeocodingRequestOptions reverseOptions = V6ReverseGeocodingRequestOptions

samples/src/main/java/com/mapbox/samples/BasicV6StructuredInputForwardGeocoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public static void main(String[] args) {
2222
.street("15th St")
2323
.place("Washington")
2424
.postcode("20005")
25+
.country("United States")
2526
.build();
2627

2728
final V6ForwardGeocodingRequestOptions requestOptions = V6ForwardGeocodingRequestOptions
2829
.builder(query)
29-
.country("United States")
3030
.types(V6FeatureType.ADDRESS)
3131
.autocomplete(false)
3232
.build();

services-geocoding/src/main/java/com/mapbox/api/geocoding/v6/V6ForwardGeocodingRequestOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public static V6ForwardGeocodingRequestOptions.Builder builder(
159159
.region(query.region())
160160
.postcode(query.postcode())
161161
.locality(query.locality())
162-
.neighborhood(query.neighborhood());
162+
.neighborhood(query.neighborhood())
163+
.country(query.country());
163164
}
164165

165166
/**

services-geocoding/src/main/java/com/mapbox/api/geocoding/v6/V6GeocodingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Call<V6Response> forwardGeocoding(
6666
* @param permanent {@link MapboxV6Geocoding#permanent()}
6767
* @param autocomplete {@link V6ForwardGeocodingRequestOptions#autocomplete()}
6868
* @param bbox {@link V6ForwardGeocodingRequestOptions#bbox()}
69-
* @param country {@link V6ForwardGeocodingRequestOptions#country()}
69+
* @param country {@link V6StructuredInputQuery#country()}
7070
* @param language {@link V6ForwardGeocodingRequestOptions#language()}
7171
* @param limit {@link V6ForwardGeocodingRequestOptions#limit()}
7272
* @param proximity {@link V6ForwardGeocodingRequestOptions#proximity()}

services-geocoding/src/main/java/com/mapbox/api/geocoding/v6/V6StructuredInputQuery.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public abstract class V6StructuredInputQuery {
5555
@Nullable
5656
abstract String neighborhood();
5757

58+
@SerializedName("country")
59+
@Nullable
60+
abstract String country();
61+
5862
/**
5963
* Creates a new {@link V6StructuredInputQuery.Builder} object.
6064
* @return Builder object.
@@ -149,6 +153,15 @@ public abstract static class Builder {
149153
*/
150154
public abstract Builder neighborhood(@NonNull String neighborhood);
151155

156+
/**
157+
* Generally recognized countries or, in some cases like Hong Kong, an area of quasi-national
158+
* administrative status that has a designated country code under <a href="https://www.iso.org/iso-3166-country-codes.html">ISO 3166-1</a>.
159+
*
160+
* @param country structured input component.
161+
* @return this builder for chaining options together
162+
*/
163+
public abstract Builder country(@NonNull String country);
164+
152165
abstract V6StructuredInputQuery autoBuild();
153166

154167
/**
@@ -169,6 +182,7 @@ public V6StructuredInputQuery build() {
169182
&& query.postcode() == null
170183
&& query.locality() == null
171184
&& query.neighborhood() == null
185+
&& query.country() == null
172186
) {
173187
throw new ServicesException("At least one component must be non null");
174188
}

services-geocoding/src/test/java/com/mapbox/api/geocoding/v6/MapboxV6GeocodingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public void testStructuredInputRequestParameters() throws InterruptedException,
166166
assertEquals(options.postcode(), url.queryParameter("postcode"));
167167
assertEquals(options.locality(), url.queryParameter("locality"));
168168
assertEquals(options.neighborhood(), url.queryParameter("neighborhood"));
169+
assertEquals(options.country(), url.queryParameter("country"));
169170
}
170171

171172
@Test
@@ -201,6 +202,7 @@ public void testDefaultStructuredInputRequestParameters() throws InterruptedExce
201202
assertNull(url.queryParameter("postcode"));
202203
assertNull(url.queryParameter("locality"));
203204
assertNull(url.queryParameter("neighborhood"));
205+
assertNull(url.queryParameter("country"));
204206
}
205207

206208
@Test

services-geocoding/src/test/java/com/mapbox/api/geocoding/v6/V6GeocodingTestUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static String removeJsonWhitespaces(String json) {
7777
.postcode("test-postcode")
7878
.locality("test-locality")
7979
.neighborhood("test-neighborhood")
80+
.country("test-country")
8081
.build();
8182

8283

services-geocoding/src/test/java/com/mapbox/api/geocoding/v6/V6StructuredInputQueryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void testStructuredInputWithAllValuesSet() {
3636
.postcode("test-postcode")
3737
.locality("test-locality")
3838
.neighborhood("test-neighborhood")
39+
.country("test-country")
3940
.build();
4041

4142
assertEquals("test-address-line1", query.addressLine1());
@@ -47,6 +48,7 @@ public void testStructuredInputWithAllValuesSet() {
4748
assertEquals("test-postcode", query.postcode());
4849
assertEquals("test-locality", query.locality());
4950
assertEquals("test-neighborhood", query.neighborhood());
51+
assertEquals("test-country", query.country());
5052
}
5153

5254
@Test
@@ -63,6 +65,7 @@ public void testUnspecifiedValuesAreNull() {
6365
assertNull(queryWithAddress.postcode());
6466
assertNull(queryWithAddress.locality());
6567
assertNull(queryWithAddress.neighborhood());
68+
assertNull(queryWithAddress.country());
6669

6770
final V6StructuredInputQuery queryWithAddressLine1 = V6StructuredInputQuery.builder()
6871
.addressLine1("test-address-line1")

0 commit comments

Comments
 (0)