instagram-graph-api
Version:
A library to help perform requests to the Instagram Graph API.
89 lines (88 loc) • 2.31 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractRequest = void 0;
const axios_1 = __importDefault(require("axios"));
const Constants_1 = require("../Constants");
/**
* Abstract class to represent requests to the Instagram Graph API.
*
* @param R the type of the response.
*
* @author Tiago Grosso <tiagogrosso99@gmail.com>
* @since 0.2.0
*/
class AbstractRequest {
/**
* The constructor.
*
* @param accessToken the access token.
*/
constructor(accessToken) {
this.params = {
access_token: accessToken,
};
}
/**
* Builds the config of the request.
*
* @returns the request config.
*/
config() {
return {
params: this.params,
method: this.method(),
url: this.url(),
baseURL: Constants_1.Constants.API_URL,
};
}
/**
* Executes the requests and returns a promise of the parsed response.
*
* @returns the promise of a parsed response.
*/
execute() {
return axios_1.default(this.config()).then((response) => {
return this.parseResponse(response);
});
}
/**
* Adds a paging param to the request.
*
* @param pageOptionToken the page option token to create the param.
*/
addPaging(pageOptionToken) {
this.params.before = undefined;
this.params.after = undefined;
this.params[pageOptionToken.option] = pageOptionToken.value;
}
/**
* Adds the range params to the request.
*
* @param since the since param.
* @param until the until param.
*/
addRange(since, until) {
this.params.since = since;
this.params.until = until;
}
/**
* Adds the limit param to the request.
*
* @param limit the number of objects to retrieve.
*/
addLimit(limit) {
this.params.limit = limit;
}
/**
* Gets the method for the request.
*
* @returns the method for the request.
*/
method() {
return 'GET';
}
}
exports.AbstractRequest = AbstractRequest;