From 12a80568f191295976a02548f730b60513f71791 Mon Sep 17 00:00:00 2001 From: Tiago Grosso Date: Sun, 21 Jan 2024 13:30:50 +0000 Subject: [PATCH] fix: remove deprecated VIDEO container (#310) Removes the ability to publish non-reel VIDEO containers, a feature that has been removed from Instagram Graph API BREAKING CHANGE: The PostPageVideoMediaRequest class and related client methods has been removed since it was no longer functional This also means that it is no longer possible to publish videos to CAROUSEL media via the API. Removed 'VIDEO' from MediaType enum --- src/it/page/PublishMediaRequests.test.ts | 24 +++---- src/main/Client.ts | 27 -------- .../media/AbstractPostPageMediaRequest.ts | 2 - .../page/media/PostPageVideoMediaRequest.ts | 66 ------------------- src/test/Client.test.ts | 33 +--------- .../media/PostPageVideoMediaRequest.test.ts | 60 ----------------- 6 files changed, 10 insertions(+), 202 deletions(-) delete mode 100644 src/main/requests/page/media/PostPageVideoMediaRequest.ts delete mode 100644 src/test/requests/page/media/PostPageVideoMediaRequest.test.ts diff --git a/src/it/page/PublishMediaRequests.test.ts b/src/it/page/PublishMediaRequests.test.ts index 86e042ce..aef13b29 100644 --- a/src/it/page/PublishMediaRequests.test.ts +++ b/src/it/page/PublishMediaRequests.test.ts @@ -1,10 +1,10 @@ -import { getClient, getPageId, getRandomPhoto, getRandomVideo, Media } from '../TestEnv'; +import { AxiosError } from 'axios'; import retry from 'retry'; -import { CONTAINER_STATUS_CODE } from '../../main/requests/data/ContainerData'; import { MediaProductType, MediaTypeInResponses } from '../../main/Enums'; +import { CONTAINER_STATUS_CODE } from '../../main/requests/data/ContainerData'; import { MediaData } from '../../main/requests/data/MediaData'; import { AbstractPostPageMediaRequest } from '../../main/requests/page/media/AbstractPostPageMediaRequest'; -import { AxiosError } from 'axios'; +import { getClient, getPageId, getRandomPhoto, getRandomVideo, Media } from '../TestEnv'; describe('PublishMedia', () => { it('Publishes photo media', async () => { @@ -14,25 +14,18 @@ describe('PublishMedia', () => { await publishAndAssertSimpleMedia(containerId, media); }); - it('Publishes video media', async () => { - const media = getRandomVideo(); - const postVideoRequest = getClient().newPostPageVideoMediaRequest(media.url, media.caption); - const containerId = await createContainerAndWaitToBeReady(postVideoRequest); - await publishAndAssertSimpleMedia(containerId, media); - }); - it('Publishes carousel media', async () => { const photoMedia = getRandomPhoto(); - const videoMedia = getRandomVideo(); + const photoMedia2 = getRandomPhoto(); const postPhotoRequest = getClient() .newPostPagePhotoMediaRequest(photoMedia.url, photoMedia.caption) .withIsCarousel(true); - const postVideoRequest = getClient() - .newPostPageVideoMediaRequest(videoMedia.url, videoMedia.caption) + const postPhotoRequest2 = getClient() + .newPostPagePhotoMediaRequest(photoMedia2.url, photoMedia2.caption) .withIsCarousel(true); const photoContainerId = await createContainerAndWaitToBeReady(postPhotoRequest); - const videoContainerId = await createContainerAndWaitToBeReady(postVideoRequest); + const videoContainerId = await createContainerAndWaitToBeReady(postPhotoRequest2); const carouselCaption = 'Sample caption'; const postCarouselRequest = getClient().newPostPageCarouselMediaRequest( @@ -83,7 +76,8 @@ function waitForContainerToBeReady(containerId: string): Promise { const response = await getContainerStatusRequest.execute(); const statusCode = response.getContainerStatusCode(); if (statusCode === CONTAINER_STATUS_CODE.ERROR) { - console.error(response.getContainerStatus()); + //console.error(response.getContainerStatus()); + console.error(response); resolve(false); operation.stop(); } diff --git a/src/main/Client.ts b/src/main/Client.ts index 7c944f19..0095eedf 100644 --- a/src/main/Client.ts +++ b/src/main/Client.ts @@ -38,7 +38,6 @@ import { GetInstagramAccountInfoRequest } from './requests/page/instagram_accoun import { GetPageMediaRequest } from './requests/page/media/GetPageMediaRequest'; import { PostPageCarouselMediaRequest } from './requests/page/media/PostPageCarouselMediaRequest'; import { PostPagePhotoMediaRequest } from './requests/page/media/PostPagePhotoMediaRequest'; -import { PostPageVideoMediaRequest } from './requests/page/media/PostPageVideoMediaRequest'; import { PostPublishMediaRequest } from './requests/page/media_publish/PostPublishMediaRequest'; import { GetPageRecentlySearchedHashtagsRequest } from './requests/page/recently_searched_hashtags/GetPageRecentlySearchedHashtagsRequest'; import { GetPageStoriesRequest } from './requests/page/stories/GetPageStoriesRequest'; @@ -405,32 +404,6 @@ export class Client { ).withApiVersion(this.apiVersion); } - /** - * Build a new {@link PostPageVideoMediaRequest}. - * - * @param videoUrl the image URL. - * @param caption the caption. - * @param thumbOffset the thumbnail offset time in milliseconds. - * @param locationId the location id. - * - * @returns a new {@link PostPageVideoMediaRequest}. - */ - public newPostPageVideoMediaRequest( - videoUrl: string, - caption?: string, - thumbOffset?: number, - locationId?: string - ): PostPageVideoMediaRequest { - return new PostPageVideoMediaRequest( - this.accessToken, - this.pageId, - videoUrl, - caption, - thumbOffset, - locationId - ).withApiVersion(this.apiVersion); - } - /** * Build a new {@link PostPageReelMediaRequest}. * diff --git a/src/main/requests/page/media/AbstractPostPageMediaRequest.ts b/src/main/requests/page/media/AbstractPostPageMediaRequest.ts index eedee86b..71788678 100644 --- a/src/main/requests/page/media/AbstractPostPageMediaRequest.ts +++ b/src/main/requests/page/media/AbstractPostPageMediaRequest.ts @@ -93,8 +93,6 @@ export abstract class AbstractPostPageMediaRequest extends AbstractRequest - * @since 1.1.0 - */ -export class PostPageVideoMediaRequest extends AbstractPostPageMediaRequest { - /** - * The constructor - * - * @param accessToken the access token. - * @param pageId the page id. - * @param videoUrl the video URL. - * @param caption the caption. - * @param thumbOffset the thumbnail offset. - * @param locationId the location id. - * @param isCarousel whether it is a carousel. - */ - constructor( - accessToken: string, - pageId: string, - videoUrl: string, - caption?: string, - thumbOffset?: number, - locationId?: string, - isCarousel = false - ) { - super(accessToken, pageId, caption, locationId); - this.params.video_url = videoUrl; - this.params.thumb_offset = thumbOffset; - this.params.is_carousel = isCarousel; - } - - /** - * Sets the thumbnail offset time in the request. - * - * @param thumbOffset the thumbnail offset time. - * - * @returns this object, for chained invocation. - */ - public withThumbOffset(thumbOffset: number): this { - this.params.thumb_offset = thumbOffset; - return this; - } - - /** - * Sets the is_carousel param in the request. - * - * @param isCarousel whether it is a carousel. - * - * @returns this object, for chained invocation. - */ - public withIsCarousel(isCarousel: boolean): this { - this.params.is_carousel = isCarousel; - return this; - } - - /** - * @inheritdoc - */ - protected mediaType(): MediaType | undefined { - return MediaType.VIDEO; - } -} diff --git a/src/test/Client.test.ts b/src/test/Client.test.ts index e392c1ca..0a66e65d 100644 --- a/src/test/Client.test.ts +++ b/src/test/Client.test.ts @@ -38,13 +38,12 @@ import { GetInstagramAccountInfoRequest } from '../main/requests/page/instagram_ import { GetPageMediaRequest } from '../main/requests/page/media/GetPageMediaRequest'; import { PostPageCarouselMediaRequest } from '../main/requests/page/media/PostPageCarouselMediaRequest'; import { PostPagePhotoMediaRequest } from '../main/requests/page/media/PostPagePhotoMediaRequest'; -import { PostPageVideoMediaRequest } from '../main/requests/page/media/PostPageVideoMediaRequest'; +import { PostPageReelMediaRequest } from '../main/requests/page/media/PostPageReelMediaRequest'; import { PostPublishMediaRequest } from '../main/requests/page/media_publish/PostPublishMediaRequest'; import { GetPageRecentlySearchedHashtagsRequest } from '../main/requests/page/recently_searched_hashtags/GetPageRecentlySearchedHashtagsRequest'; import { GetPageStoriesRequest } from '../main/requests/page/stories/GetPageStoriesRequest'; import { GetTagsRequest } from '../main/requests/page/tags/GetTagsRequest'; import { TestConstants } from './TestConstants'; -import { PostPageReelMediaRequest } from '../main/requests/page/media/PostPageReelMediaRequest'; describe('Client', () => { const client: Client = new Client(TestConstants.ACCESS_TOKEN, TestConstants.PAGE_ID); @@ -498,36 +497,6 @@ describe('Client', () => { ); }); - it('Builds a PostPageVideoMediaRequest', () => { - expect(client.newPostPageVideoMediaRequest(TestConstants.MEDIA_URL)).toEqual( - new PostPageVideoMediaRequest(TestConstants.ACCESS_TOKEN, TestConstants.PAGE_ID, TestConstants.MEDIA_URL) - ); - expect(clientExplicitVersion.newPostPageVideoMediaRequest(TestConstants.MEDIA_URL)).toEqual( - new PostPageVideoMediaRequest( - TestConstants.ACCESS_TOKEN, - TestConstants.PAGE_ID, - TestConstants.MEDIA_URL - ).withApiVersion(TestConstants.API_VERSION) - ); - expect( - client.newPostPageVideoMediaRequest( - TestConstants.MEDIA_URL, - TestConstants.CAPTION, - TestConstants.THUMB_OFFSET, - TestConstants.LOCATION_ID - ) - ).toEqual( - new PostPageVideoMediaRequest( - TestConstants.ACCESS_TOKEN, - TestConstants.PAGE_ID, - TestConstants.MEDIA_URL, - TestConstants.CAPTION, - TestConstants.THUMB_OFFSET, - TestConstants.LOCATION_ID - ) - ); - }); - it('Builds a PostPageReelMediaRequest', () => { expect(client.newPostPageReelMediaRequest(TestConstants.MEDIA_URL)).toEqual( new PostPageReelMediaRequest(TestConstants.ACCESS_TOKEN, TestConstants.PAGE_ID, TestConstants.MEDIA_URL) diff --git a/src/test/requests/page/media/PostPageVideoMediaRequest.test.ts b/src/test/requests/page/media/PostPageVideoMediaRequest.test.ts deleted file mode 100644 index f1936532..00000000 --- a/src/test/requests/page/media/PostPageVideoMediaRequest.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -import axios from 'axios'; -import MockAdapter from 'axios-mock-adapter'; -import { Constants } from '../../../../main/Constants'; -import { CreatedObjectIdResponse } from '../../../../main/requests/common/CreatedObjectIdResponse'; -import { PostPageVideoMediaRequest } from '../../../../main/requests/page/media/PostPageVideoMediaRequest'; -import { TestConstants } from '../../../TestConstants'; - -describe('PostPageVideoMediaRequest.', () => { - const request: PostPageVideoMediaRequest = new PostPageVideoMediaRequest( - TestConstants.ACCESS_TOKEN, - TestConstants.PAGE_ID, - TestConstants.MEDIA_URL, - TestConstants.CAPTION, - TestConstants.THUMB_OFFSET, - TestConstants.LOCATION_ID, - true - ); - const requestBare: PostPageVideoMediaRequest = new PostPageVideoMediaRequest( - TestConstants.ACCESS_TOKEN, - TestConstants.PAGE_ID, - TestConstants.MEDIA_URL - ); - - it('Builds the config', () => { - expect(request.config().method).toEqual('POST'); - expect(request.config().url).toEqual(`/${TestConstants.PAGE_ID}/media`); - expect(request.config().params.video_url).toEqual(TestConstants.MEDIA_URL); - expect(request.config().params.caption).toEqual(TestConstants.CAPTION); - expect(request.config().params.thumb_offset).toEqual(TestConstants.THUMB_OFFSET); - expect(request.config().params.location_id).toEqual(TestConstants.LOCATION_ID); - expect(request.config().params.is_carousel).toBeTruthy(); - }); - - it('Adds params request config', () => { - expect(requestBare.config().params.video_url).toEqual(TestConstants.MEDIA_URL); - expect(requestBare.config().params.caption).toBeUndefined(); - expect(requestBare.config().params.location_id).toBeUndefined(); - expect(requestBare.config().params.thumb_offset).toBeUndefined(); - expect(requestBare.config().params.is_carousel).toBeFalsy(); - - requestBare.withCaption(TestConstants.CAPTION); - requestBare.withLocationId(TestConstants.LOCATION_ID); - requestBare.withThumbOffset(TestConstants.THUMB_OFFSET); - requestBare.withIsCarousel(true); - - expect(requestBare.config().params.caption).toEqual(TestConstants.CAPTION); - expect(requestBare.config().params.thumb_offset).toEqual(TestConstants.THUMB_OFFSET); - expect(requestBare.config().params.location_id).toEqual(TestConstants.LOCATION_ID); - expect(requestBare.config().params.is_carousel).toBeTruthy(); - }); - - const mock = new MockAdapter(axios); - mock.onPost(`${Constants.API_URL}/${TestConstants.PAGE_ID}/media`).reply(200, { id: TestConstants.CONTAINER_ID }); - it('Parses the response', () => { - expect.assertions(1); - return request.execute().then((response) => { - expect(response).toEqual(new CreatedObjectIdResponse({ id: TestConstants.CONTAINER_ID })); - }); - }); -});