Skip to content

Commit

Permalink
Ads API v11 (#265)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tushdante and osowskit authored May 27, 2022
1 parent 6388310 commit 0b6759a
Show file tree
Hide file tree
Showing 20 changed files with 990 additions and 233 deletions.
15 changes: 13 additions & 2 deletions examples/cards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@
]

vwc = TwitterAds::Creative::Cards.new(account)
video_website_card = vwc.create(account, name, components)
vwc.name = name
vwc.components = components
vwc.save
vwc.name = 'vwc - ruby sdk'
vwc.save
puts vwc.name # vwc - ruby sdk

# fetch all
# card = TwitterAds::Creative::Cards.all(account, card_ids: '1508693734346485761').first

# fetch by card-id
# card = TwitterAds::Creative::Cards.load(account, '1508693734346485761')

# get user_id for as_user_id parameter
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_screen_name').id
Expand All @@ -46,5 +57,5 @@
tweet = TwitterAds::Creative::DraftTweet.new(account)
tweet.text = 'Created from SDK'
tweet.as_user_id = user_id
tweet.card_uri = video_website_card.card_uri
tweet.card_uri = vwc.card_uri
tweet.save
10 changes: 5 additions & 5 deletions examples/draft_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# fetch draft tweets from a given account
tweets = TwitterAds::Creative::DraftTweet.all(account)
tweets.each { |tweet|
p tweet.id_str
p tweet.id
p tweet.text
}

Expand All @@ -35,19 +35,19 @@
draft_tweet.text = 'draft tweet - new'
draft_tweet.as_user_id = user_id
draft_tweet.save
p draft_tweet.id_str
p draft_tweet.id
p draft_tweet.text

# fetch single draft tweet metadata
tweet_id = draft_tweet.id_str
tweet_id = draft_tweet.id
draft_tweet = TwitterAds::Creative::DraftTweet.load(account, tweet_id)
p draft_tweet.id_str
p draft_tweet.id
p draft_tweet.text

# update (PUT) metadata
draft_tweet.text = 'draft tweet - update'
draft_tweet = draft_tweet.save
p draft_tweet.id_str
p draft_tweet.id
p draft_tweet.text

# preview draft tweet of current instance (send notification)
Expand Down
4 changes: 2 additions & 2 deletions examples/promoted_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# promote the tweet using our line item
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet1[:id_str]
promoted_tweet.tweet_id = tweet1[:id]
promoted_tweet.save

# create request for a nullcasted tweet with a website card
Expand All @@ -46,5 +46,5 @@
# promote the tweet using our line item
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet2[:id_str]
promoted_tweet.tweet_id = tweet2[:id]
promoted_tweet.save
4 changes: 0 additions & 4 deletions lib/twitter-ads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,14 @@
require 'twitter-ads/creative/account_media'
require 'twitter-ads/creative/cards_fetch'
require 'twitter-ads/creative/cards'
require 'twitter-ads/creative/image_app_download_card'
require 'twitter-ads/creative/image_conversation_card'
require 'twitter-ads/creative/media_creative'
require 'twitter-ads/creative/media_library'
require 'twitter-ads/creative/promoted_account'
require 'twitter-ads/creative/promoted_tweet'
require 'twitter-ads/creative/scheduled_tweet'
require 'twitter-ads/creative/draft_tweet'
require 'twitter-ads/creative/video_app_download_card'
require 'twitter-ads/creative/video_conversation_card'
require 'twitter-ads/creative/video_website_card'
require 'twitter-ads/creative/website_card'
require 'twitter-ads/creative/poll_cards'
require 'twitter-ads/creative/tweet_previews'
require 'twitter-ads/creative/tweets'
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/campaign/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ class Campaign < Analytics

property :name
property :funding_instrument_id
property :end_time, type: :time
property :start_time, type: :time
property :entity_status
property :effective_status
property :currency
property :standard_delivery
property :daily_budget_amount_local_micro
property :total_budget_amount_local_micro
property :budget_optimization

# sdk only
property :to_delete, type: :bool
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/campaign/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class LineItem < Analytics
property :primary_web_event_tag
property :product_type
property :start_time, type: :time
property :standard_delivery, type: :bool
property :total_budget_amount_local_micro

# beta (not yet generally available)
property :advertiser_user_id

# sdk only
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter-ads/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module TwitterAds

API_VERSION = '10'
API_VERSION = '11'

# The Ads API Client class which functions as a
# container for basic API consumer information.
Expand Down
53 changes: 31 additions & 22 deletions lib/twitter-ads/creative/cards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,53 @@ class Cards

attr_reader :account

property :id, read_only: true
property :card_type, read_only: true
property :card_uri, read_only: true
property :created_at, type: :time, read_only: true
property :deleted, type: :bool, read_only: true
property :updated_at, type: :time, read_only: true
# these are writable, but not in the sense that they can be set on an object and then saved
property :name, read_only: true
property :components, read_only: true
property :name
property :components

RESOURCE = "/#{TwitterAds::API_VERSION}/" +
'accounts/%{account_id}/cards' # @api private
'accounts/%{account_id}/cards/%{id}' # @api private
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" +
'accounts/%{account_id}/cards' # @api private

def load(*)
raise ArgumentError.new(
"'Cards' object has no attribute 'load'")
end

def reload(*)
raise ArgumentError.new(
"'Cards' object has no attribute 'reload'")
end

def create(account, name, components)
resource = RESOURCE % { account_id: account.id }
params = { 'name': name, 'components': components }
def save
headers = { 'Content-Type' => 'application/json' }
response = Request.new(account.client,
:post,
resource,
headers: headers,
body: params.to_json).perform
params = { 'name': name, 'components': components }
if @id
resource = RESOURCE % {
account_id: account.id,
id: id
}
request = Request.new(account.client,
:put,
resource,
headers: headers,
body: params.to_json)
else
resource = RESOURCE_COLLECTION % {
account_id: account.id
}
request = Request.new(account.client,
:post,
resource,
headers: headers,
body: params.to_json)
end

response = request.perform
from_response(response.body[:data])
end

def initialize(account)
@account = account
self
end

end

end
Expand Down
1 change: 0 additions & 1 deletion lib/twitter-ads/creative/draft_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class DraftTweet

# read-only
property :id, read_only: true
property :id_str, read_only: true
property :created_at, type: :time, read_only: true
property :updated_at, type: :time, read_only: true
property :user_id, read_only: true
Expand Down
47 changes: 0 additions & 47 deletions lib/twitter-ads/creative/image_app_download_card.rb

This file was deleted.

48 changes: 0 additions & 48 deletions lib/twitter-ads/creative/video_app_download_card.rb

This file was deleted.

50 changes: 0 additions & 50 deletions lib/twitter-ads/creative/video_website_card.rb

This file was deleted.

Loading

0 comments on commit 0b6759a

Please sign in to comment.