Skip to content

Commit

Permalink
Adding V6FeatureType.SECONDARY_ADDRESS & address_line1
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedaly16 committed Apr 18, 2024
1 parent 4a7f780 commit 7dce6ad
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 2 deletions.
Expand Up @@ -87,6 +87,7 @@ private Call<V6Response> structuredInputCall(
return getService().structureInputForwardGeocoding(
ApiCallHelper.getHeaderUserAgent(clientAppName()),
accessToken(),
options.addressLine1(),
options.addressNumber(),
options.street(),
options.block(),
Expand Down
Expand Up @@ -33,6 +33,10 @@ public abstract class V6ForwardGeocodingRequestOptions implements V6RequestOptio
@Nullable
abstract String query();

@SerializedName("address_line1")
@Nullable
abstract String addressLine1();

@SerializedName("address_number")
@Nullable
abstract String addressNumber();
Expand Down Expand Up @@ -147,6 +151,7 @@ public static V6ForwardGeocodingRequestOptions.Builder builder(
@NonNull V6StructuredInputQuery query
) {
return new $AutoValue_V6ForwardGeocodingRequestOptions.Builder()
.addressLine1(query.addressLine1())
.addressNumber(query.addressNumber())
.street(query.street())
.block(query.block())
Expand Down Expand Up @@ -186,6 +191,8 @@ public abstract static class Builder {
abstract Builder query(@NonNull String query);

// Structured input options
abstract Builder addressLine1(String addressLine1);

abstract Builder addressNumber(String addressNumber);

abstract Builder street(String street);
Expand Down
Expand Up @@ -54,6 +54,7 @@ Call<V6Response> forwardGeocoding(
*
* @param userAgent the user agent
* @param accessToken {@link MapboxV6Geocoding#accessToken()}
* @param addressLine1 {@link V6StructuredInputQuery#addressLine1()}
* @param addressNumber {@link V6StructuredInputQuery#addressNumber()}
* @param street {@link V6StructuredInputQuery#street()}
* @param block {@link V6StructuredInputQuery#block()}
Expand All @@ -77,6 +78,7 @@ Call<V6Response> forwardGeocoding(
Call<V6Response> structureInputForwardGeocoding(
@Header("User-Agent") String userAgent,
@Query("access_token") String accessToken,
@Query("address_line1") String addressLine1,
@Query("address_number") String addressNumber,
@Query("street") String street,
@Query("block") String block,
Expand Down
Expand Up @@ -19,6 +19,10 @@
@AutoValue
public abstract class V6StructuredInputQuery {

@SerializedName("address_line1")
@Nullable
abstract String addressLine1();

@SerializedName("address_number")
@Nullable
abstract String addressNumber();
Expand Down Expand Up @@ -65,6 +69,15 @@ public static V6StructuredInputQuery.Builder builder() {
@AutoValue.Builder
public abstract static class Builder {

/**
* A string including address_number and street. These values can be provided as separate
* parameters address_number and street listed below.
*
* @param addressLine1 structured input component.
* @return this builder for chaining options together
*/
public abstract Builder addressLine1(@NonNull String addressLine1);

/**
* The number associated with the house.
*
Expand Down Expand Up @@ -147,7 +160,8 @@ public abstract static class Builder {
public V6StructuredInputQuery build() {
final V6StructuredInputQuery query = autoBuild();

if (query.addressNumber() == null
if (query.addressLine1() == null
&& query.addressNumber() == null
&& query.street() == null
&& query.block() == null
&& query.place() == null
Expand Down
Expand Up @@ -84,6 +84,11 @@ private V6FeatureType() {
*/
public static final String ADDRESS = "address";

/**
* Sub-unit, suite, or lot within a single parent address. Currently available in the US only.
*/
public static final String SECONDARY_ADDRESS = "secondary_address";

/**
* Retention policy for the types.
*/
Expand All @@ -98,7 +103,8 @@ private V6FeatureType() {
NEIGHBORHOOD,
STREET,
BLOCK,
ADDRESS
ADDRESS,
SECONDARY_ADDRESS
})
public @interface FeatureType {
}
Expand Down
Expand Up @@ -157,6 +157,7 @@ public void testStructuredInputRequestParameters() throws InterruptedException,

final HttpUrl url = request.getRequestUrl();
assertEquals("/search/geocode/v6/forward", Objects.requireNonNull(url).encodedPath());
assertEquals(options.addressLine1(), url.queryParameter("address_line1"));
assertEquals(options.addressNumber(), url.queryParameter("address_number"));
assertEquals(options.street(), url.queryParameter("street"));
assertEquals(options.block(), url.queryParameter("block"));
Expand Down Expand Up @@ -192,6 +193,7 @@ public void testDefaultStructuredInputRequestParameters() throws InterruptedExce
assertEquals(geocoding.accessToken(), url.queryParameter("access_token"));
assertNull(url.queryParameter("q"));
assertEquals(structuredInputQuery.addressNumber(), url.queryParameter("address_number"));
assertNull(url.queryParameter("address_line1"));
assertNull(url.queryParameter("street"));
assertNull(url.queryParameter("block"));
assertNull(url.queryParameter("place"));
Expand Down
Expand Up @@ -68,6 +68,7 @@ public static String removeJsonWhitespaces(String json) {

public static final V6StructuredInputQuery TEST_COMPLETE_STRUCTURED_INPUT =
V6StructuredInputQuery.builder()
.addressLine1("test-address-line1")
.addressNumber("test-address-number")
.street("test-street")
.block("test-block")
Expand Down
Expand Up @@ -27,6 +27,7 @@ public void run() {
@Test
public void testStructuredInputWithAllValuesSet() {
final V6StructuredInputQuery query = V6StructuredInputQuery.builder()
.addressLine1("test-address-line1")
.addressNumber("test-address-number")
.street("test-street")
.block("test-block")
Expand All @@ -37,6 +38,7 @@ public void testStructuredInputWithAllValuesSet() {
.neighborhood("test-neighborhood")
.build();

assertEquals("test-address-line1", query.addressLine1());
assertEquals("test-address-number", query.addressNumber());
assertEquals("test-street", query.street());
assertEquals("test-block", query.block());
Expand All @@ -62,6 +64,13 @@ public void testUnspecifiedValuesAreNull() {
assertNull(queryWithAddress.locality());
assertNull(queryWithAddress.neighborhood());

final V6StructuredInputQuery queryWithAddressLine1 = V6StructuredInputQuery.builder()
.addressLine1("test-address-line1")
.build();

assertEquals("test-address-line1", queryWithAddressLine1.addressLine1());
assertNull(queryWithAddressLine1.addressNumber());

final V6StructuredInputQuery queryWithStreet = V6StructuredInputQuery.builder()
.street("test-street")
.build();
Expand Down
@@ -1,4 +1,5 @@
{
"address_line1": "test-address-line1",
"address_number": "test-address-number",
"street": "test-street",
"block": "test-block",
Expand Down

0 comments on commit 7dce6ad

Please sign in to comment.