Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit 48e42d7

Browse files
oedJoel Torstensson
authored andcommitted
feat(api): Add support to query the public space data api
1 parent f9fbcd4 commit 48e42d7

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/3box.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ class Box {
168168
* @param {String} opts.profileServer URL of Profile API server
169169
* @return {Object} a json object with the profile for the given address
170170
*/
171-
172171
static async getProfile (address, opts = {}) {
173172
const normalizedAddress = address.toLowerCase()
174173
opts = Object.assign({ useCacheService: true }, opts)
@@ -189,11 +188,35 @@ class Box {
189188
* @param {String} opts.profileServer URL of Profile API server
190189
* @return {Object} a json object with each key an address and value the profile
191190
*/
192-
193191
static async getProfiles (addressArray, opts = {}) {
194192
return API.getProfiles(addressArray, opts)
195193
}
196194

195+
/**
196+
* Get the public data in a space of a given address with the given name
197+
*
198+
* @param {String} address An ethereum address
199+
* @param {String} name A space name
200+
* @param {Object} opts Optional parameters
201+
* @param {String} opts.profileServer URL of Profile API server
202+
* @return {Object} a json object with the public space data
203+
*/
204+
static async getSpace (address, name, opts = {}) {
205+
return API.getSpace(address, name, opts.profileServer)
206+
}
207+
208+
/**
209+
* Get the names of all spaces a user has
210+
*
211+
* @param {String} address An ethereum address
212+
* @param {Object} opts Optional parameters
213+
* @param {String} opts.profileServer URL of Profile API server
214+
* @return {Object} an array with all spaces as strings
215+
*/
216+
static async listSpaces (address, opts = {}) {
217+
return API.listSpaces(address, opts.profileServer)
218+
}
219+
197220
static async _getProfileOrbit (address, opts = {}) {
198221
// opts = Object.assign({ iframeStore: true }, opts)
199222
console.log(opts.addressServer)

src/api.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ async function getRootStoreAddress (identifier, serverUrl = ADDRESS_SERVER_URL)
1616
throw new Error(res.message)
1717
}
1818
}
19+
async function listSpaces (address, serverUrl = PROFILE_SERVER_URL) {
20+
return new Promise(async (resolve, reject) => {
21+
try {
22+
const res = await utils.fetchJson(serverUrl + '/list-spaces?address=' + encodeURIComponent(address))
23+
resolve(res)
24+
} catch (err) {
25+
reject(err)
26+
}
27+
})
28+
}
29+
30+
async function getSpace (address, name, serverUrl = PROFILE_SERVER_URL) {
31+
return new Promise(async (resolve, reject) => {
32+
try {
33+
const res = await utils.fetchJson(serverUrl + `/space?address=${encodeURIComponent(address)}&name=${encodeURIComponent(name)}`)
34+
resolve(res)
35+
} catch (err) {
36+
reject(err)
37+
}
38+
})
39+
}
1940

2041
async function getProfile (address, serverUrl = PROFILE_SERVER_URL) {
2142
return new Promise(async (resolve, reject) => {
@@ -64,4 +85,4 @@ async function getVerifiedAccounts (profile) {
6485
return verifs
6586
}
6687

67-
module.exports = { profileGraphQL, getProfile, getRootStoreAddress, getProfiles, getVerifiedAccounts }
88+
module.exports = { profileGraphQL, getProfile, getSpace, listSpaces, getRootStoreAddress, getProfiles, getVerifiedAccounts }

0 commit comments

Comments
 (0)