Skip to content

Commit 1b643af

Browse files
authored
Draft campaigns (xdevplatform#137)
* `entity_status` * add enums * add read resource attributes * update fixtures * add tests * update docs * update examples * misc: * remove `JOB_STATUS` * remove the `currency` property from campaigns * add missing line item resource properties
1 parent 57821ff commit 1b643af

13 files changed

+283
-287
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Quick Start
1616
1717
from twitter_ads.client import Client
1818
from twitter_ads.campaign import Campaign
19+
from twitter_ads.enum import ENTITY_STATUS
1920
2021
CONSUMER_KEY = 'your consumer key'
2122
CONSUMER_SECRET = 'your consumer secret'
@@ -33,7 +34,7 @@ Quick Start
3334
# load and update a specific campaign
3435
campaign = account.campaigns().next()
3536
campaign.name = 'updated campaign name'
36-
campaign.paused = True
37+
campaign.entity_status = ENTITY_STATUS.PAUSED
3738
campaign.save()
3839
3940
# iterate through campaigns

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Quick Start
3030
3131
from twitter_ads.client import Client
3232
from twitter_ads.campaign import Campaign
33+
from twitter_ads.enum import ENTITY_STATUS
3334
3435
# initialize the client
3536
client = Client(CONSUMER_KEY,
@@ -43,7 +44,7 @@ Quick Start
4344
# load and update a specific campaign
4445
campaign = list(account.campaigns())[0]
4546
campaign.name = 'updated campaign name'
46-
campaign.paused = True
47+
campaign.entity_status = ENTITY_STATUS.PAUSED
4748
campaign.save()
4849
4950
# iterate through campaigns

examples/batch_request.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from twitter_ads.client import Client
44
from twitter_ads.campaign import Campaign, LineItem, TargetingCriteria
5-
from twitter_ads.enum import PRODUCT, PLACEMENT, OBJECTIVE
5+
from twitter_ads.enum import ENTITY_STATUS, OBJECTIVE, PLACEMENT, PRODUCT
66

77
CONSUMER_KEY = 'your consumer key'
88
CONSUMER_SECRET = 'your consumer secret'
@@ -21,14 +21,14 @@
2121
campaign_1.funding_instrument_id = account.funding_instruments().next().id
2222
campaign_1.daily_budget_amount_local_micro = 1000000
2323
campaign_1.name = 'my first campaign'
24-
campaign_1.paused = True
24+
campaign_1.entity_status = ENTITY_STATUS.PAUSED
2525
campaign_1.start_time = datetime.utcnow()
2626

2727
campaign_2 = Campaign(account)
2828
campaign_2.funding_instrument_id = account.funding_instruments().next().id
2929
campaign_2.daily_budget_amount_local_micro = 2000000
3030
campaign_2.name = 'my second campaign'
31-
campaign_2.paused = True
31+
campaign_2.entity_status = ENTITY_STATUS.PAUSED
3232
campaign_2.start_time = datetime.utcnow()
3333

3434
campaigns_list = [campaign_1, campaign_2]
@@ -48,7 +48,7 @@
4848
line_item_1.placements = [PLACEMENT.ALL_ON_TWITTER]
4949
line_item_1.objective = OBJECTIVE.TWEET_ENGAGEMENTS
5050
line_item_1.bid_amount_local_micro = 10000
51-
line_item_1.paused = True
51+
line_item_1.entity_status = ENTITY_STATUS.PAUSED
5252

5353
line_item_2 = LineItem(account)
5454
line_item_2.campaign_id = campaign_1.id
@@ -57,7 +57,7 @@
5757
line_item_2.placements = [PLACEMENT.ALL_ON_TWITTER]
5858
line_item_2.objective = OBJECTIVE.TWEET_ENGAGEMENTS
5959
line_item_2.bid_amount_local_micro = 20000
60-
line_item_2.paused = True
60+
line_item_2.entity_status = ENTITY_STATUS.PAUSED
6161

6262
line_items_list = [line_item_1, line_item_2]
6363
LineItem.batch_save(account, line_items_list)
@@ -89,4 +89,4 @@
8989
campaign_1.to_delete = True
9090
campaign_2.to_delete = True
9191

92-
Campaign.batch_save(account, campaigns_list)
92+
Campaign.batch_save(account, campaigns_list)

examples/quick_start.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from twitter_ads.client import Client
44
from twitter_ads.campaign import Campaign, LineItem, TargetingCriteria
5-
from twitter_ads.enum import PRODUCT, PLACEMENT, OBJECTIVE
5+
from twitter_ads.enum import ENTITY_STATUS, OBJECTIVE, PLACEMENT, PRODUCT
66

77
CONSUMER_KEY = 'your consumer key'
88
CONSUMER_SECRET = 'your consumer secret'
@@ -21,7 +21,7 @@
2121
campaign.funding_instrument_id = account.funding_instruments().next().id
2222
campaign.daily_budget_amount_local_micro = 1000000
2323
campaign.name = 'my first campaign'
24-
campaign.paused = True
24+
campaign.entity_status = ENTITY_STATUS.PAUSED
2525
campaign.start_time = datetime.utcnow()
2626
campaign.save()
2727

@@ -33,7 +33,7 @@
3333
line_item.placements = [PLACEMENT.ALL_ON_TWITTER]
3434
line_item.objective = OBJECTIVE.TWEET_ENGAGEMENTS
3535
line_item.bid_amount_local_micro = 10000
36-
line_item.paused = True
36+
line_item.entity_status = ENTITY_STATUS.PAUSED
3737
line_item.save()
3838

3939
# add targeting criteria

examples/video_tutorial.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from twitter_ads.client import Client
2-
from twitter_ads.enum import CREATIVE_TYPE, OBJECTIVE, PRODUCT
2+
from twitter_ads.enum import CREATIVE_TYPE, ENTITY_STATUS, OBJECTIVE, PRODUCT
33
from twitter_ads.campaign import Campaign, LineItem
44
from twitter_ads.creative import AccountMedia, Video
55
from twitter_ads import API_VERSION
@@ -44,7 +44,7 @@
4444
# get the first funding instrument on the account
4545
campaign.funding_instrument_id = account.funding_instruments().first.id
4646
campaign.daily_budget_amount_local_micro = 1000000000
47-
campaign.paused = True
47+
campaign.entity_status = ENTITY_STATUS.PAUSED
4848
campaign.start_time = datetime.utcnow()
4949
campaign.save()
5050

@@ -58,7 +58,7 @@
5858
line_item.product_type = 'MEDIA'
5959
line_item.placements = [PLACEMENT.ALL_ON_TWITTER]
6060
line_item.bid_amount_local_micro = 1000000
61-
line_item.paused = True
61+
line_item.entity_status = ENTITY_STATUS.PAUSED
6262
line_item.categories = 'IAB1'
6363
line_item.save()
6464

@@ -110,5 +110,5 @@
110110
raise
111111

112112
# unpause the campaign
113-
campaign.paused = False
114-
campaign.save()
113+
campaign.entity_status = ENTITY_STATUS.ACTIVE
114+
campaign.save()

tests/fixtures/promoted_tweets_all.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"line_item_id": "2b7xw",
1010
"id": "6thl4",
11-
"paused": false,
11+
"entity_status": "ACTIVE",
1212
"created_at": "2015-04-11T20:50:25Z",
1313
"updated_at": "2015-04-11T20:50:25Z",
1414
"approval_status": "ACCEPTED",
@@ -18,7 +18,7 @@
1818
{
1919
"line_item_id": "2b7xw",
2020
"id": "6thl3",
21-
"paused": false,
21+
"entity_status": "ACTIVE",
2222
"created_at": "2015-04-11T20:50:25Z",
2323
"updated_at": "2015-04-11T20:50:25Z",
2424
"approval_status": "ACCEPTED",
@@ -28,7 +28,7 @@
2828
{
2929
"line_item_id": "2b7xw",
3030
"id": "6thl5",
31-
"paused": false,
31+
"entity_status": "ACTIVE",
3232
"created_at": "2015-04-11T20:50:25Z",
3333
"updated_at": "2015-04-11T20:50:25Z",
3434
"approval_status": "ACCEPTED",
@@ -38,7 +38,7 @@
3838
{
3939
"line_item_id": "2b7xw",
4040
"id": "6thl6",
41-
"paused": false,
41+
"entity_status": "ACTIVE",
4242
"created_at": "2015-04-11T20:50:25Z",
4343
"updated_at": "2015-04-11T20:50:25Z",
4444
"approval_status": "ACCEPTED",
@@ -48,7 +48,7 @@
4848
{
4949
"line_item_id": "2b7xw",
5050
"id": "6thl7",
51-
"paused": false,
51+
"entity_status": "ACTIVE",
5252
"created_at": "2015-04-11T20:50:25Z",
5353
"updated_at": "2015-04-11T20:50:25Z",
5454
"approval_status": "ACCEPTED",
@@ -58,7 +58,7 @@
5858
{
5959
"line_item_id": "2b7xw",
6060
"id": "6thl8",
61-
"paused": false,
61+
"entity_status": "ACTIVE",
6262
"created_at": "2015-04-11T20:50:25Z",
6363
"updated_at": "2015-04-11T20:50:25Z",
6464
"approval_status": "ACCEPTED",
@@ -68,7 +68,7 @@
6868
{
6969
"line_item_id": "2b7xw",
7070
"id": "6thlb",
71-
"paused": false,
71+
"entity_status": "ACTIVE",
7272
"created_at": "2015-04-11T20:50:25Z",
7373
"updated_at": "2015-04-11T20:50:25Z",
7474
"approval_status": "ACCEPTED",
@@ -78,7 +78,7 @@
7878
{
7979
"line_item_id": "2b7xw",
8080
"id": "6thle",
81-
"paused": false,
81+
"entity_status": "ACTIVE",
8282
"created_at": "2015-04-11T20:50:25Z",
8383
"updated_at": "2015-04-11T20:50:25Z",
8484
"approval_status": "ACCEPTED",
@@ -88,7 +88,7 @@
8888
{
8989
"line_item_id": "2b7xw",
9090
"id": "6thlf",
91-
"paused": false,
91+
"entity_status": "ACTIVE",
9292
"created_at": "2015-04-11T20:50:25Z",
9393
"updated_at": "2015-04-11T20:50:25Z",
9494
"approval_status": "ACCEPTED",
@@ -98,7 +98,7 @@
9898
{
9999
"line_item_id": "2b7xw",
100100
"id": "6thlg",
101-
"paused": false,
101+
"entity_status": "ACTIVE",
102102
"created_at": "2015-04-11T20:50:25Z",
103103
"updated_at": "2015-04-11T20:50:25Z",
104104
"approval_status": "ACCEPTED",
@@ -108,7 +108,7 @@
108108
{
109109
"line_item_id": "2b7xw",
110110
"id": "6thlh",
111-
"paused": false,
111+
"entity_status": "ACTIVE",
112112
"created_at": "2015-04-11T20:50:25Z",
113113
"updated_at": "2015-04-11T20:50:25Z",
114114
"approval_status": "ACCEPTED",
@@ -118,7 +118,7 @@
118118
{
119119
"line_item_id": "2b7xw",
120120
"id": "6thln",
121-
"paused": false,
121+
"entity_status": "ACTIVE",
122122
"created_at": "2015-04-11T20:50:25Z",
123123
"updated_at": "2015-04-11T20:50:25Z",
124124
"approval_status": "ACCEPTED",
@@ -128,7 +128,7 @@
128128
{
129129
"line_item_id": "2b7xw",
130130
"id": "6thlo",
131-
"paused": false,
131+
"entity_status": "ACTIVE",
132132
"created_at": "2015-04-11T20:50:25Z",
133133
"updated_at": "2015-04-11T20:50:25Z",
134134
"approval_status": "ACCEPTED",
@@ -138,7 +138,7 @@
138138
{
139139
"line_item_id": "2b7xw",
140140
"id": "6thlp",
141-
"paused": false,
141+
"entity_status": "ACTIVE",
142142
"created_at": "2015-04-11T20:50:25Z",
143143
"updated_at": "2015-04-11T20:50:25Z",
144144
"approval_status": "ACCEPTED",
@@ -148,7 +148,7 @@
148148
{
149149
"line_item_id": "2b7xw",
150150
"id": "6thlq",
151-
"paused": false,
151+
"entity_status": "ACTIVE",
152152
"created_at": "2015-04-11T20:50:25Z",
153153
"updated_at": "2015-04-11T20:50:25Z",
154154
"approval_status": "ACCEPTED",
@@ -158,7 +158,7 @@
158158
{
159159
"line_item_id": "2b7xw",
160160
"id": "6tt7l",
161-
"paused": false,
161+
"entity_status": "ACTIVE",
162162
"created_at": "2015-04-12T23:47:44Z",
163163
"updated_at": "2015-04-12T23:47:44Z",
164164
"approval_status": "ACCEPTED",
@@ -168,7 +168,7 @@
168168
{
169169
"line_item_id": "2b7xw",
170170
"id": "6tt7m",
171-
"paused": false,
171+
"entity_status": "ACTIVE",
172172
"created_at": "2015-04-12T23:47:44Z",
173173
"updated_at": "2015-04-12T23:47:44Z",
174174
"approval_status": "ACCEPTED",
@@ -178,7 +178,7 @@
178178
{
179179
"line_item_id": "2b7xw",
180180
"id": "6ugv1",
181-
"paused": false,
181+
"entity_status": "ACTIVE",
182182
"created_at": "2015-04-13T22:19:08Z",
183183
"updated_at": "2015-04-13T22:19:08Z",
184184
"approval_status": "ACCEPTED",
@@ -188,7 +188,7 @@
188188
{
189189
"line_item_id": "2b7xw",
190190
"id": "6w7b5",
191-
"paused": false,
191+
"entity_status": "ACTIVE",
192192
"created_at": "2015-04-16T17:01:56Z",
193193
"updated_at": "2015-04-16T17:01:56Z",
194194
"approval_status": "ACCEPTED",
@@ -198,7 +198,7 @@
198198
{
199199
"line_item_id": "2dw80",
200200
"id": "70dbj",
201-
"paused": false,
201+
"entity_status": "ACTIVE",
202202
"created_at": "2015-04-23T20:27:27Z",
203203
"updated_at": "2015-04-23T20:27:27Z",
204204
"approval_status": "ACCEPTED",

tests/fixtures/promoted_tweets_load.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"data": {
44
"line_item_id": "2b7xw",
55
"id": "6thl4",
6-
"paused": false,
6+
"entity_status": "ACTIVE",
77
"created_at": "2015-04-11T20:50:25Z",
88
"updated_at": "2015-04-11T20:50:25Z",
99
"approval_status": "ACCEPTED",

0 commit comments

Comments
 (0)