Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit e595684

Browse files
authored
Merge pull request #33 from ipfs/generic-api
generic API
2 parents 23788f6 + 85c8c02 commit e595684

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

API/generic/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Generic API
2+
===========
3+
4+
#### `id`
5+
6+
> Returns the identity of the Peer
7+
8+
##### `Go` **WIP**
9+
10+
##### `JavaScript` - ipfs.id([callback])
11+
12+
`callback` must follow `function (err, identity) {}` signature, where `err` is an error if the operation was not successful. `identity` is an object with the Peer identity.
13+
14+
If no `callback` is passed, a promise is returned.
15+
16+
Example:
17+
18+
```js
19+
ipfs.id(function (err, identity) {
20+
if (err) {
21+
throw err
22+
}
23+
console.log(identity)
24+
})
25+
```
26+
27+
#### `version`
28+
29+
> Returns the implementation version
30+
31+
##### `Go` **WIP**
32+
33+
##### `JavaScript` - ipfs.version([callback])
34+
35+
`callback` must follow `function (err, version) {}` signature, where `err` is an error if the operation was not successful. `version` is an object with the version of the implementation, the commit and the Repo.
36+
37+
If no `callback` is passed, a promise is returned.
38+
39+
Example:
40+
41+
```js
42+
ipfs.version(function (err, version) {
43+
if (err) {
44+
throw err
45+
}
46+
console.log(version)
47+
})
48+
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
"greenkeeperio-bot <[email protected]>",
4848
"nginnever <[email protected]>"
4949
]
50-
}
50+
}

src/generic.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 8] */
3+
4+
'use strict'
5+
6+
const expect = require('chai').expect
7+
8+
module.exports = (common) => {
9+
describe('.generic', () => {
10+
let ipfs
11+
12+
before(function (done) {
13+
// CI takes longer to instantiate the daemon,
14+
// so we need to increase the timeout for the
15+
// before step
16+
this.timeout(20 * 1000)
17+
18+
common.setup((err, factory) => {
19+
expect(err).to.not.exist
20+
factory.spawnNode((err, node) => {
21+
expect(err).to.not.exist
22+
ipfs = node
23+
done()
24+
})
25+
})
26+
})
27+
28+
after((done) => {
29+
common.teardown(done)
30+
})
31+
32+
describe('callback API', () => {
33+
it('.id', (done) => {
34+
ipfs.id((err, res) => {
35+
expect(err).to.not.exist
36+
expect(res).to.have.a.property('id')
37+
expect(res).to.have.a.property('publicKey')
38+
done()
39+
})
40+
})
41+
42+
it('.version', (done) => {
43+
ipfs.version((err, result) => {
44+
expect(err).to.not.exist
45+
expect(result).to.have.a.property('version')
46+
expect(result).to.have.a.property('commit')
47+
expect(result).to.have.a.property('repo')
48+
done()
49+
})
50+
})
51+
})
52+
53+
describe('promise API', () => {
54+
it('.id', () => {
55+
return ipfs.id()
56+
.then((res) => {
57+
expect(res).to.have.a.property('id')
58+
expect(res).to.have.a.property('publicKey')
59+
})
60+
})
61+
62+
it('.version', () => {
63+
return ipfs.version()
64+
.then((result) => {
65+
expect(result).to.have.a.property('version')
66+
expect(result).to.have.a.property('commit')
67+
expect(result).to.have.a.property('repo')
68+
})
69+
})
70+
})
71+
})
72+
}

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ exports.object = require('./object')
44
exports.files = require('./files')
55
exports.config = require('./config')
66
exports.pin = require('./pin')
7+
exports.generic = require('./generic')

0 commit comments

Comments
 (0)