Skip to content

Add geoip javascript client guide #87

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Jan 26, 2021
Merged

Add geoip javascript client guide #87

merged 4 commits into from
Jan 26, 2021

Conversation

kevcenteno
Copy link
Member

No description provided.

@github-actions
Copy link

github-actions bot commented Jan 22, 2021

Jest Coverage

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 100 99.14 100 100
_gatsby/gatsby-config/remark 100 92.31 100 100
_ sectionize.ts 100 92.31 100 100 35
_gatsby/gatsby-node/pages/createApiSpecPages/utils 100 100 100 100
_ addCompiledExamples.ts 100 100 100 100
_ addLineNumbers.ts 100 100 100 100
_ getPrimitive.ts 100 100 100 100
_ normalizeArray.ts 100 100 100 100
_ normalizeObject.ts 100 100 100 100
_ openapi.fixture.ts 100 100 100 100
_ primitives.ts 100 100 100 100
_ sampleFromSchema.ts 100 100 100 100
_ sortKeys.ts 100 100 100 100
_ transformDocument.ts 100 100 100 100
_types 100 100 100 100
_ Item.ts 100 100 100 100
_utils 100 100 100 100
_ openapi.ts 100 100 100 100
_ pagination.ts 100 100 100 100
Done in 6.74s.

@github-actions
Copy link

github-actions bot commented Jan 23, 2021

Visit the preview URL for this PR (updated for commit c68a015):

https://dev-maxmind-com--pr87-geoip-js-ns65qotw.web.app

(expires Mon, 01 Feb 2021 21:42:21 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Copy link
Contributor

@oalders oalders left a comment

Choose a reason for hiding this comment

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

Very nice work! 📝 Just a few comments to look at.

convenient, there are some caveats with its usage as some browser settings and
add-ons (such as ad blockers) may prevent the GeoIP2 JavaScript API from
successfully calling the web services, as well as unexpected usage spikes that
you may want to monitor.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty long sentence. I think it can be broken up for clarity. Particularly it's not 100% clear how "as well as unexpected usage spikes that you may want to monitor." fits in. I think maybe it means:

While it is convenient, there are some caveats with its usage. Some browser settings and
add-ons (such as ad blockers) may prevent the GeoIP2 JavaScript API from
successfully calling the web services. Additionally, there may be unexpected usage spikes which
you may want to monitor.

Probably also worth noting why usage might spike.

In order to use this service, the following JavaScript must be included in your
page.

**Do not download this JavaScript file and load it from your server(s)!**
Copy link
Contributor

Choose a reason for hiding this comment

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

It's clear to me why this shouldn't be done, but maybe a note to clarify what the consequences are.


| Option | Description |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `geoip2.country(onSuccess, onError, options)` | Calls the GeoIP2 Precision: Country endpoint using the routable IP address associated with the machine on which it is running. |
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the product names should be quoted or emphasized here. Having that colon in the description without additional context is a bit confusing.


All of the functions take the same 3 arguments:

* If successful, this function calls the `onSuccess`. The first parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

calls the onSuccess.

It feels like a word is missing here.

Explorer 8, this is implemented as a non-enumerable property using
`defineProperty`.

* If there is an error, the function calls the `onError` with the error object
Copy link
Contributor

Choose a reason for hiding this comment

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

the function calls the onError

This also feels like it has a word missing, but maybe I'm just not getting the JS lingo. I think it needs a trailing period?


* The optional `options` parameter is an object containing flags for the

service. This parameter is reserved for future use. There are no options at
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a line break above?


```json
{
"city": {
Copy link
Contributor

Choose a reason for hiding this comment

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

The spacing of this left curly brace is kind of odd.


```js
// demo.js
var fillInPage = (function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use two spaces to condense the indention a bit? We are using two spaces in the html block above this as well as in the json block below this.


```json
{
"city": ...,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge deal, perhaps more of a personal preference. Generally, I'm not a fan of aligning properties like this. It makes maintaining a little harder when the widest property changes.

| (none) | 406 Not Acceptable | Your request included an `Accept-Charset` header that is not supported. `UTF-8` is the only acceptable character set. |
| (none) | 415 Unsupported Media Type | Your request included an `Accept` header that is not supported. The web service cannot return content of that type. |
| (none) | 503 Service Not Available | There is a problem with the web service server. You can try this request again later. |
| Code | HTTP Status | Error |
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we are going to end up having a table very similar to this on a lot of pages, with some variance based on 400 requests. We don't have to abstract this now, but it might be worth starting to think about it.

"names": {}
},
"country": ...,
"continent": ...,
Copy link
Contributor

Choose a reason for hiding this comment

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

General style question. For the ellipses that are property values, should we encase them in an enclosure that can identify their type?

Examples: "...", [...], {...}.

var fillInPage = (function() {
var updateCityText = function(geoipResponse) {

/* It's possible that we won't have any names for this city.
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpicky, but examples of most multiline comments in popular styleguides typically utilize a linebreak after the opening /* and a * on each additional line.

Some reasoning from Google – "subsequent lines must start with * aligned with the * on the previous line, to make comments obvious with no extra context."

updateCityText(geoipResponse);
};

/* If we get an error we will display an error message*/
Copy link
Contributor

Choose a reason for hiding this comment

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

We can change this to a // comment since it is a single line. If not, then a space needs to be added between message and the closing */.

@kevcenteno
Copy link
Member Author

@oalders @wesrice Thanks for the feedback. I've made the suggested changes in c68a015

Copy link
Contributor

@oalders oalders left a comment

Choose a reason for hiding this comment

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

💯

@kevcenteno kevcenteno merged commit fd77f51 into main Jan 26, 2021
@kevcenteno kevcenteno deleted the geoip-js branch January 26, 2021 18:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants