Skip to content

Commit 2ec29ac

Browse files
authored
Minor bug fixes (#197)
* Fix promoted_tweet example * Fix TypeError > no implicit conversion of nil into Hash (TypeError) when with_deleted is false
1 parent 5751811 commit 2ec29ac

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

examples/promoted_tweet.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,27 @@
2020
# load up the account instance, campaign and line item
2121
account = client.accounts(ADS_ACCOUNT)
2222
campaign = account.campaigns.first
23-
line_item = account.line_items(nil, params: { campaign_id: campaign.id }).first
23+
line_item = account.line_items(nil, campaign_ids: campaign.id).first
2424

2525
# create request for a simple nullcasted tweet
26-
tweet1 = TwitterAds::Tweet.create(account, 'There can be only one...')
26+
tweet1 = TwitterAds::Tweet.create(account, text: 'There can be only one...')
2727

2828
# promote the tweet using our line item
2929
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
3030
promoted_tweet.line_item_id = line_item.id
31-
promoted_tweet.tweet_id = tweet1.body[:data][:id]
31+
promoted_tweet.tweet_id = tweet1[:id_str]
3232
promoted_tweet.save
3333

3434
# create request for a nullcasted tweet with a website card
3535
website_card = TwitterAds::Creative::WebsiteCard.all(account).first
36-
tweet2 = TwitterAds::Tweet.create(account, "Fine. There can be two. #{website_card.preview_url}")
36+
tweet2 = TwitterAds::Tweet.create(
37+
account,
38+
text: 'Fine. There can be two.',
39+
card_uri: website_card.card_uri
40+
)
3741

3842
# promote the tweet using our line item
3943
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
4044
promoted_tweet.line_item_id = line_item.id
41-
promoted_tweet.tweet_id = tweet2.body[:data][:id]
45+
promoted_tweet.tweet_id = tweet2[:id_str]
4246
promoted_tweet.save

lib/twitter-ads/creative/cards_fetch.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,19 @@ def load(account, card_uris = nil, card_id = nil, with_deleted = nil, opts = {})
8787
'Please supply one or the other, but not both.')
8888
end
8989

90+
params = {}.merge!(opts)
91+
9092
if with_deleted && TwitterAds::Utils.to_bool(with_deleted)
91-
params = { with_deleted: true }.merge!(opts)
93+
params = { with_deleted: true }.merge!(params)
9294
end
9395

9496
if card_uris
95-
params = { card_uris: Array(card_uris).join(',') }.merge!(opts).merge!(params)
97+
params = { card_uris: Array(card_uris).join(',') }.merge!(params)
9698
resource = FETCH_URI % { account_id: account.id }
9799
request = Request.new(account.client, :get, resource, params: params)
98100
return Cursor.new(self.class, request, init_with: [account])
99101
else
100-
params = { card_id: card_id }.merge!(opts).merge!(params)
102+
params = { card_id: card_id }.merge!(params)
101103
resource = FETCH_ID % { account_id: account.id, id: card_id }
102104
response = Request.new(account.client, :get, resource, params: params).perform
103105
return from_response(response.body[:data])

0 commit comments

Comments
 (0)