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 18:14:27 +02:00

60 lines
2.0 KiB
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* global fetch */
var OceanAgent = function () {
function OceanAgent(connectionUrl) {
(0, _classCallCheck3.default)(this, OceanAgent);
this.assetsUrl = connectionUrl + '/assets';
}
(0, _createClass3.default)(OceanAgent, [{
key: 'getAssetsMetadata',
value: function getAssetsMetadata() {
return fetch(this.assetsUrl + '/metadata', { method: 'GET' }).then(function (res) {
return res.json();
}).then(function (data) {
return JSON.parse(data);
});
}
}, {
key: 'publishDataAsset',
value: function publishDataAsset(asset) {
return fetch(this.assetsUrl + '/metadata', {
method: 'POST',
body: JSON.stringify(asset),
headers: { 'Content-type': 'application/json' }
}).then(function (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(function (error) {
console.log('Publish asset to ocean database could not be completed: ' + error.message());
return false;
});
}
}]);
return OceanAgent;
}();
exports.default = OceanAgent;