twitch-api-ts
Version:
Modern wrapper for the Twitch API with typings.
62 lines • 2.69 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelPointsClient = void 0;
class ChannelPointsClient {
constructor(api) {
this.api = api;
}
createCustomReward(props) {
return __awaiter(this, void 0, void 0, function* () {
const broadcaster_id = (yield this.api.getCurrentUser()).id;
const { data } = yield this.api.post('channel_points/custom_rewards', { broadcaster_id }, props);
return data[0];
});
}
deleteCustomReward(id) {
return __awaiter(this, void 0, void 0, function* () {
const broadcaster_id = (yield this.api.getCurrentUser()).id;
yield this.api.delete('channel_points/custom_rewards', {
broadcaster_id,
id,
});
return true;
});
}
getCustomReward(id) {
return __awaiter(this, void 0, void 0, function* () {
const broadcaster_id = (yield this.api.getCurrentUser()).id;
const reward = yield this.api
.get('channel_points/custom_rewards', {
broadcaster_id,
id,
})
.catch((e) => {
if (e.getStatusCode() == 404)
return null;
throw e;
});
return reward === null || reward === void 0 ? void 0 : reward.data[0];
});
}
getCustomRewards(only_manageable_rewards = false) {
return __awaiter(this, void 0, void 0, function* () {
const broadcaster_id = (yield this.api.getCurrentUser()).id;
const { data } = yield this.api.get('channel_points/custom_rewards', {
broadcaster_id,
only_manageable_rewards,
});
return data;
});
}
}
exports.ChannelPointsClient = ChannelPointsClient;
//# sourceMappingURL=channel-points-client.js.map
;