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

Add IP2Location.io API #909

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/options/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ export default {
}
},

// This service requires an option to define `key`. Options are proived using objects or functions
// User can sign up for the free api key at here: https://www.ip2location.io/sign-up
ip2locationio: function () {
return {
// This service responds with JSON, so we simply need to parse it and return the country code
url: 'https://api.ip2location.io/?key={api_key}&format=json',
headers: ['Accept: application/json'],
callback: function (done, response) {
try {
const json = JSON.parse(response);
return json.error ? toError(json) : {
code: json.country_code
};
} catch (err) {
return toError({
error: 'Invalid response (' + err + ')'
});
}
}
};
},

maxmind: function() {
return {
// This service responds with a JavaScript file which defines additional functionality. Once loaded, we must
Expand Down