1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/dist/ocean-agent.js
2018-08-31 15:17:12 +02:00

31 lines
1.1 KiB
JavaScript

/* global fetch */
export default class OceanAgent {
constructor(connectionUrl) {
this.assetsUrl = connectionUrl + '/assets';
}
getAssetsMetadata() {
return fetch(this.assetsUrl + '/metadata', { method: 'GET' }).then(res => res.json()).then(data => JSON.parse(data));
}
publishDataAsset(asset) {
return fetch(this.assetsUrl + '/metadata', {
method: 'POST',
body: JSON.stringify(asset),
headers: { 'Content-type': 'application/json' }
}).then(response => {
console.log('Success:', response);
if (response.ok) {
console.log('Success:', response);
return true;
}
console.log('Failed: ', response.status, response.statusText);
return false;
// throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`)
}).catch(error => {
console.log(`Publish asset to ocean database could not be completed: ${error.message()}`);
return false;
});
}
}