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

62 lines
1.8 KiB
JavaScript
Raw Normal View History

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2018-08-31 16:26:23 +02:00
Object.defineProperty(exports, "__esModule", {
value: true
2018-08-31 16:26:23 +02:00
});
exports.default = void 0;
2018-08-31 16:26:23 +02:00
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
2018-08-31 18:14:27 +02:00
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
2018-08-31 16:26:23 +02:00
2018-08-31 15:17:12 +02:00
/* global fetch */
var OceanAgent =
/*#__PURE__*/
function () {
function OceanAgent(connectionUrl) {
(0, _classCallCheck2.default)(this, OceanAgent);
this.assetsUrl = connectionUrl + '/assets';
}
(0, _createClass2.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);
});
2018-08-31 15:17:12 +02:00
}
}, {
key: "publishDataAsset",
value: function publishDataAsset(asset) {
return fetch(this.assetsUrl + '/metadata', {
method: 'POST',
body: JSON.stringify(asset),
headers: {
'Content-type': 'application/json'
2018-08-31 16:26:23 +02:00
}
}).then(function (response) {
console.log('Success:', response);
if (response.ok) {
console.log('Success:', response);
return true;
2018-08-31 16:26:23 +02:00
}
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: ".concat(error.message()));
return false;
});
}
}]);
return OceanAgent;
2018-08-31 16:26:23 +02:00
}();
exports.default = OceanAgent;