Skip to content
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

for reverseGeocode, pass through apikey and token #295

Merged
merged 1 commit into from Apr 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/Tasks/ReverseGeocodeSpec.js
Expand Up @@ -105,5 +105,25 @@ describe('L.esri.ReverseGeocode', function () {

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleFrenchResponse);
});

it('should pass through a token', function (done) {
var request = L.esri.Geocoding.reverseGeocode({ token: 'testToken' }).latlng([48.8583, 2.2945]).run(function (error, result, response) {
done();
});

expect(request.url).to.contain('token=testToken');

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleResponse);
});

it('should pass through an apikey', function (done) {
var request = L.esri.Geocoding.reverseGeocode({ apikey: 'testApiKey' }).latlng([48.8583, 2.2945]).run(function (error, result, response) {
done();
});

expect(request.url).to.contain('token=testApiKey');

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleResponse);
});
});
/* eslint-disable handle-callback-err */
9 changes: 8 additions & 1 deletion src/Tasks/ReverseGeocode.js
Expand Up @@ -13,7 +13,8 @@ export var ReverseGeocode = Task.extend({
setters: {
distance: 'distance',
language: 'langCode',
intersection: 'returnIntersection'
intersection: 'returnIntersection',
apikey: 'apikey'
},

initialize: function (options) {
Expand All @@ -29,6 +30,12 @@ export var ReverseGeocode = Task.extend({
},

run: function (callback, context) {
if (this.options.token) {
this.params.token = this.options.token;
}
if (this.options.apikey) {
this.params.token = this.options.apikey;
}
return this.request(function (error, response) {
var result;

Expand Down