UNPKG

x-api-sdk-ts

Version:

TypeScript Library for the X (ex-twitter) API V2

107 lines 4.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Posts = void 0; const IPosts_1 = require("../interfaces/api/IPosts"); class Posts extends IPosts_1.AbstractPosts { async create(text, options) { const requestBody = { text }; if (options) { if (options.card_uri) requestBody.card_uri = options.card_uri; if (options.community_id) requestBody.community_id = options.community_id; if (options.direct_message_deep_link) requestBody.direct_message_deep_link = options.direct_message_deep_link; if (options.for_super_followers_only !== undefined) requestBody.for_super_followers_only = options.for_super_followers_only; if (options.nullcast !== undefined) requestBody.nullcast = options.nullcast; if (options.quote_tweet_id) requestBody.quote_tweet_id = options.quote_tweet_id; if (options.reply_settings) requestBody.reply_settings = options.reply_settings; if (options.geo) requestBody.geo = options.geo; if (options.media) requestBody.media = options.media; if (options.poll) requestBody.poll = options.poll; if (options.reply) requestBody.reply = options.reply; } const headers = await this.oAuth2.getHeaders(); return await this.requestClient.post(`${this.baseUrl}/2/tweets`, requestBody, { ...headers, 'Content-Type': 'application/json' }); } async delete(id) { const headers = await this.oAuth2.getHeaders(); return await this.requestClient.delete(`${this.baseUrl}/2/tweets/${id}`, { ...headers, 'Content-Type': 'application/json' }); } async get(id, options) { var _a, _b, _c, _d, _e, _f; const headers = await this.oAuth2.getHeaders(); const params = {}; if (options) { if ((_a = options.tweetFields) === null || _a === void 0 ? void 0 : _a.length) { params['tweet.fields'] = options.tweetFields; } if ((_b = options.expansions) === null || _b === void 0 ? void 0 : _b.length) { params.expansions = options.expansions; } if ((_c = options.mediaFields) === null || _c === void 0 ? void 0 : _c.length) { params['media.fields'] = options.mediaFields; } if ((_d = options.pollFields) === null || _d === void 0 ? void 0 : _d.length) { params['poll.fields'] = options.pollFields; } if ((_e = options.userFields) === null || _e === void 0 ? void 0 : _e.length) { params['user.fields'] = options.userFields; } if ((_f = options.placeFields) === null || _f === void 0 ? void 0 : _f.length) { params['place.fields'] = options.placeFields; } } return await this.requestClient.get(`${this.baseUrl}/2/tweets/${id}`, params, { ...headers, 'Content-Type': 'application/json' }); } async getMultiple(ids, options) { var _a, _b, _c, _d, _e, _f; const headers = await this.oAuth2.getHeaders(); const params = { ids }; if (options) { if ((_a = options.tweetFields) === null || _a === void 0 ? void 0 : _a.length) { params['tweet.fields'] = options.tweetFields; } if ((_b = options.expansions) === null || _b === void 0 ? void 0 : _b.length) { params.expansions = options.expansions; } if ((_c = options.mediaFields) === null || _c === void 0 ? void 0 : _c.length) { params['media.fields'] = options.mediaFields; } if ((_d = options.pollFields) === null || _d === void 0 ? void 0 : _d.length) { params['poll.fields'] = options.pollFields; } if ((_e = options.userFields) === null || _e === void 0 ? void 0 : _e.length) { params['user.fields'] = options.userFields; } if ((_f = options.placeFields) === null || _f === void 0 ? void 0 : _f.length) { params['place.fields'] = options.placeFields; } } return await this.requestClient.get(`${this.baseUrl}/2/tweets`, params, { ...headers, 'Content-Type': 'application/json' }); } } exports.Posts = Posts; //# sourceMappingURL=posts.js.map