-
Notifications
You must be signed in to change notification settings - Fork 117
Batch geocoding support #267
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5d04003
new geocoding batch fixture
zugaldia 9d3ad90
add a new geocoding-batch-fixtures rule and fix the paths
zugaldia 40830a1
reformat fixture for easy reading
zugaldia 3dd4daf
add batch methods and tests
zugaldia d5ff6e7
update @since 2.0.0 tags
zugaldia f2b2ce8
remove unnecessary code from MapboxGeocodingBatchTest
zugaldia 2ca64e2
o o p s
zugaldia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import com.mapbox.services.api.geocoding.v5.models.GeocodingResponse; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| import retrofit2.Call; | ||
|
|
@@ -30,6 +31,7 @@ public class MapboxGeocoding extends MapboxService<GeocodingResponse> { | |
| private Builder builder = null; | ||
| private GeocodingService service = null; | ||
| private Call<GeocodingResponse> call = null; | ||
| private Call<List<GeocodingResponse>> batchCall = null; | ||
|
|
||
| /** | ||
| * Public constructor. | ||
|
|
@@ -80,6 +82,10 @@ public Call<GeocodingResponse> getCall() { | |
| return call; | ||
| } | ||
|
|
||
| if (builder.getQuery().contains(";")) { | ||
| throw new IllegalArgumentException("Use getBatchCall() for batch calls."); | ||
|
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. niceee |
||
| } | ||
|
|
||
| call = getService().getCall( | ||
| getHeaderUserAgent(builder.getClientAppName()), | ||
| builder.getMode(), | ||
|
|
@@ -95,6 +101,37 @@ public Call<GeocodingResponse> getCall() { | |
| return call; | ||
| } | ||
|
|
||
| /** | ||
| * Used internally. | ||
| * | ||
| * @return batch call | ||
| * @since 2.0.0 | ||
| */ | ||
| public Call<List<GeocodingResponse>> getBatchCall() { | ||
| // No need to recreate it | ||
| if (batchCall != null) { | ||
| return batchCall; | ||
| } | ||
|
|
||
| if (!builder.getQuery().contains(";")) { | ||
| throw new IllegalArgumentException("Use getCall() for non-batch calls."); | ||
| } | ||
|
|
||
| batchCall = getService().getBatchCall( | ||
| getHeaderUserAgent(builder.getClientAppName()), | ||
| builder.getMode(), | ||
| builder.getQuery(), | ||
| builder.getAccessToken(), | ||
| builder.getCountry(), | ||
| builder.getProximity(), | ||
| builder.getGeocodingTypes(), | ||
| builder.getAutocomplete(), | ||
| builder.getBbox(), | ||
| builder.getLimit()); | ||
|
|
||
| return batchCall; | ||
| } | ||
|
|
||
| /** | ||
| * Execute the call | ||
| * | ||
|
|
@@ -107,6 +144,17 @@ public Response<GeocodingResponse> executeCall() throws IOException { | |
| return getCall().execute(); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the batch call | ||
| * | ||
| * @return The Geocoding v5 response | ||
| * @throws IOException Signals that an I/O exception of some sort has occurred. | ||
| * @since 2.0.0 | ||
| */ | ||
| public Response<List<GeocodingResponse>> executeBatchCall() throws IOException { | ||
| return getBatchCall().execute(); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the call | ||
| * | ||
|
|
@@ -118,6 +166,16 @@ public void enqueueCall(Callback<GeocodingResponse> callback) { | |
| getCall().enqueue(callback); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the batch call | ||
| * | ||
| * @param callback A Retrofit callback. | ||
| * @since 2.0.0 | ||
| */ | ||
| public void enqueueBatchCall(Callback<List<GeocodingResponse>> callback) { | ||
| getBatchCall().enqueue(callback); | ||
| } | ||
|
|
||
| /** | ||
| * Cancel the call | ||
| * | ||
|
|
@@ -128,6 +186,15 @@ public void cancelCall() { | |
| getCall().cancel(); | ||
| } | ||
|
|
||
| /** | ||
| * Cancel the batch call | ||
| * | ||
| * @since 2.0.0 | ||
| */ | ||
| public void cancelBatchCall() { | ||
| getBatchCall().cancel(); | ||
| } | ||
|
|
||
| /** | ||
| * clone the call | ||
| * | ||
|
|
@@ -139,6 +206,16 @@ public Call<GeocodingResponse> cloneCall() { | |
| return getCall().clone(); | ||
| } | ||
|
|
||
| /** | ||
| * clone the batch call | ||
| * | ||
| * @return cloned call | ||
| * @since 2.0.0 | ||
| */ | ||
| public Call<List<GeocodingResponse>> cloneBatchCall() { | ||
| return getBatchCall().clone(); | ||
| } | ||
|
|
||
| /** | ||
| * Builds your geocoder query by adding parameters. | ||
| * | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@since 2.0.0