Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

/**
Expand All @@ -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
*/

Copy link
Copy Markdown

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

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
*/

Copy link
Copy Markdown

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 tag

public String getBaseUrl() {
return baseUrl;
}

/**
* Set the App Name to identify
*
Expand All @@ -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.");
}
}

Expand Down
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;
Expand Down Expand Up @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -458,6 +444,11 @@ public Builder setClientAppName(String appName) {
return this;
}

public Builder setBaseUrl(String baseUrl) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc? Looks like we are also missing javadoc for the method above: setClientAppName

super.baseUrl = baseUrl;
return this;
}

/**
* Build method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -74,7 +60,7 @@ public GeocodingService getService() {

Retrofit retrofit = new Retrofit.Builder()
.client(getOkHttpClient())
.baseUrl(baseUrl)
.baseUrl(builder.getBaseUrl())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();

Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.
*
Expand Down
Loading