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

Geolocation #81

Merged
merged 7 commits into from
May 29, 2017
Merged

Geolocation #81

merged 7 commits into from
May 29, 2017

Conversation

stephenmcd
Copy link
Contributor

No description provided.

Copy link
Contributor

@stephenfarrar stephenfarrar left a comment

Choose a reason for hiding this comment

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

Thanks! This is cool.

I just have a few comments about things I got confused about when reading the code. Nothing major at all.

// Geolocation API which uses HTTP POST for its request, and HTTP
// status codes for determining success.
var isSuccessResponse = function(response) {
if (!isPost) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a slight preference for

if (isPost) {
  ...
} else {
  ...
}

I had to read this twice because the ! is easy to miss.

});
if (isPost) {
// Remove key from query for HTTP POST, since query is the JSON being posted.
delete query.key;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to check I've understood, this will mutate the object that was passed as a parameter, and the caller is relying on that? That's very subtle.

I'd much prefer if we could move this logic about POST out of this function, so that it continues to just take the query, return the URL, and not have side-effects.

@@ -156,10 +175,15 @@ exports.inject = function(options) {
throw 'Missing either a valid API key, or a client ID and secret';
}

var isPost = method == 'POST';
Copy link
Contributor

Choose a reason for hiding this comment

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

Use triple equals
===

lib/index.js Outdated

var makeApiMethod = function(apiConfig) {
return function(query, callback, customParams) {
query = apiConfig.validator(query);
query.supportsClientId = apiConfig.supportsClientId !== false;
query.method = apiConfig.method;
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a preference for making the method an extra parameter in makeApiCall(), rather than adding it as a query parameter that you have to later delete.

It's not really a query param.

If we're worried that makeApiCall() is getting too many arguments, we can make the third arg an options object, containing both useClientId and method.


function rateLimitedGet() {
return requestQueue.add(function() {
return Task.start(function(resolve, reject) {
return makeUrlRequest(requestUrl, resolve, reject);
return makeUrlRequest(requestUrl, resolve, reject, postData);
Copy link
Contributor

Choose a reason for hiding this comment

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

It worries me a little that we only support GET and POST, but never check that method isn't anything else.

Should makeUrlRequest take the method, as well as the postData ?

@@ -93,6 +98,7 @@ exports.inject = function(options) {
until: function(response) {
return !(
response == null
|| response.status === 403 // Geolocation API only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I didn't understand this bit. It looks like it happens for all APIs, not just geolocation. And we shouldn't retry for 403 generally.

@stephenmcd
Copy link
Contributor Author

@stephenfarrar I made all the changes we discussed offline in 5ef38ec apart from the order of arguments in makeUrlRequest - I opted for backwards compatibility there.

@stephenmcd stephenmcd merged commit 441d29e into master May 29, 2017
@jpoehnelt jpoehnelt deleted the geolocation branch February 7, 2020 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants