Skip to content

Commit 207f9d4

Browse files
author
Cameron Mace
authored
Remove hardcoded accesstoken and adds buildconfig task (#688)
1 parent a8b22cb commit 207f9d4

7 files changed

Lines changed: 60 additions & 79 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
build-config:
2+
./gradlew compileBuildConfig
3+
14
checkstyle:
25
./gradlew checkstyle
36

samples/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
apply plugin: 'java'
2+
apply plugin: 'de.fuerstenau.buildconfig'
3+
14
dependencies {
25
compile project(":services-core")
36
compile project(":services-directions")
47
compile project(":services-geocoding")
58
compile project(":services-optimization")
69
compile project(":services-geojson")
7-
// compile project(":services-matching")
10+
compile project(":services-matching")
811
compile project(":services-staticmap")
912
}
1013

14+
buildConfig {
15+
packageName = 'com.mapbox.sample'
16+
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', System.getenv("MAPBOX_ACCESS_TOKEN")
17+
}
18+
1119
sonarqube {
1220
skipProject = true
1321
}

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

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mapbox.api.directions.v5.MapboxDirections;
44
import com.mapbox.api.directions.v5.models.DirectionsResponse;
55
import com.mapbox.geojson.Point;
6+
import com.mapbox.sample.BuildConfig;
67
import retrofit2.Call;
78
import retrofit2.Callback;
89
import retrofit2.Response;
@@ -19,36 +20,24 @@ public static void main(String[] args) throws IOException {
1920
buildMapboxDirectionsRequest();
2021

2122

22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
3323
}
3424

3525
private static void buildMapboxDirectionsRequest() throws IOException {
3626

3727
MapboxDirections.Builder builder = MapboxDirections.builder();
3828

3929
// 1. Pass in all the required information to get a simple directions route.
40-
builder.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ");
30+
builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN);
4131
builder.origin(Point.fromLngLat(-95.6332, 29.7890));
4232
builder.destination(Point.fromLngLat(-95.3591, 29.7576));
4333

4434
// 2. That's it! Now execute the command and get the response.
4535
Response<DirectionsResponse> response = builder.build().executeCall();
4636

4737
// 3. Log information from the response
48-
System.out.println("Check that the response is successful" + response.isSuccessful());
49-
System.out.println(("Get the first routes distance from origin to destination: "
50-
+ response.body().routes().get(0).distance()));
51-
38+
System.out.printf("Check that the response is successful %b", response.isSuccessful());
39+
System.out.printf("Get the first routes distance from origin to destination: %f",
40+
response.body().routes().get(0).distance());
5241

5342

5443
//
@@ -82,32 +71,6 @@ public void onFailure(Call<DirectionsResponse> call, Throwable t) {
8271
}
8372

8473

85-
86-
87-
88-
89-
90-
91-
92-
93-
94-
95-
96-
97-
98-
99-
100-
101-
102-
103-
104-
105-
106-
107-
108-
109-
110-
11174
//
11275
//
11376
//

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
44
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;
55

6+
import com.mapbox.sample.BuildConfig;
67
import retrofit2.Call;
78
import retrofit2.Callback;
89
import retrofit2.Response;
@@ -11,7 +12,7 @@ public class BasicGeocoding {
1112

1213
public static void main(String[] args) {
1314
MapboxGeocoding geocoding = MapboxGeocoding.builder()
14-
.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ")
15+
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
1516
.query("1600")
1617
.build();
1718

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
package com.mapbox.samples;
22

3-
//import com.mapbox.matching.v5.MapboxMapMatching;
4-
//import com.mapbox.matching.v5.models.MapMatchingResponse;
5-
3+
import com.mapbox.api.matching.v5.MapboxMapMatching;
4+
import com.mapbox.api.matching.v5.models.MapMatchingResponse;
5+
import com.mapbox.geojson.Point;
6+
import com.mapbox.sample.BuildConfig;
7+
import retrofit2.Call;
8+
import retrofit2.Callback;
9+
import retrofit2.Response;
610

711
public class BasicMapMatching {
8-
// public static void main(String[] args) {
9-
//
10-
// MapboxMapMatching mapMatching = MapboxMapMatching.builder()
11-
// .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ")
12-
// .coordinate(Point.fromLngLat(-117.1728265285492,32.71204416018209))
13-
// .coordinate(Point.fromLngLat(-117.17288821935652,32.712258556224))
14-
// .coordinate(Point.fromLngLat(-117.17293113470076,32.712443613445814))
15-
// .coordinate(Point.fromLngLat(-117.17292040586472,32.71256999376694))
16-
// .coordinate(Point.fromLngLat(-117.17298477888109,32.712603845608285))
17-
// .coordinate(Point.fromLngLat(-117.17314302921294,32.71259933203019))
18-
// .coordinate(Point.fromLngLat(-117.17334151268004,32.71254065549407))
19-
// .build();
20-
//
21-
// System.out.println(mapMatching.cloneCall().request().url());
22-
//
23-
// mapMatching.enqueueCall(new Callback<MapMatchingResponse>() {
24-
// @Override
25-
// public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
26-
// System.out.println(response.body().toString());
27-
// }
28-
//
29-
// @Override
30-
// public void onFailure(Call<MapMatchingResponse> call, Throwable throwable) {
31-
// System.out.println(throwable);
32-
// }
33-
// });
34-
// }
12+
public static void main(String[] args) {
13+
14+
MapboxMapMatching mapMatching = MapboxMapMatching.builder()
15+
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
16+
.coordinate(Point.fromLngLat(-117.1728265285492,32.71204416018209))
17+
.coordinate(Point.fromLngLat(-117.17288821935652,32.712258556224))
18+
.coordinate(Point.fromLngLat(-117.17293113470076,32.712443613445814))
19+
.coordinate(Point.fromLngLat(-117.17292040586472,32.71256999376694))
20+
.coordinate(Point.fromLngLat(-117.17298477888109,32.712603845608285))
21+
.coordinate(Point.fromLngLat(-117.17314302921294,32.71259933203019))
22+
.coordinate(Point.fromLngLat(-117.17334151268004,32.71254065549407))
23+
.build();
24+
25+
mapMatching.enqueueCall(new Callback<MapMatchingResponse>() {
26+
@Override
27+
public void onResponse(Call<MapMatchingResponse> call,
28+
Response<MapMatchingResponse> response) {
29+
System.out.println(response.body().toString());
30+
}
31+
32+
@Override
33+
public void onFailure(Call<MapMatchingResponse> call, Throwable throwable) {
34+
System.out.println(throwable);
35+
}
36+
});
37+
}
3538
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.mapbox.api.optimization.v1.MapboxOptimization;
66
import com.mapbox.api.optimization.v1.models.OptimizationResponse;
77

8+
import com.mapbox.sample.BuildConfig;
89
import retrofit2.Call;
910
import retrofit2.Callback;
1011
import retrofit2.Response;
@@ -14,21 +15,22 @@ public class BasicOptimization {
1415
public static void main(String[] args) {
1516

1617
MapboxOptimization optimization = MapboxOptimization.builder()
17-
.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ")
18+
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
1819
.coordinate(Point.fromLngLat(-122.42, 37.78))
1920
.coordinate(Point.fromLngLat(-122.45, 37.91))
2021
.coordinate(Point.fromLngLat(-122.48, 37.73))
2122
.build();
2223

2324
optimization.enqueueCall(new Callback<OptimizationResponse>() {
2425
@Override
25-
public void onResponse(Call<OptimizationResponse> call, Response<OptimizationResponse> response) {
26+
public void onResponse(Call<OptimizationResponse> call,
27+
Response<OptimizationResponse> response) {
2628
System.out.println(response.body().code());
2729
}
2830

2931
@Override
30-
public void onFailure(Call<OptimizationResponse> call, Throwable t) {
31-
System.out.println(t);
32+
public void onFailure(Call<OptimizationResponse> call, Throwable throwable) {
33+
System.out.println(throwable);
3234
}
3335
});
3436
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.mapbox.api.staticmap.v1.StaticMapCriteria;
66
import com.mapbox.api.staticmap.v1.models.StaticMarkerAnnotation;
77
import com.mapbox.api.staticmap.v1.models.StaticPolylineAnnotation;
8+
import com.mapbox.sample.BuildConfig;
89

910
import java.awt.Color;
1011
import java.util.ArrayList;
@@ -28,7 +29,7 @@ public static void main(String[] args) {
2829
polylines.add(StaticPolylineAnnotation.builder().polyline("abcdef").build());
2930

3031
MapboxStaticMap mapboxStaticMap = MapboxStaticMap.builder()
31-
.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ")
32+
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
3233
.width(500)
3334
.height(300)
3435
.retina(true)

0 commit comments

Comments
 (0)