Skip to content

Commit

Permalink
Docs(readme): Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fvdm committed Oct 17, 2018
1 parent 974b106 commit 830c58e
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
```


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)

0 comments on commit 830c58e

Please sign in to comment.