-
Notifications
You must be signed in to change notification settings - Fork 117
[android] - make changing base url a part of public API. #245
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
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.mapbox.services.commons; | ||
|
|
||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.utils.MapboxUtils; | ||
|
|
||
| /** | ||
|
|
@@ -8,11 +9,32 @@ | |
| public abstract class MapboxBuilder { | ||
|
|
||
| protected String clientAppName; | ||
| protected String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| public abstract MapboxBuilder setAccessToken(String accessToken); | ||
|
|
||
| public abstract String getAccessToken(); | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @param <T> the concrete implementation of MapboxBuilder | ||
| * @return the current MapboxBuilder instance | ||
| * @since 2.0.0 | ||
| */ | ||
| public abstract <T extends MapboxBuilder> T setBaseUrl(String baseUrl); | ||
|
|
||
| /** | ||
| * Get the base url of the API. | ||
| * | ||
| * @return the base url used as endpoint. | ||
| * @since 2.0.0 | ||
| */ | ||
|
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. Missing @SInCE 2.0.0 tag |
||
| public String getBaseUrl() { | ||
| return baseUrl; | ||
| } | ||
|
|
||
| /** | ||
| * Set the App Name to identify | ||
| * | ||
|
|
@@ -36,7 +58,7 @@ public String getClientAppName() { | |
| protected void validateAccessToken(String accessToken) throws ServicesException { | ||
| if (!MapboxUtils.isAccessTokenValid(accessToken)) { | ||
| throw new ServicesException( | ||
| "Using Mapbox Services requires setting a valid access token."); | ||
| "Using Mapbox Services requires setting a valid access token."); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package com.mapbox.services.directions.v4; | ||
|
|
||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.MapboxBuilder; | ||
| import com.mapbox.services.commons.MapboxService; | ||
| import com.mapbox.services.commons.ServicesException; | ||
|
|
@@ -33,9 +32,6 @@ public class MapboxDirections extends MapboxService<DirectionsResponse> { | |
| private DirectionsService service = null; | ||
| private Call<DirectionsResponse> call = null; | ||
|
|
||
| // Allows testing | ||
| private String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| /** | ||
| * Mapbox builder | ||
| * | ||
|
|
@@ -48,18 +44,6 @@ public MapboxDirections(Builder builder) { | |
| this.builder = builder; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @param baseUrl {@link String} baseUrl | ||
| * @since 1.0.0 | ||
| * @deprecated Use Directions v5 instead | ||
| */ | ||
| @Deprecated | ||
| public void setBaseUrl(String baseUrl) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
|
|
@@ -76,7 +60,7 @@ public DirectionsService getService() { | |
|
|
||
| Retrofit retrofit = new Retrofit.Builder() | ||
| .client(getOkHttpClient()) | ||
| .baseUrl(baseUrl) | ||
| .baseUrl(builder.getBaseUrl()) | ||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .build(); | ||
| service = retrofit.create(DirectionsService.class); | ||
|
|
@@ -458,6 +442,20 @@ public MapboxDirections build() throws ServicesException { | |
| return new MapboxDirections(this); | ||
| } | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @return the current MapboxBuilder instance | ||
| * @since 2.0.0 | ||
| * @deprecated Use Directions v5 instead | ||
| */ | ||
| @Override | ||
|
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. No need to expose this in Directions v4, it has been deprecated. |
||
| @Deprecated | ||
| public MapboxBuilder setBaseUrl(String baseUrl) { | ||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package com.mapbox.services.directions.v5; | ||
|
|
||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.MapboxBuilder; | ||
| import com.mapbox.services.commons.MapboxService; | ||
| import com.mapbox.services.commons.ServicesException; | ||
|
|
@@ -32,23 +31,10 @@ public class MapboxDirections extends MapboxService<DirectionsResponse> { | |
| private DirectionsService service = null; | ||
| private Call<DirectionsResponse> call = null; | ||
|
|
||
| // Allows testing | ||
| private String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| private MapboxDirections(Builder builder) { | ||
| this.builder = builder; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @param baseUrl the baseURL | ||
| * @since 1.0.0 | ||
| */ | ||
| public void setBaseUrl(String baseUrl) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| private DirectionsService getService() { | ||
| // No need to recreate it | ||
| if (service != null) { | ||
|
|
@@ -58,7 +44,7 @@ private DirectionsService getService() { | |
| // Retrofit instance | ||
| Retrofit retrofit = new Retrofit.Builder() | ||
| .client(getOkHttpClient()) | ||
| .baseUrl(baseUrl) | ||
| .baseUrl(builder.getBaseUrl()) | ||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .build(); | ||
|
|
||
|
|
@@ -458,6 +444,11 @@ public Builder setClientAppName(String appName) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder setBaseUrl(String baseUrl) { | ||
|
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. Javadoc? Looks like we are also missing javadoc for the method above: |
||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build method | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.MapboxBuilder; | ||
| import com.mapbox.services.commons.MapboxService; | ||
| import com.mapbox.services.commons.ServicesException; | ||
|
|
@@ -47,23 +46,10 @@ public class MapboxDistance extends MapboxService<DistanceResponse> { | |
| private DistanceService service = null; | ||
| private Call<DistanceResponse> call = null; | ||
|
|
||
| // Allows testing | ||
| private String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| private MapboxDistance(Builder builder) { | ||
| this.builder = builder; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @param baseUrl the baseURL. | ||
| * @since 2.0.0 | ||
| */ | ||
| public void setBaseUrl(String baseUrl) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| private DistanceService getService() { | ||
| //No need to recreate it | ||
| if (service != null) { | ||
|
|
@@ -78,7 +64,7 @@ private DistanceService getService() { | |
| // Retrofit instance | ||
| Retrofit retrofit = new Retrofit.Builder() | ||
| .client(getOkHttpClient()) | ||
| .baseUrl(baseUrl) | ||
| .baseUrl(builder.getBaseUrl()) | ||
| .addConverterFactory(GsonConverterFactory.create(gson)) | ||
| .build(); | ||
|
|
||
|
|
@@ -277,6 +263,19 @@ public Builder setClientAppName(String appName) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @return Builder | ||
| * @since 2.0.0 | ||
| */ | ||
| @Override | ||
|
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. Javadoc |
||
| public Builder setBaseUrl(String baseUrl) { | ||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Builder method | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.MapboxBuilder; | ||
| import com.mapbox.services.commons.MapboxService; | ||
| import com.mapbox.services.commons.ServicesException; | ||
|
|
@@ -32,9 +31,6 @@ public class MapboxGeocoding extends MapboxService<GeocodingResponse> { | |
| private GeocodingService service = null; | ||
| private Call<GeocodingResponse> call = null; | ||
|
|
||
| // Allows testing | ||
| private String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| /** | ||
| * Public constructor. | ||
| * | ||
|
|
@@ -45,16 +41,6 @@ public MapboxGeocoding(Builder builder) { | |
| this.builder = builder; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @param baseUrl the baseURL. | ||
| * @since 1.0.0 | ||
| */ | ||
| public void setBaseUrl(String baseUrl) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
|
|
@@ -74,7 +60,7 @@ public GeocodingService getService() { | |
|
|
||
| Retrofit retrofit = new Retrofit.Builder() | ||
| .client(getOkHttpClient()) | ||
| .baseUrl(baseUrl) | ||
| .baseUrl(builder.getBaseUrl()) | ||
| .addConverterFactory(GsonConverterFactory.create(gson)) | ||
| .build(); | ||
|
|
||
|
|
@@ -448,6 +434,19 @@ public Builder setClientAppName(String appName) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @return the current MapboxBuilder instance | ||
| * @since 2.0.0 | ||
| */ | ||
| @Override | ||
|
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. Javadoc |
||
| public Builder setBaseUrl(String baseUrl) { | ||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build method | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.mapbox.services.Constants; | ||
| import com.mapbox.services.commons.MapboxBuilder; | ||
| import com.mapbox.services.commons.MapboxService; | ||
| import com.mapbox.services.commons.ServicesException; | ||
|
|
@@ -38,24 +37,10 @@ public class MapboxMapMatching extends MapboxService<MapMatchingResponse> { | |
| private MapMatchingService service = null; | ||
| private Call<MapMatchingResponse> call = null; | ||
|
|
||
| // Allows testing | ||
| private String baseUrl = Constants.BASE_API_URL; | ||
|
|
||
| private MapboxMapMatching(Builder builder) { | ||
| this.builder = builder; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @param baseUrl the baseURL. | ||
| * @since 1.2.0 | ||
| */ | ||
| public void setBaseUrl(String baseUrl) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
|
|
||
| private MapMatchingService getService() { | ||
| // No need to recreate it | ||
| if (service != null) { | ||
|
|
@@ -70,7 +55,7 @@ private MapMatchingService getService() { | |
| // Retrofit instance | ||
| Retrofit retrofit = new Retrofit.Builder() | ||
| .client(getOkHttpClient()) | ||
| .baseUrl(baseUrl) | ||
| .baseUrl(builder.getBaseUrl()) | ||
| .addConverterFactory(GsonConverterFactory.create(gson)) | ||
| .build(); | ||
|
|
||
|
|
@@ -318,6 +303,19 @@ public Builder setClientAppName(String appName) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @return the current MapboxBuilder instance | ||
| * @since 2.0.0 | ||
| */ | ||
| @Override | ||
|
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. Javadoc |
||
| public Builder setBaseUrl(String baseUrl) { | ||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Builder method | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,7 @@ public class MapboxStaticImage { | |
| * @since 1.0.0 | ||
| */ | ||
| public MapboxStaticImage(Builder builder) { | ||
| HttpUrl.Builder urlBuilder = new HttpUrl.Builder() | ||
| .scheme("https") | ||
| .host("api.mapbox.com") | ||
| HttpUrl.Builder urlBuilder = HttpUrl.parse(builder.getBaseUrl()).newBuilder() | ||
| .addPathSegment("styles") | ||
| .addPathSegment("v1") | ||
| .addPathSegment(builder.getUsername()) | ||
|
|
@@ -375,6 +373,19 @@ public Builder setClientAppName(String appName) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the base url of the API. | ||
| * | ||
| * @param baseUrl base url used as end point | ||
| * @return the current MapboxBuilder instance | ||
| * @since 2.0.0 | ||
| */ | ||
| @Override | ||
|
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. Javadoc |
||
| public MapboxBuilder setBaseUrl(String baseUrl) { | ||
| super.baseUrl = baseUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build the client when all user parameters have been set. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @SInCE 2.0.0 and @param tags