@machinemode/cryptopia
Version:
Node wrapper for Cryptopia's CLient API
74 lines • 2.5 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Response_1 = require("./Response");
var ApiResponse = (function (_super) {
__extends(ApiResponse, _super);
function ApiResponse(statusCode, responseBody) {
var _this = _super.call(this, statusCode, responseBody) || this;
_this.Success = false;
_this.Message = '';
_this.Error = '';
_this.init(responseBody);
return _this;
}
Object.defineProperty(ApiResponse.prototype, "success", {
get: function () {
return this.Success && !this.error;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiResponse.prototype, "message", {
get: function () {
return this.Message;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiResponse.prototype, "data", {
get: function () {
return this.Data;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiResponse.prototype, "error", {
get: function () {
return this.Error;
},
enumerable: true,
configurable: true
});
ApiResponse.prototype.init = function (responseBody) {
var response;
try {
response = JSON.parse(this.body);
}
catch (error) {
this.Message = "Could not parse response\n";
}
if (this.ok && response) {
this.Success = response.Success;
this.Message = response.Message;
this.Data = response.Data;
this.Error = response.Error;
}
else {
var rawBody = this.body ? this.body.toString() : '';
this.Message += "Server responded with " + this.status + ": " + rawBody;
}
};
return ApiResponse;
}(Response_1.default));
exports.default = ApiResponse;
//# sourceMappingURL=ApiResponse.js.map