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

60 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-08-31 16:26:23 +02:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
2018-08-31 18:14:27 +02:00
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
2018-08-31 16:26:23 +02:00
2018-08-31 18:14:27 +02:00
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 }; }
2018-08-31 16:26:23 +02:00
2018-08-31 15:17:12 +02:00
/* global fetch */
2018-08-31 16:26:23 +02:00
var OceanAgent = function () {
function OceanAgent(connectionUrl) {
2018-08-31 18:14:27 +02:00
(0, _classCallCheck3.default)(this, OceanAgent);
2018-08-31 15:17:12 +02:00
2018-08-31 16:26:23 +02:00
this.assetsUrl = connectionUrl + '/assets';
2018-08-31 15:17:12 +02:00
}
2018-08-31 18:14:27 +02:00
(0, _createClass3.default)(OceanAgent, [{
2018-08-31 16:26:23 +02:00
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) {
2018-08-31 15:17:12 +02:00
console.log('Success:', response);
2018-08-31 16:26:23 +02:00
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;