Sugar namespsace get. (#95)
diff --git a/README.md b/README.md
index 3f36dec..81cdbb2 100644
--- a/README.md
+++ b/README.md
@@ -245,7 +245,6 @@
ow.activations.get({name: '...'})
ow.triggers.get({name: '...'})
ow.rules.get({name: '...'})
-ow.namespaces.get({name: '...'})
ow.packages.get({name: '...'})
ow.feeds.get({name: '...', trigger: '...'})
```
diff --git a/lib/namespaces.js b/lib/namespaces.js
index b07fa96..e9d8a81 100644
--- a/lib/namespaces.js
+++ b/lib/namespaces.js
@@ -7,22 +7,17 @@
class Namespaces extends BaseOperation {
list () {
- return this.client.request('GET', `namespaces`)
+ return this.client.request('GET', 'namespaces')
}
- get (options) {
- if (typeof options === 'string') {
- return this.client.request('GET', `namespaces/${options}`)
- }
-
- options = options || {}
- const id = options.name || options.namespace
-
- if (!id) {
- throw new Error('Missing mandatory parameter: id or namespace.')
- }
-
- return this.client.request('GET', `namespaces/${id}`)
+ get () {
+ let actions = this.client.request('GET', 'namespaces/_/actions')
+ let packages = this.client.request('GET', 'namespaces/_/packages')
+ let triggers = this.client.request('GET', 'namespaces/_/triggers')
+ let rules = this.client.request('GET', 'namespaces/_/rules')
+ return Promise
+ .all([actions, packages, triggers, rules])
+ .then(([actions, packages, triggers, rules]) => ({actions, packages, triggers, rules}))
}
}
diff --git a/test/unit/namespaces.test.js b/test/unit/namespaces.test.js
index 1c7b03e..5a31673 100644
--- a/test/unit/namespaces.test.js
+++ b/test/unit/namespaces.test.js
@@ -18,46 +18,17 @@
return namespaces.list()
})
-test('should retrieve namespace using id', t => {
- t.plan(2)
+test('should retrieve namespace entities', t => {
+ t.plan(16)
const client = {}
- const id = 'custom_ns'
client.request = (method, path, options) => {
t.is(method, 'GET')
- t.is(path, `namespaces/${id}`)
+ let parts = path.split('/')
+ t.is(parts[0], 'namespaces')
+ t.is(parts[1], '_')
+ t.is(["actions", "triggers", "rules", "packages"].indexOf(parts[2]) > -1, true)
}
const namespaces = new Namespaces(client)
- return namespaces.get({name: id})
-})
-
-test('should retrieve namespace using string id', t => {
- t.plan(2)
- const client = {}
- const id = 'custom_ns'
- client.request = (method, path, options) => {
- t.is(method, 'GET')
- t.is(path, `namespaces/${id}`)
- }
-
- const namespaces = new Namespaces(client)
- return namespaces.get(id)
-})
-
-test('should retrieve namespace using namespace', t => {
- t.plan(2)
- const client = {}
- const id = 'custom_ns'
- client.request = (method, path, options) => {
- t.is(method, 'GET')
- t.is(path, `namespaces/${id}`)
- }
-
- const namespaces = new Namespaces(client)
- return namespaces.get({namespace: id})
-})
-
-test('should throw error for missing namespace id', t => {
- const namespaces = new Namespaces()
- return t.throws(() => { namespaces.get() }, /Missing mandatory parameter/)
+ return namespaces.get()
})