From c9414c3a3ceb5b72c6355cf9150262f12da4775b Mon Sep 17 00:00:00 2001 From: smaeda-ks Date: Tue, 17 Sep 2019 20:26:47 +0900 Subject: [PATCH 1/4] Add new Tweets endpoint --- twitter_ads/creative.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/twitter_ads/creative.py b/twitter_ads/creative.py index 29d9a87..ff5732f 100644 --- a/twitter_ads/creative.py +++ b/twitter_ads/creative.py @@ -580,3 +580,15 @@ def load(klass, account, **kwargs): # read-only resource_property(TweetPreview, 'preview', readonly=True) resource_property(TweetPreview, 'tweet_id', readonly=True) + + +class Tweets(object): + + RESOURCE_COLLECTION = '/' + API_VERSION + '/accounts/{account_id}/tweets' + + @classmethod + @FlattenParams + def all(klass, account, **kwargs): + resource = klass.RESOURCE_COLLECTION.format(account_id=account.id) + request = Request(account.client, 'get', resource, params=kwargs) + return Cursor(None, request) From 632af3d7dcfd9b68b8ceec45c4a3ceba0aaf2d84 Mon Sep 17 00:00:00 2001 From: smaeda-ks Date: Tue, 17 Sep 2019 20:31:12 +0900 Subject: [PATCH 2/4] Add Enum --- twitter_ads/enum.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/twitter_ads/enum.py b/twitter_ads/enum.py index 967cd93..722dd76 100644 --- a/twitter_ads/enum.py +++ b/twitter_ads/enum.py @@ -195,6 +195,12 @@ def enum(**enums): SCHEDULED='SCHEDULED' ) +TIMELINE_TYPE = enum( + ALL='ALL', + NULLCAST='NULLCAST', + ORGANIC='ORGANIC' +) + SEGMENTATION_TYPE = enum( AGE='AGE', APP_STORE_CATEGORY='APP_STORE_CATEGORY', From a626f8932229df2e6bdb856919d0d8e5ffbf9cef Mon Sep 17 00:00:00 2001 From: smaeda-ks Date: Tue, 17 Sep 2019 20:31:35 +0900 Subject: [PATCH 3/4] remove deprecated fixtures --- tests/fixtures/tweet_preview.json | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 tests/fixtures/tweet_preview.json diff --git a/tests/fixtures/tweet_preview.json b/tests/fixtures/tweet_preview.json deleted file mode 100644 index 2a43ed9..0000000 --- a/tests/fixtures/tweet_preview.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "data_type": "tweet_preview", - "data": [ - { - "platform": "web", - "preview": "
Hello World!
Ratings/pricing not available for preview Ratings/pricing not available for preview
INSTALL
Promoted by AdsAPI
" - }, - { - "platform": "android", - "preview": "
Hello World!
Ratings/pricing not available for preview Ratings/pricing not available for preview
INSTALL
Promoted by AdsAPI
" - }, - { - "platform": "iphone", - "preview": "
Hello World!
Ratings/pricing not available for preview Ratings/pricing not available for preview
INSTALL
Promoted by AdsAPI
" - } - ], - "request": { - "params": { - "status": "Hello World!", - "card_id": "pfs", - "account_id": "2iqph" - } - } -} From cabd8927efa9d0ff4379976b9da8fe23633c2d9f Mon Sep 17 00:00:00 2001 From: smaeda-ks Date: Tue, 17 Sep 2019 20:42:31 +0900 Subject: [PATCH 4/4] Add test --- tests/fixtures/tweets_get.json | 60 ++++++++++++++++++++++++++++++++++ tests/test_tweets_get.py | 45 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 tests/fixtures/tweets_get.json create mode 100644 tests/test_tweets_get.py diff --git a/tests/fixtures/tweets_get.json b/tests/fixtures/tweets_get.json new file mode 100644 index 0000000..b51fe27 --- /dev/null +++ b/tests/fixtures/tweets_get.json @@ -0,0 +1,60 @@ +{ + "request": { + "params": { + "tweet_ids": [ + "1166476031668015104" + ], + "tweet_type": "PUBLISHED", + "trim_user": true, + "account_id": "2iqph" + } + }, + "next_cursor": null, + "data": [ + { + "coordinates": null, + "retweeted": false, + "source": "Ads API Internal Test App", + "entities": { + "hashtags": [], + "symbols": [], + "user_mentions": [], + "urls": [] + }, + "display_text_range": [ + 0, + 9 + ], + "favorite_count": 0, + "in_reply_to_status_id_str": null, + "geo": null, + "id_str": "1166476031668015104", + "scopes": { + "followers": false + }, + "in_reply_to_user_id": null, + "truncated": false, + "retweet_count": 0, + "id": 1166476031668015104, + "in_reply_to_status_id": null, + "nullcast": true, + "created_at": "Tue Aug 27 22:22:12 +0000 2019", + "place": null, + "scheduled_at": null, + "tweet_type": "PUBLISHED", + "favorited": false, + "full_text": "hello, v6", + "lang": "es", + "contributors": [ + 2417045708 + ], + "in_reply_to_screen_name": null, + "in_reply_to_user_id_str": null, + "user": { + "id": 756201191646691328, + "id_str": "756201191646691328" + }, + "tweet_id": "1166476031668015104" + } + ] +} \ No newline at end of file diff --git a/tests/test_tweets_get.py b/tests/test_tweets_get.py new file mode 100644 index 0000000..95802cf --- /dev/null +++ b/tests/test_tweets_get.py @@ -0,0 +1,45 @@ +import responses +import unittest + +from tests.support import with_resource, with_fixture, characters + +from twitter_ads.account import Account +from twitter_ads.creative import Tweets +from twitter_ads.client import Client +from twitter_ads.cursor import Cursor +from twitter_ads.enum import TWEET_TYPE +from twitter_ads import API_VERSION + + +@responses.activate +def test_tweets_get_all(): + responses.add(responses.GET, + with_resource('/' + API_VERSION + '/accounts/2iqph'), + body=with_fixture('accounts_load'), + content_type='application/json') + + responses.add(responses.GET, + with_resource('/' + API_VERSION + '/accounts/2iqph/tweets'), + body=with_fixture('tweets_get'), + content_type='application/json') + + client = Client( + characters(40), + characters(40), + characters(40), + characters(40) + ) + + account = Account.load(client, '2iqph') + + tweets = Tweets.all( + account, + tweet_ids=['1166476031668015104'], + tweet_type=TWEET_TYPE.PUBLISHED, + trim_user=True + ) + + assert tweets is not None + assert isinstance(tweets, Cursor) + assert tweets.count == 1 + assert tweets.first['tweet_id'] == '1166476031668015104'