diff --git a/README.md b/README.md index 4754b30..d2fcbd2 100644 --- a/README.md +++ b/README.md @@ -17,35 +17,31 @@ Unofficial Node.js module for the Maxmind GeoIP2 Web Services. Usage ----- -There are multiple ways to load and set up this module. -All communication is done over HTTPS. +There are multiple ways to load and use this module. -#### One line +When you don't provide a callback function you'll get +a _promise_ in return. -```js -require ('geoip2ws') (userId, licenseKey) (ip, callback); -``` -#### Multiple calls, same account +#### One line with callback ```js -const geoip2ws = require ('geoip2ws') (userId, licenseKey); -geoip2ws (ip1, callback); -geoip2ws (ip2, callback); +require ('geoip2ws') (userId, licenseKey) (ip, callback); ``` -#### Mix products (or accounts) -```js -const geoip2ws = require ('geoip2ws'); -const insights = new geoip2ws (userId, licenseKey, 'insights'); -const country = new geoip2ws (userId, licenseKey, 'country'); +#### Promise -// precise lookup, higher cost -insights (ip, callback); +```js +const geo = require ('geoip2ws') ({ + userId: 12345, + licenseKey: 'abc678', +}); -// vague lookup, lower cost -country (ip, callback); +geo ('city', '1.2.3.4') + .then (console.log) + .catch (console.error) +; ``` @@ -91,30 +87,12 @@ parameter | type | required | description :---------|:---------|:---------|:-------------------------------------------- service | string | no | The service, same as above ip | string | yes | The IPv4 or IPv6 address to lookup -callback | function | yes | Your callback `function` to receive the data +callback | function | no | Your callback. Leave out to return a promise. ```js geo ('city', '145.53.252.135', myCallback); ``` - -Callback --------- - -The callback function receives result data and errors. Unless an error occurs the -data JSON will be parsed to an object. When everything is ok `err` is `null` else -`err` is an instance of `Error`. It also returns API errors this same way. - -```js -function myCallback (err, data) { - if (err) { - console.log (err); - } else { - console.log (data.city.names.en); - } -} -``` - [Example response data](http://dev.maxmind.com/geoip/geoip2/web-services/#Response_Body) @@ -165,5 +143,3 @@ Author ------ [Franklin van de Meent](https://frankl.in/) - -[![Buy me a coffee](https://frankl.in/u/kofi/kofi-readme.svg)](https://ko-fi.com/franklin)