-
Notifications
You must be signed in to change notification settings - Fork 117
Directions junction view api #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f51e5d4
bfd5a93
717f1e4
3778466
2ad0056
7a0a5c4
7871fe6
97bb4bf
90933d6
c4230dd
5c3780a
80a3531
6edfd1c
aa54ecd
8cfb1f0
761bf4c
a027edc
d5fd7a3
3306864
95a8f92
b91fcaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| package com.mapbox.api.directions.v5.models; | ||
|
|
||
| import android.support.annotation.NonNull; | ||
| import android.support.annotation.Nullable; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.google.gson.TypeAdapter; | ||
| import com.mapbox.api.directions.v5.DirectionsAdapterFactory; | ||
| import com.mapbox.api.directions.v5.MapboxDirections; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Includes both plain text information that can be visualized inside your navigation application | ||
| * along with the text string broken down into {@link BannerComponents} which may or may not | ||
| * include a image url. To receive this information, your request must have | ||
| * {@link MapboxDirections#bannerInstructions()} set to true. | ||
| * | ||
| * @since 5.0.0 | ||
| */ | ||
| @AutoValue | ||
| public abstract class BannerView extends DirectionsJsonObject { | ||
|
|
||
| /** | ||
| * Create a new instance of this class by using the {@link Builder} class. | ||
| * | ||
| * @return this classes {@link Builder} for creating a new instance | ||
| * @since 5.0.0 | ||
| */ | ||
| public static Builder builder() { | ||
| return new AutoValue_BannerView.Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Plain text with all the {@link BannerComponents} text combined. | ||
| * | ||
| * @return plain text with all the {@link BannerComponents} text items combined | ||
| * @since 5.0.0 | ||
| */ | ||
| @NonNull | ||
| public abstract String text(); | ||
|
|
||
| /** | ||
| * A part or element of the {@link BannerInstructions}. | ||
| * | ||
| * @return a {@link BannerComponents} specific to a {@link LegStep} | ||
| * @since 5.0.0 | ||
| */ | ||
| @Nullable | ||
| public abstract List<BannerComponents> components(); | ||
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
kmadsen marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * This indicates the type of maneuver. | ||
| * | ||
| * @return String with type of maneuver | ||
| * @see StepManeuver.StepManeuverType | ||
| * @since 5.0.0 | ||
| */ | ||
| @Nullable | ||
| @StepManeuver.StepManeuverType | ||
| public abstract String type(); | ||
|
|
||
| /** | ||
| * This indicates the mode of the maneuver. If type is of turn, the modifier indicates the | ||
| * change in direction accomplished through the turn. If the type is of depart/arrive, the | ||
| * modifier indicates the position of waypoint from the current direction of travel. | ||
| * | ||
| * @return String with modifier | ||
| * @since 5.0.0 | ||
| */ | ||
| @Nullable | ||
| public abstract String modifier(); | ||
|
|
||
| /** | ||
| * Convert the current {@link BannerView} to its builder holding the currently assigned | ||
| * values. This allows you to modify a single property and then rebuild the object resulting in | ||
| * an updated and modified {@link BannerView}. | ||
| * | ||
| * @return a {@link BannerView.Builder} with the same values set to match the ones defined | ||
| * in this {@link BannerView} | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract BannerView.Builder toBuilder(); | ||
|
|
||
| /** | ||
| * Gson type adapter for parsing Gson to this class. | ||
| * | ||
| * @param gson the built {@link Gson} object | ||
| * @return the type adapter for this class | ||
| * @since 5.0.0 | ||
| */ | ||
| public static TypeAdapter<BannerView> typeAdapter(Gson gson) { | ||
| return new AutoValue_BannerView.GsonTypeAdapter(gson); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of this class by passing in a formatted valid JSON String. | ||
| * | ||
| * @param json a formatted valid JSON string defining a BannerText | ||
| * @return a new instance of this class defined by the values passed inside this static factory | ||
| * method | ||
| * @since 5.0.0 | ||
| */ | ||
| public static BannerView fromJson(String json) { | ||
| GsonBuilder gson = new GsonBuilder(); | ||
| gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); | ||
| return gson.create().fromJson(json, BannerView.class); | ||
| } | ||
|
|
||
| /** | ||
| * This builder can be used to set the values describing the {@link BannerView}. | ||
| * | ||
| * @since 5.0.0 | ||
| */ | ||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
|
|
||
| /** | ||
| * Plain text with all the {@link BannerComponents} text combined. | ||
| * | ||
| * @param text plain text with all the {@link BannerComponents} text items combined | ||
| * @return this builder for chaining options together | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract Builder text(@NonNull String text); | ||
|
|
||
| /** | ||
| * A part or element of the {@link BannerInstructions}. | ||
| * | ||
| * @param components a {@link BannerComponents} specific to a {@link LegStep} | ||
| * @return this builder for chaining options together | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract Builder components(List<BannerComponents> components); | ||
|
|
||
| /** | ||
| * This indicates the type of maneuver. See {@link BannerView#type()} for a full list of | ||
| * options. | ||
| * | ||
| * @param type String with type of maneuver | ||
| * @return this builder for chaining options together | ||
| * @see StepManeuver.StepManeuverType | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract Builder type(@Nullable @StepManeuver.StepManeuverType String type); | ||
kmadsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * This indicates the mode of the maneuver. If type is of turn, the modifier indicates the | ||
| * change in direction accomplished through the turn. If the type is of depart/arrive, the | ||
| * modifier indicates the position of waypoint from the current direction of travel. | ||
| * | ||
| * @param modifier String with modifier | ||
| * @return this builder for chaining options together | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract Builder modifier(@Nullable String modifier); | ||
|
|
||
| /** | ||
| * Build a new {@link BannerView} object. | ||
| * | ||
| * @return a new {@link BannerView} using the provided values in this builder | ||
| * @since 5.0.0 | ||
| */ | ||
| public abstract BannerView build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.mapbox.api.directions.v5.models; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| public class JunctionViewResponseTest { | ||
|
|
||
| private static final String BANNER_INSTRUCTION_JSON = "{\"distanceAlongGeometry\":139.2,\"primary\":{\"text\":\"E23\",\"components\":[{\"text\":\"E23\",\"type\":\"icon\"}],\"type\":\"fork\",\"modifier\":\"right\"},\"secondary\":{\"text\":\"東名阪自動車道 / 亀山 / 四日市 / 東名阪自動車道\",\"components\":[{\"text\":\"東名阪自動車道\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"亀山\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"四日市\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"東名阪自動車道\",\"type\":\"text\"}],\"type\":\"fork\",\"modifier\":\"right\"},\"view\":{\"text\":\"CA01610_1_E\",\"components\":[{\"text\":\"CA01610_1_E\",\"type\":\"guidance-view\",\"imageURL\":\"https://api-turn-here-staging-451578336.us-east-1.elb.amazonaws.com/guidance-views/v1/z/jct/CA01610_1_E\"}],\"type\":\"fork\",\"modifier\":\"right\"}}"; | ||
|
|
||
| @Test | ||
| public void shouldReadBannerInstruction() { | ||
| BannerInstructions response = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON); | ||
| assertNotNull(response); | ||
| } | ||
|
|
||
| @Test | ||
| public void fromtestToFromJson() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo *
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor thing Could we rename the test so it's clearer (although not consistently applied 👀 at the "naming" convention of the rest of the tests)? We should also remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed these comments and agree with the nits. I'm not ignoring. Think these were copy pasted so larger clean ups will happen during free time :) |
||
| BannerInstructions responseFromJson1 = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor thing Could we improve naming here? Especially |
||
|
|
||
| String jsonString = responseFromJson1.toJson(); | ||
| BannerInstructions responseFromJson2 = BannerInstructions.fromJson(jsonString); | ||
|
|
||
| Assert.assertEquals(responseFromJson1, responseFromJson2); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT |
||
| Assert.assertEquals(responseFromJson2, responseFromJson1); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValuesFromJson() { | ||
| BannerInstructions responseFromJson = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON); | ||
|
|
||
| BannerView bannerView = responseFromJson.view(); | ||
| Assert.assertEquals(bannerView.text(), "CA01610_1_E"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above re: |
||
| Assert.assertEquals(bannerView.type(), StepManeuver.FORK); | ||
| Assert.assertEquals(bannerView.modifier(), "right"); | ||
|
|
||
| Assert.assertEquals(responseFromJson.view().components().size(), 1); | ||
| BannerComponents bannerComponent = responseFromJson.view().components().get(0); | ||
| Assert.assertEquals(bannerComponent.text(), "CA01610_1_E"); | ||
| Assert.assertEquals(bannerComponent.type(), BannerComponents.GUIDANCE_VIEW); | ||
| Assert.assertEquals(bannerComponent.imageUrl(), "https://api-turn-here-staging-451578336.us-east-1.elb.amazonaws.com/guidance-views/v1/z/jct/CA01610_1_E"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.