Skip to content

Commit d7a99e3

Browse files
authored
v6 updates (#210)
* Update API_VERSION * v6: Expose concurrent job limit - Analytics module is now Class object * Add support for PROMOTED_ACCOUNT stats entity * mark scoped_timeline as deprecated * as_user_id is now required parameter * Add additional optimization enum * remove tailored_audience_type request parameter * rename lookalike_expansion to audience_expansion * Media identifier consistency * remove meaningless tests * bump version * Fix comments in Analytics class * Add helper method * Add new Tweets endpoint * Update comments
1 parent bd2226d commit d7a99e3

37 files changed

Lines changed: 255 additions & 370 deletions

examples/draft_tweet.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# load up the account instance, campaign and line item
2121
account = client.accounts(ADS_ACCOUNT)
2222

23+
# get user_id for as_user_id parameter
24+
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_twitter_handle_name').id
25+
2326
# fetch draft tweets from a given account
2427
tweets = TwitterAds::Creative::DraftTweet.all(account)
2528
tweets.each { |tweet|
@@ -30,6 +33,7 @@
3033
# create a new draft tweet
3134
draft_tweet = TwitterAds::Creative::DraftTweet.new(account)
3235
draft_tweet.text = 'draft tweet - new'
36+
draft_tweet.as_user_id = user_id
3337
draft_tweet.save
3438
p draft_tweet.id_str
3539
p draft_tweet.text
@@ -52,7 +56,7 @@
5256
# draft_tweet.preview(draft_tweet_id: '1142048306194862080')
5357

5458
# create a nullcasted tweet using draft tweet metadata
55-
tweet = TwitterAds::Tweet.create(account, text: draft_tweet.text)
59+
tweet = TwitterAds::Tweet.create(account, text: draft_tweet.text, as_user_id: user_id)
5660
p tweet
5761

5862
# delete draft tweet

examples/promoted_tweet.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
campaign = account.campaigns.first
2323
line_item = account.line_items(nil, campaign_ids: campaign.id).first
2424

25+
# get user_id for as_user_id parameter
26+
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_twitter_handle_name').id
27+
2528
# create request for a simple nullcasted tweet
26-
tweet1 = TwitterAds::Tweet.create(account, text: 'There can be only one...')
29+
tweet1 = TwitterAds::Tweet.create(account, text: 'There can be only one...', as_user_id: user_id)
2730

2831
# promote the tweet using our line item
2932
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
@@ -36,7 +39,8 @@
3639
tweet2 = TwitterAds::Tweet.create(
3740
account,
3841
text: 'Fine. There can be two.',
39-
card_uri: website_card.card_uri
42+
card_uri: website_card.card_uri,
43+
as_user_id: user_id
4044
)
4145

4246
# promote the tweet using our line item

lib/twitter-ads.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
require 'twitter-ads/http/request'
2828
require 'twitter-ads/http/response'
2929

30+
require 'twitter-ads/restapi.rb'
31+
3032
require 'twitter-ads/audiences/tailored_audience'
3133

3234
require 'twitter-ads/campaign/app_list'
@@ -69,6 +71,7 @@
6971
require 'twitter-ads/creative/website_card'
7072
require 'twitter-ads/creative/poll_cards'
7173
require 'twitter-ads/creative/tweet_previews'
74+
require 'twitter-ads/creative/tweets'
7275

7376
require 'twitter-ads/targeting/reach_estimate'
7477

lib/twitter-ads/account.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ class Account
1717
property :updated_at, type: :time, read_only: true
1818
property :deleted, type: :bool, read_only: true
1919

20-
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
21-
'accounts' # @api private
22-
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
23-
'accounts/%{id}' # @api private
24-
FEATURES = "/#{TwitterAds::API_VERSION}/" \
25-
'accounts/%{id}/features' # @api private
26-
SCOPED_TIMELINE = "/#{TwitterAds::API_VERSION}/" \
27-
'accounts/%{id}/scoped_timeline' # @api private
20+
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
21+
'accounts' # @api private
22+
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
23+
'accounts/%{id}' # @api private
24+
FEATURES = "/#{TwitterAds::API_VERSION}/" \
25+
'accounts/%{id}/features' # @api private
26+
SCOPED_TIMELINE = '/5/accounts/%{id}/scoped_timeline' # @api private
2827
AUTHENTICATED_USER_ACCESS = "/#{TwitterAds::API_VERSION}/" \
2928
'accounts/%{id}/authenticated_user_access' # @api private
3029

@@ -257,6 +256,8 @@ def tailored_audiences(id = nil, opts = {})
257256
#
258257
# @since 0.2.3
259258
def scoped_timeline(id, opts = {})
259+
TwitterAds::Utils.deprecated(
260+
'Scoped Timeline')
260261
params = { user_id: id }.merge!(opts)
261262
resource = SCOPED_TIMELINE % { id: @id }
262263
request = Request.new(client, :get, resource, params: params)

lib/twitter-ads/campaign/campaign.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# Copyright (C) 2019 Twitter, Inc.
33

44
module TwitterAds
5-
class Campaign
5+
class Campaign < Analytics
66

77
include TwitterAds::DSL
88
include TwitterAds::Resource
99
include TwitterAds::Persistence
10-
include TwitterAds::Analytics
1110
include TwitterAds::Batch
1211

1312
attr_reader :account

lib/twitter-ads/campaign/funding_instrument.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
# Copyright (C) 2019 Twitter, Inc.
33

44
module TwitterAds
5-
class FundingInstrument
5+
class FundingInstrument < Analytics
66

77
include TwitterAds::DSL
88
include TwitterAds::Resource
9-
include TwitterAds::Analytics
109

1110
attr_reader :account
1211

lib/twitter-ads/campaign/line_item.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# Copyright (C) 2019 Twitter, Inc.
33

44
module TwitterAds
5-
class LineItem
5+
class LineItem < Analytics
66

77
include TwitterAds::DSL
88
include TwitterAds::Resource
99
include TwitterAds::Persistence
10-
include TwitterAds::Analytics
1110
include TwitterAds::Batch
1211

1312
attr_reader :account
@@ -40,7 +39,7 @@ class LineItem
4039
property :advertiser_user_id
4140
property :bid_type
4241
property :tracking_tags
43-
property :lookalike_expansion
42+
property :audience_expansion
4443

4544
# sdk only
4645
property :to_delete, type: :bool

lib/twitter-ads/campaign/organic_tweet.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
# Author Bob, Nugit
44

55
module TwitterAds
6-
class OrganicTweet
7-
8-
include TwitterAds::Analytics
6+
class OrganicTweet < Analytics
97

108
end
119
end

lib/twitter-ads/campaign/targeting_criteria.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class TargetingCriteria
2222
property :targeting_type
2323
property :targeting_value
2424
property :tailored_audience_expansion, type: :bool
25-
property :tailored_audience_type
2625
property :location_type
2726

2827
# sdk only

lib/twitter-ads/campaign/tweet.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
# Copyright (C) 2019 Twitter, Inc.
33

44
module TwitterAds
5-
module Tweet
6-
7-
# cannot instaniate Tweet, only including class methods for stats
8-
extend TwitterAds::Analytics::ClassMethods
5+
class Tweet < Analytics
96

107
RESOURCE_CREATE = "/#{TwitterAds::API_VERSION}/" \
118
'accounts/%{account_id}/tweet' # @api private
@@ -17,10 +14,9 @@ class << self
1714
# @param opts [Hash] A hash of options.
1815
#
1916
# @option opts [String] :text The main Tweet body.
20-
# @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
17+
# @option opts [Array] :media_keys A list of media keys (up to 4) to associate with the Tweet.
2118
# @option opts [Integer] :as_user_id The user ID whom you are posting the Tweet on behalf of.
2219
# @option opts [Boolean] :trim_user Excludes the user object from the hydrated Tweet response.
23-
# @option opts [String] :video_id The Video UUID to be associated with thie Tweet.
2420
# @option opts [String] :video_title An optional title to be included.
2521
# @option opts [String] :video_description An optional description to be included.
2622
# @option opts [String] :video_cta An optional CTA value for the associated video.

0 commit comments

Comments
 (0)