Skip to content

Commit

Permalink
docs: version-agnostic README
Browse files Browse the repository at this point in the history
Also, simplified default example to use gateway API, and not RPC
  • Loading branch information
lidel committed Oct 21, 2022
1 parent 4423251 commit 0407e45
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,26 @@ npm install --save ipfs-geoip

### CDN

Instead of a local installation (and browserification) you may request a [remote copy from jsDelivr](https://www.jsdelivr.com/package/npm/ipfs-geoip):
Instead of a local installation (and browserification) you may request specific
version `N.N.N` as a [remote copy from jsDelivr](https://www.jsdelivr.com/package/npm/ipfs-geoip):


**<v9**
```html
<!-- loading the minified version using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/ipfs-geoip@8.0.0/dist/index.min.js"></script>
<!-- loading the minified version N.N.N using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/ipfs-geoip@N.N.N/dist/index.min.js"></script>
```

When using prebuilt bundle from CDN, `ipfs-geoip` will be exposed under `window.IpfsGeoip`

**>=v9**

```html
<!-- ipfs-http-client at the time of writing does not distribute esm -->
<script src="https://cdn.jsdelivr.net/npm/ipfs-http-client@58.0.1/dist/index.min.js"></script>
<!-- the script type is module -->
<script type="module">
import { lookup } from 'https://cdn.jsdelivr.net/npm/ipfs-geoip@9.0.0/dist/index.min.js';
const client = window.IpfsHttpClient.create({
host: 'ipfs.io',
port: 443,
protocol: 'https'
});
console.log(await lookup(client, '66.6.44.4'))
import { lookup } from 'https://cdn.jsdelivr.net/npm/ipfs-geoip@N.N.N/dist/index.min.js';
const gateway = 'https://ipfs.io'
console.log(await lookup(gateway, '66.6.44.4'))
</script>
```

The response in the console looks like:
The response in the console should look similar to:
```js
{
"country_name": "USA",
Expand All @@ -87,25 +79,25 @@ The response in the console looks like:

### With public gateways (default)

If `ipfs` is a string or array of strings with public gateway URLs, it will be used for
If `gateways` is a string or array of strings with public gateway URLs, it will be used for
fetching IPFS blocks as [`application/vnd.ipld.raw`](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw)
and parsing them as DAG-CBOR locally:
and parsing them as DAG-CBOR locally via [@ipld/dag-cbor](https://www.npmjs.com/package/@ipld/dag-cbor):

```js
const geoip = require('ipfs-geoip')
const exampleIp = '66.6.44.4'

const ipfsGw = ['https://ipfs.io', 'https://dweb.link']
const gateways = ['https://ipfs.io', 'https://dweb.link']

try {
const result = await geoip.lookup(ipfsGw, exampleIp)
const result = await geoip.lookup(gateways, exampleIp)
console.log('Result: ', result)
} catch (err) {
console.log('Error: ' + err)
}

try {
const result = await geoip.lookupPretty(ipfsGw, '/ip4/' + exampleIp)
const result = await geoip.lookupPretty(gateways, '/ip4/' + exampleIp)
console.log('Pretty result: %s', result.formatted)
} catch (err) {
console.log('Error: ' + err)
Expand Down

0 comments on commit 0407e45

Please sign in to comment.