Skip to content

Commit 0b6759a

Browse files
tushdanteTom Osowski
andauthored
Ads API v11 (#265)
* Added support for unified cards and tests * updated cards example * update API_VERSION to 11 * Removed deprecated website/app cards * Line item budget changes * code quality changes * removed start/end times from campaigns * Remove string version of IDs Co-authored-by: Tom Osowski <tosowski@twitter.com>
1 parent 6388310 commit 0b6759a

20 files changed

+990
-233
lines changed

examples/cards.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@
3737
]
3838

3939
vwc = TwitterAds::Creative::Cards.new(account)
40-
video_website_card = vwc.create(account, name, components)
40+
vwc.name = name
41+
vwc.components = components
42+
vwc.save
43+
vwc.name = 'vwc - ruby sdk'
44+
vwc.save
45+
puts vwc.name # vwc - ruby sdk
46+
47+
# fetch all
48+
# card = TwitterAds::Creative::Cards.all(account, card_ids: '1508693734346485761').first
49+
50+
# fetch by card-id
51+
# card = TwitterAds::Creative::Cards.load(account, '1508693734346485761')
4152

4253
# get user_id for as_user_id parameter
4354
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_screen_name').id
@@ -46,5 +57,5 @@
4657
tweet = TwitterAds::Creative::DraftTweet.new(account)
4758
tweet.text = 'Created from SDK'
4859
tweet.as_user_id = user_id
49-
tweet.card_uri = video_website_card.card_uri
60+
tweet.card_uri = vwc.card_uri
5061
tweet.save

examples/draft_tweet.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# fetch draft tweets from a given account
2727
tweets = TwitterAds::Creative::DraftTweet.all(account)
2828
tweets.each { |tweet|
29-
p tweet.id_str
29+
p tweet.id
3030
p tweet.text
3131
}
3232

@@ -35,19 +35,19 @@
3535
draft_tweet.text = 'draft tweet - new'
3636
draft_tweet.as_user_id = user_id
3737
draft_tweet.save
38-
p draft_tweet.id_str
38+
p draft_tweet.id
3939
p draft_tweet.text
4040

4141
# fetch single draft tweet metadata
42-
tweet_id = draft_tweet.id_str
42+
tweet_id = draft_tweet.id
4343
draft_tweet = TwitterAds::Creative::DraftTweet.load(account, tweet_id)
44-
p draft_tweet.id_str
44+
p draft_tweet.id
4545
p draft_tweet.text
4646

4747
# update (PUT) metadata
4848
draft_tweet.text = 'draft tweet - update'
4949
draft_tweet = draft_tweet.save
50-
p draft_tweet.id_str
50+
p draft_tweet.id
5151
p draft_tweet.text
5252

5353
# preview draft tweet of current instance (send notification)

examples/promoted_tweet.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# promote the tweet using our line item
3232
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
3333
promoted_tweet.line_item_id = line_item.id
34-
promoted_tweet.tweet_id = tweet1[:id_str]
34+
promoted_tweet.tweet_id = tweet1[:id]
3535
promoted_tweet.save
3636

3737
# create request for a nullcasted tweet with a website card
@@ -46,5 +46,5 @@
4646
# promote the tweet using our line item
4747
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
4848
promoted_tweet.line_item_id = line_item.id
49-
promoted_tweet.tweet_id = tweet2[:id_str]
49+
promoted_tweet.tweet_id = tweet2[:id]
5050
promoted_tweet.save

lib/twitter-ads.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,14 @@
6060
require 'twitter-ads/creative/account_media'
6161
require 'twitter-ads/creative/cards_fetch'
6262
require 'twitter-ads/creative/cards'
63-
require 'twitter-ads/creative/image_app_download_card'
6463
require 'twitter-ads/creative/image_conversation_card'
6564
require 'twitter-ads/creative/media_creative'
6665
require 'twitter-ads/creative/media_library'
6766
require 'twitter-ads/creative/promoted_account'
6867
require 'twitter-ads/creative/promoted_tweet'
6968
require 'twitter-ads/creative/scheduled_tweet'
7069
require 'twitter-ads/creative/draft_tweet'
71-
require 'twitter-ads/creative/video_app_download_card'
7270
require 'twitter-ads/creative/video_conversation_card'
73-
require 'twitter-ads/creative/video_website_card'
74-
require 'twitter-ads/creative/website_card'
7571
require 'twitter-ads/creative/poll_cards'
7672
require 'twitter-ads/creative/tweet_previews'
7773
require 'twitter-ads/creative/tweets'

lib/twitter-ads/campaign/campaign.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class Campaign < Analytics
2020

2121
property :name
2222
property :funding_instrument_id
23-
property :end_time, type: :time
24-
property :start_time, type: :time
2523
property :entity_status
2624
property :effective_status
2725
property :currency
2826
property :standard_delivery
2927
property :daily_budget_amount_local_micro
3028
property :total_budget_amount_local_micro
29+
property :budget_optimization
3130

3231
# sdk only
3332
property :to_delete, type: :bool

lib/twitter-ads/campaign/line_item.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ class LineItem < Analytics
3434
property :primary_web_event_tag
3535
property :product_type
3636
property :start_time, type: :time
37+
property :standard_delivery, type: :bool
3738
property :total_budget_amount_local_micro
38-
39-
# beta (not yet generally available)
4039
property :advertiser_user_id
4140

4241
# sdk only

lib/twitter-ads/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module TwitterAds
55

6-
API_VERSION = '10'
6+
API_VERSION = '11'
77

88
# The Ads API Client class which functions as a
99
# container for basic API consumer information.

lib/twitter-ads/creative/cards.rb

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,53 @@ class Cards
1212

1313
attr_reader :account
1414

15+
property :id, read_only: true
16+
property :card_type, read_only: true
1517
property :card_uri, read_only: true
1618
property :created_at, type: :time, read_only: true
1719
property :deleted, type: :bool, read_only: true
1820
property :updated_at, type: :time, read_only: true
1921
# these are writable, but not in the sense that they can be set on an object and then saved
20-
property :name, read_only: true
21-
property :components, read_only: true
22+
property :name
23+
property :components
2224

2325
RESOURCE = "/#{TwitterAds::API_VERSION}/" +
24-
'accounts/%{account_id}/cards' # @api private
26+
'accounts/%{account_id}/cards/%{id}' # @api private
27+
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" +
28+
'accounts/%{account_id}/cards' # @api private
2529

26-
def load(*)
27-
raise ArgumentError.new(
28-
"'Cards' object has no attribute 'load'")
29-
end
30-
31-
def reload(*)
32-
raise ArgumentError.new(
33-
"'Cards' object has no attribute 'reload'")
34-
end
35-
36-
def create(account, name, components)
37-
resource = RESOURCE % { account_id: account.id }
38-
params = { 'name': name, 'components': components }
30+
def save
3931
headers = { 'Content-Type' => 'application/json' }
40-
response = Request.new(account.client,
41-
:post,
42-
resource,
43-
headers: headers,
44-
body: params.to_json).perform
32+
params = { 'name': name, 'components': components }
33+
if @id
34+
resource = RESOURCE % {
35+
account_id: account.id,
36+
id: id
37+
}
38+
request = Request.new(account.client,
39+
:put,
40+
resource,
41+
headers: headers,
42+
body: params.to_json)
43+
else
44+
resource = RESOURCE_COLLECTION % {
45+
account_id: account.id
46+
}
47+
request = Request.new(account.client,
48+
:post,
49+
resource,
50+
headers: headers,
51+
body: params.to_json)
52+
end
53+
54+
response = request.perform
4555
from_response(response.body[:data])
4656
end
4757

4858
def initialize(account)
4959
@account = account
5060
self
5161
end
52-
5362
end
5463

5564
end

lib/twitter-ads/creative/draft_tweet.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class DraftTweet
1414

1515
# read-only
1616
property :id, read_only: true
17-
property :id_str, read_only: true
1817
property :created_at, type: :time, read_only: true
1918
property :updated_at, type: :time, read_only: true
2019
property :user_id, read_only: true

lib/twitter-ads/creative/image_app_download_card.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)