Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions tests/fixtures/tweet_preview.json

This file was deleted.

60 changes: 60 additions & 0 deletions tests/fixtures/tweets_get.json
Original file line number Diff line number Diff line change
@@ -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": "<a href=\"https://ads-api.twitter.com\" rel=\"nofollow\">Ads API Internal Test App</a>",
"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"
}
]
}
45 changes: 45 additions & 0 deletions tests/test_tweets_get.py
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 12 additions & 0 deletions twitter_ads/creative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions twitter_ads/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down