UNPKG

instagram-graph-api

Version:

A library to help perform requests to the Instagram Graph API.

273 lines (272 loc) 11.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Client = void 0; const DeleteCommentRequest_1 = require("./requests/comment/DeleteCommentRequest"); const GetCommentRequest_1 = require("./requests/comment/GetCommentRequest"); const PostHideCommentRequest_1 = require("./requests/comment/PostHideCommentRequest"); const GetRepliesRequest_1 = require("./requests/comment/replies/GetRepliesRequest"); const PostReplyRequest_1 = require("./requests/comment/replies/PostReplyRequest"); const GetHashtagRecentMediaRequest_1 = require("./requests/hashtag/media/GetHashtagRecentMediaRequest"); const GetHashtagTopMediaRequest_1 = require("./requests/hashtag/media/GetHashtagTopMediaRequest"); const GetHashtagIdRequest_1 = require("./requests/hashtag/search/GetHashtagIdRequest"); const GetMediaChildrenRequest_1 = require("./requests/media/children/GetMediaChildrenRequest"); const GetMediaCommentsRequest_1 = require("./requests/media/comments/GetMediaCommentsRequest"); const PostMediaCommentRequest_1 = require("./requests/media/comments/PostMediaCommentRequest"); const GetMediaInfoRequest_1 = require("./requests/media/info/GetMediaInfoRequest"); const GetSimplePostMediaInsightsRequest_1 = require("./requests/media/insights/GetSimplePostMediaInsightsRequest"); const GetStoryMediaInsightsRequest_1 = require("./requests/media/insights/GetStoryMediaInsightsRequest"); const GetPageInfoRequest_1 = require("./requests/page/info/GetPageInfoRequest"); const GetPageDayInsightsRequest_1 = require("./requests/page/insights/GetPageDayInsightsRequest"); const GetPageLifetimeInsightsRequest_1 = require("./requests/page/insights/GetPageLifetimeInsightsRequest"); const GetPageMonthInsightsRequest_1 = require("./requests/page/insights/GetPageMonthInsightsRequest"); const GetPageWeekInsightsRequest_1 = require("./requests/page/insights/GetPageWeekInsightsRequest"); const GetPageMediaRequest_1 = require("./requests/page/media/GetPageMediaRequest"); /** * A client that creating requests. * * @author Tiago Grosso <tiagogrosso99@gmail.com> * @since 0.2.0 */ class Client { /** * The constructor. * * @param accessToken the access token. * @param pageId The id of the page. */ constructor(accessToken, pageId) { this.accessToken = accessToken; this.pageId = pageId; } /** * Gets the access token. * * @returns the access token. */ getAccessToken() { return this.accessToken; } /** * Gets the page id. * * @returns the page id. */ getPageId() { return this.pageId; } /** * Builds a new {@link GetPageInfoRequest}. * * @param fields the fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetPageInfoRequest}. */ newGetPageInfoRequest(...fields) { return new GetPageInfoRequest_1.GetPageInfoRequest(this.accessToken, this.pageId, ...fields); } /** * Builds a new {@link GetPageMediaRequest}. * * @param fields the fields to retrieve from the API for each media object. If no field is specified, all are retrieved. * * @returns a new {@link GetPageMediaRequest}. */ newGetPageMediaRequest(...fields) { return new GetPageMediaRequest_1.GetPageMediaRequest(this.accessToken, this.pageId, ...fields); } /** * Builds a new {@link GetPageLifetimeInsightsRequest}. * * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPageLifetimeInsightsRequest}. */ newGetPageLifetimeInsightsRequest(...metrics) { return new GetPageLifetimeInsightsRequest_1.GetPageLifetimeInsightsRequest(this.accessToken, this.pageId, ...metrics); } /** * Builds a new {@link GetPageDayInsightsRequest}. * * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPageDayInsightsRequest}. */ newGetPageDayInsightsRequest(...metrics) { return new GetPageDayInsightsRequest_1.GetPageDayInsightsRequest(this.accessToken, this.pageId, ...metrics); } /** * Builds a new {@link GetPageWeekInsightsRequest}. * * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPageWeekInsightsRequest}. */ newGetPageWeekInsightsRequest(...metrics) { return new GetPageWeekInsightsRequest_1.GetPageWeekInsightsRequest(this.accessToken, this.pageId, ...metrics); } /** * Builds a new {@link GetPageMonthInsightsRequest}. * * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPageMonthInsightsRequest}. */ newGetPageMonthInsightsRequest(...metrics) { return new GetPageMonthInsightsRequest_1.GetPageMonthInsightsRequest(this.accessToken, this.pageId, ...metrics); } /** * Builds a new {@link GetMediaInfoRequest}. * * @param mediaId the media object id. * @param fields the fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetMediaInfoRequest}. */ newGetMediaInfoRequest(mediaId, ...fields) { return new GetMediaInfoRequest_1.GetMediaInfoRequest(this.accessToken, mediaId, ...fields); } /** * Builds a new {@link GetMediaChildrenRequest}. * * @param mediaId the media object id. * * @returns a new {@link GetMediaChildrenRequest}. */ newGetMediaChildrenRequest(mediaId) { return new GetMediaChildrenRequest_1.GetMediaChildrenRequest(this.accessToken, mediaId); } /** * Builds a new {@link GetMediaCommentsRequest}. * * @param mediaId the media object id. * @param fields the fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetMediaCommentsRequest}. */ newGetMediaCommentsRequest(mediaId, ...fields) { return new GetMediaCommentsRequest_1.GetMediaCommentsRequest(this.accessToken, mediaId, ...fields); } /** * Builds a new {@link PostMediaCommentRequest}. * * @param mediaId the media object id. * @param text the text of the comment, * * @returns a new {@link PostMediaCommentRequest}. */ newPostMediaCommentRequest(mediaId, text) { return new PostMediaCommentRequest_1.PostMediaCommentRequest(this.accessToken, mediaId, text); } /** * Builds a new {@link GetPostMediaInsightsRequest}. * * @param mediaId the media object id (must be of type 'Photo' or 'Video'). * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPostMediaInsightsRequest}. */ newGetSimplePostMediaInsightsRequest(mediaId, ...metrics) { return new GetSimplePostMediaInsightsRequest_1.GetSimplePostMediaInsightsRequest(this.accessToken, mediaId, ...metrics); } /** * Builds a new {@link GetPostMediaInsightsRequest}. * * @param mediaId the media object id (must be of type 'Story'). * @param metrics the metrics to retrieve from the API. If no metric is specified, all are retrieved. * * @returns a new {@link GetPostMediaInsightsRequest}. */ newGetStoryMediaInsightsRequest(mediaId, ...metrics) { return new GetStoryMediaInsightsRequest_1.GetStoryMediaInsightsRequest(this.accessToken, mediaId, ...metrics); } /** * Builds a new {@link GetHashtagIdRequest}. * * @param hashtag the hashtag. * @param userId (optional) the id of the user making the request. If omitted, the page id is used. * * @returns a new {@link GetHashtagIdRequest}. */ newGetHashtagIdRequest(hashtag, userId = this.pageId) { return new GetHashtagIdRequest_1.GetHashtagIdRequest(this.accessToken, userId, hashtag); } /** * Builds a new {@link GetHashtagRecentMediaRequest}. * * @param hashtagId the hashtag id. * @param userId (optional) the id of the user making the request. If omitted, the page id is used. * @param fields the media fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetHashtagRecentMediaRequest}. */ newGetHashtagRecentMediaRequest(hashtagId, userId = this.pageId, ...fields) { return new GetHashtagRecentMediaRequest_1.GetHashtagRecentMediaRequest(this.accessToken, hashtagId, userId, ...fields); } /** * Builds a new {@link GetHashtagTopMediaRequest}. * * @param hashtagId the hashtag id. * @param userId (optional) the id of the user making the request. If omitted, the page id is used. * @param fields the media fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetHashtagTopMediaRequest}. */ newGetHashtagTopMediaRequest(hashtagId, userId = this.pageId, ...fields) { return new GetHashtagTopMediaRequest_1.GetHashtagTopMediaRequest(this.accessToken, hashtagId, userId, ...fields); } /** * Builds a new {@link GetCommentRequest}. * * @param commentId the comment id. * @param fields the comment fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetCommentRequest}. */ newGetCommentRequest(commentId, ...fields) { return new GetCommentRequest_1.GetCommentRequest(this.accessToken, commentId, ...fields); } /** * Builds a new {@link PostHideCommentRequest}. * * @param commentId the comment id. * @param hide whether to hide or show the comment (default: true). * * @returns a new {@link PostHideCommentRequest}. */ newPostHideCommentRequest(commentId, hide = true) { return new PostHideCommentRequest_1.PostHideCommentRequest(this.accessToken, commentId, hide); } /** * Builds a new {@link DeleteCommentRequest}. * * @param commentId the comment id. * * @returns a new {@link DeleteCommentRequest}. */ newDeleteCommentRequest(commentId) { return new DeleteCommentRequest_1.DeleteCommentRequest(this.accessToken, commentId); } /** * Builds a new {@link GetRepliesRequest}. * * @param commentId the comment id. * @param fields the comment fields to retrieve from the API. If no field is specified, all are retrieved. * * @returns a new {@link GetRepliesRequest}. */ newGetRepliesRequest(commentId, ...fields) { return new GetRepliesRequest_1.GetRepliesRequest(this.accessToken, commentId, ...fields); } /** * Builds a new {@link PostReplyRequest}. * * @param commentId the comment id. * @param text the text of the reply. * * @returns a new {@link PostReplyRequest}. */ newPostReplyRequest(commentId, text) { return new PostReplyRequest_1.PostReplyRequest(this.accessToken, commentId, text); } } exports.Client = Client;