trender-client
Version:
Official Trender client API
204 lines (203 loc) • 8.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Constante_1 = require("../utils/Constante");
const RequestEmitter_1 = tslib_1.__importDefault(require("../utils/RequestEmitter"));
const PostUserManager_1 = tslib_1.__importDefault(require("./PostUserManager"));
class PostManager extends RequestEmitter_1.default {
constructor(params) {
var _a;
super(params);
Object.defineProperty(this, "user", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "cdnurl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.user = new PostUserManager_1.default(params);
this.cdnurl = (_a = params === null || params === void 0 ? void 0 : params.cdnurl) !== null && _a !== void 0 ? _a : Constante_1.cdnsiteurl;
}
file(user_id, post_id, file_name) {
return `${this.cdnurl}/posts/${user_id}/${post_id}/${file_name}`;
}
uploadFile(files) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const formdata = new FormData();
formdata.append('posts', files);
const request = yield this.uploadFiles(`/upload?type=posts`, formdata);
const response = request;
return response;
});
}
create(options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.postRequest(`/posts`, options);
const response = request;
return response;
});
}
delete(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.deleteRequest(`/posts/${target_id}`);
const response = request;
return response;
});
}
unPin(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.deleteRequest(`/posts/${target_id}/pin`);
const response = request;
return response;
});
}
pin(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.postRequest(`/posts/${target_id}/pin`, {});
const response = request;
return response;
});
}
getPinPost(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.getRequest(`/posts/${target_id}/pin`);
const response = request;
return response;
});
}
like(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.postRequest(`/posts/${target_id}/likes`, {});
const response = request;
return response;
});
}
unlike(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.deleteRequest(`/posts/${target_id}/likes`);
const response = request;
return response;
});
}
getLikesPost(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.getRequest(`/posts/${target_id}/likes`);
const response = request;
return response;
});
}
save(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.postRequest(`/posts/${target_id}/saves`);
const response = request;
return response;
});
}
unSave(target_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.deleteRequest(`/posts/${target_id}/saves`);
const response = request;
return response;
});
}
getSavedPost(target_id, params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let _url = `/posts/${target_id}/saves`;
const parameters = [];
if (params === null || params === void 0 ? void 0 : params.pagination_key)
parameters.push(`pagination_key=${params.pagination_key}`);
if (parameters.length > 0)
_url = _url.concat("?");
const request = yield this.getRequest(_url.concat(parameters.join("&")));
const response = request;
return response;
});
}
report(target_id, reason, description) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.postRequest(`/posts/${target_id}/reports`, {
reason: reason,
description: description
});
const response = request;
return response;
});
}
fetchOne(post_id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const request = yield this.getRequest(`/posts/${post_id}`);
const response = request;
return response;
});
}
comments(post_id, params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let _url = `/posts/${post_id}/comments`;
const parameters = [];
if (params === null || params === void 0 ? void 0 : params.pagination_key)
parameters.push(`pagination_key=${params.pagination_key}`);
if (parameters.length > 0)
_url = _url.concat("?");
const request = yield this.getRequest(_url.concat(parameters.join("&")));
const response = request;
return response;
});
}
shares(post_id, params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let _url = `/posts/${post_id}/shares`;
const parameters = [];
if (params === null || params === void 0 ? void 0 : params.pagination_key)
parameters.push(`pagination_key=${params.pagination_key}`);
if (parameters.length > 0)
_url = _url.concat("?");
const request = yield this.getRequest(_url.concat(parameters.join("&")));
const response = request;
return response;
});
}
fetch(params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let _url = `/posts`;
const parameters = [];
if (params === null || params === void 0 ? void 0 : params.pagination_key)
parameters.push(`pagination_key=${params.pagination_key}`);
if (parameters.length > 0)
_url = _url.concat("?");
const request = yield this.getRequest(_url.concat(parameters.join("&")));
const response = request;
return response;
});
}
search(params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let _url = `/posts/search`;
const parameters = [];
if (params === null || params === void 0 ? void 0 : params.after)
parameters.push(`after=${params.after.toString()}`);
if (params === null || params === void 0 ? void 0 : params.before)
parameters.push(`before=${params.before.toString()}`);
if (params === null || params === void 0 ? void 0 : params.query)
parameters.push(`query=${encodeURIComponent(params.query.toString())}`);
if (params === null || params === void 0 ? void 0 : params.pagination_key)
parameters.push(`pagination_key=${params.pagination_key.toString()}`);
if (params === null || params === void 0 ? void 0 : params.from)
parameters.push(`from=${params.from.toString()}`);
if (params === null || params === void 0 ? void 0 : params.locale)
parameters.push(`locale=${params.locale.toString()}`);
if (params === null || params === void 0 ? void 0 : params.type)
parameters.push(`type=${params.type.toString()}`);
if (parameters.length > 0)
_url = _url.concat("?");
const request = yield this.getRequest(_url.concat(parameters.join("&")));
const response = request;
return response;
});
}
}
exports.default = PostManager;