Skip to content

Commit

Permalink
refactor: modularize name api(ipfs-inactive#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofmn committed Jun 18, 2017
1 parent 682f3f6 commit dc73324
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
30 changes: 0 additions & 30 deletions src/api/name.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/api/name/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

module.exports = (arg) => {
return {
publish: require('./publish')(arg),
resolve: require('./resolve')(arg)
}
}
20 changes: 20 additions & 0 deletions src/api/name/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const promisify = require('promisify-es6')
const moduleConfig = require('../../module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({
path: 'name/publish',
args: args,
qs: opts
}, callback)
})
}
20 changes: 20 additions & 0 deletions src/api/name/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const promisify = require('promisify-es6')
const moduleConfig = require('../../module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({
path: 'name/resolve',
args: args,
qs: opts
}, callback)
})
}
12 changes: 12 additions & 0 deletions test/sub-modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,16 @@ describe('submodules', () => {
expect(list).to.be.a('function')
})
})

describe('name', () => {
it('.publish', () => {
const publish = require('../src/api/name/publish')
expect(publish).to.be.a('function')
})

it('.resolve', () => {
const resolve = require('../src/api/name/resolve')
expect(resolve).to.be.a('function')
})
})
})

0 comments on commit dc73324

Please sign in to comment.