tickethead-sdk
Version:
SDK for the Tickethead API
93 lines • 3.25 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrderbookService = void 0;
const query_string_1 = __importDefault(require("query-string"));
/**
* Service class for orderbook API calls. Requires an organizer to be set (call to `useOrganizer`)
*/
class OrderbookService {
constructor(client, version) {
this.client = client;
this.version = version;
}
/**
* Returns true if the service is reachable
* Currently the
*
* @returns Services' online status
*/
health() {
return __awaiter(this, void 0, void 0, function* () {
try {
const res = yield this.client.get(`orderbook/health`);
if (res.data.status === 'ok') {
return { online: true };
}
}
catch (e) {
// Do nothing
}
return { online: false };
});
}
/**
* Returns all available offers
*
* @returns
*/
listOffers() {
return __awaiter(this, arguments, void 0, function* (req = {}) {
const query = query_string_1.default.stringify(req, {
arrayFormat: 'comma',
skipNull: true,
skipEmptyString: true,
});
const res = yield this.client.get(`orderbook/${this.version}/offer?${query}`);
return res.data.data;
});
}
/**
* Creates a new order
*/
createOrder(orderData) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`orderbook/${this.version}/order`, orderData);
return res.data.data;
});
}
/**
* Returns all offers which belong to the current user
*
* @returns
*/
getMine() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.get(`orderbook/${this.version}/offer/mine`);
return res.data.data;
});
}
/**
* Delete the given offer from the orderbook
*
* @param offerId
*/
deleteOffer(offerId) {
return __awaiter(this, void 0, void 0, function* () {
yield this.client.delete(`orderbook/${this.version}/offer/${offerId.id}`);
});
}
}
exports.OrderbookService = OrderbookService;
//# sourceMappingURL=service.js.map