Skip to content

Commit 79736cd

Browse files
authored
Ads API v7 (#224)
* bump version to 7 * changed serving_status to entity_status for media creatives * added granular tap placements * removed deprecated behavior targeting * added advertiser business categories endpoint * added missing content categories endpoint * added audience summary and tests * removed scoped timeline endpoint
1 parent 5f2960e commit 79736cd

16 files changed

Lines changed: 192 additions & 244 deletions

File tree

examples/audience_summary.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
# Copyright (C) 2019 Twitter, Inc.
3+
require 'twitter-ads'
4+
5+
CONSUMER_KEY = 'your consumer key'
6+
CONSUMER_SECRET = 'your consumer secret'
7+
ACCESS_TOKEN = 'user access token'
8+
ACCESS_TOKEN_SECRET = 'user access token secret'
9+
ADS_ACCOUNT = 'ads account id'
10+
11+
# initialize the twitter ads api client
12+
client = TwitterAds::Client.new(
13+
CONSUMER_KEY,
14+
CONSUMER_SECRET,
15+
ACCESS_TOKEN,
16+
ACCESS_TOKEN_SECRET
17+
)
18+
19+
# load up the account instance
20+
account = client.accounts(ADS_ACCOUNT)
21+
22+
# targeting criteria params
23+
params = {
24+
targeting_criteria: [
25+
{
26+
targeting_type: 'LOCATION',
27+
targeting_value: '96683cc9126741d1'
28+
},
29+
{
30+
targeting_type: 'BROAD_KEYWORD',
31+
targeting_value: 'cats'
32+
},
33+
{
34+
targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER',
35+
targeting_value: '14230524'
36+
},
37+
{
38+
targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER',
39+
targeting_value: '90420314'
40+
}
41+
]
42+
}
43+
44+
audience_summary = TwitterAds::AudienceSummary.fetch(account, params)
45+
puts audience_summary

lib/twitter-ads.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
require 'twitter-ads/campaign/tweet'
4141
require 'twitter-ads/campaign/organic_tweet'
4242
require 'twitter-ads/campaign/iab_category'
43+
require 'twitter-ads/campaign/advertiser_business_categories'
44+
require 'twitter-ads/campaign/content_categories'
4345

4446
require 'twitter-ads/targeting_criteria/tv_market'
4547
require 'twitter-ads/targeting_criteria/tv_show'
@@ -52,8 +54,6 @@
5254
require 'twitter-ads/targeting_criteria/location'
5355
require 'twitter-ads/targeting_criteria/interest'
5456
require 'twitter-ads/targeting_criteria/language'
55-
require 'twitter-ads/targeting_criteria/behavior'
56-
require 'twitter-ads/targeting_criteria/behavior_taxonomy'
5757
require 'twitter-ads/targeting_criteria/app_store_category'
5858

5959
require 'twitter-ads/creative/account_media'
@@ -74,7 +74,7 @@
7474
require 'twitter-ads/creative/tweet_previews'
7575
require 'twitter-ads/creative/tweets'
7676

77-
require 'twitter-ads/targeting/reach_estimate'
77+
require 'twitter-ads/targeting/audience_summary'
7878

7979
require 'twitter-ads/measurement/web_event_tag'
8080
require 'twitter-ads/measurement/app_event_tag'

lib/twitter-ads/account.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Account
2323
'accounts/%{id}' # @api private
2424
FEATURES = "/#{TwitterAds::API_VERSION}/" \
2525
'accounts/%{id}/features' # @api private
26-
SCOPED_TIMELINE = '/5/accounts/%{id}/scoped_timeline' # @api private
2726
AUTHENTICATED_USER_ACCESS = "/#{TwitterAds::API_VERSION}/" \
2827
'accounts/%{id}/authenticated_user_access' # @api private
2928

@@ -247,24 +246,6 @@ def tailored_audiences(id = nil, opts = {})
247246
load_resource(TailoredAudience, id, opts)
248247
end
249248

250-
# Returns the most recent promotable Tweets created by one or more specified Twitter users.
251-
#
252-
# @param ids [Array] An Array of Twitter user IDs.
253-
# @param opts [Hash] A Hash of extended options.
254-
#
255-
# @return [Array] An Array of Tweet objects.
256-
#
257-
# @since 0.2.3
258-
def scoped_timeline(id, opts = {})
259-
TwitterAds::Utils.deprecated(
260-
'Scoped Timeline')
261-
params = { user_id: id }.merge!(opts)
262-
resource = SCOPED_TIMELINE % { id: @id }
263-
request = Request.new(client, :get, resource, params: params)
264-
response = request.perform
265-
response.body[:data]
266-
end
267-
268249
def authenticated_user_access
269250
params = {}
270251
resource = AUTHENTICATED_USER_ACCESS % { id: @id }

lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb renamed to lib/twitter-ads/campaign/advertiser_business_categories.rb

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

44
module TwitterAds
5-
class BehaviorTaxonomy
5+
class AdvertiserBusinessCategories
66

77
include TwitterAds::DSL
88
include TwitterAds::Resource
99

10+
attr_reader :account
11+
1012
property :id, read_only: true
1113
property :name, read_only: true
12-
property :parent_id, read_only: true
13-
property :created_at, read_only: true
14-
property :updated_at, read_only: true
14+
property :iab_categories, read_only: true
1515

16-
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
17-
'targeting_criteria/behavior_taxonomies' # @api private
16+
# @api private
17+
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/advertiser_business_categories"
1818

1919
def initialize(account)
2020
@account = account
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
# Copyright (C) 2019 Twitter, Inc.
3+
4+
module TwitterAds
5+
class ContentCategories
6+
7+
include TwitterAds::DSL
8+
include TwitterAds::Resource
9+
10+
attr_reader :account
11+
12+
property :id, read_only: true
13+
property :name, read_only: true
14+
property :iab_categories, read_only: true
15+
16+
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/content_categories" # @api private
17+
18+
def initialize(account)
19+
@account = account
20+
self
21+
end
22+
end
23+
end

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 = '6'
6+
API_VERSION = '7'
77

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

lib/twitter-ads/creative/media_creative.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MediaCreative < Analytics
1616
property :created_at, type: :time, read_only: true
1717
property :deleted, type: :bool, read_only: true
1818
property :id, read_only: true
19-
property :serving_status, read_only: true
19+
property :entity_status, read_only: true
2020
property :updated_at, type: :time, read_only: true
2121

2222
property :account_media_id

lib/twitter-ads/enum.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ module Product
2424
end
2525

2626
module Placement
27-
ALL_ON_TWITTER = 'ALL_ON_TWITTER'
28-
TWITTER_SEARCH = 'TWITTER_SEARCH'
29-
TWITTER_TIMELINE = 'TWITTER_TIMELINE'
30-
PUBLISHER_NETWORK = 'PUBLISHER_NETWORK'
27+
ALL_ON_TWITTER = 'ALL_ON_TWITTER'
28+
TWITTER_SEARCH = 'TWITTER_SEARCH'
29+
TWITTER_TIMELINE = 'TWITTER_TIMELINE'
30+
PUBLISHER_NETWORK = 'PUBLISHER_NETWORK'
31+
TAP_FULL = 'TAP_FULL'
32+
TAP_FULL_LANDSCAPE = 'TAP_FULL_LANDSCAPE'
33+
TAP_BANNER = 'TAP_BANNER'
34+
TAP_NATIVE = 'TAP_NATIVE'
35+
TAP_MRECT = 'TAP_MRECT'
3136
end
3237

3338
module Placement
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
# Copyright (C) 2019 Twitter, Inc.
3+
4+
module TwitterAds
5+
module AudienceSummary
6+
7+
include TwitterAds::DSL
8+
include TwitterAds::Resource
9+
10+
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
11+
'accounts/%{account_id}/audience_summary'
12+
13+
property :audience_size, read_only: true
14+
15+
class << self
16+
17+
# Get an audience summary for the specified targeting criteria.
18+
#
19+
# @example
20+
# TwitterAds::AudienceSummary.fetch(
21+
# account,
22+
# params: {targeting_criteria:[{targeting_type:'LOCATION',
23+
# targeting_value:'96683cc9126741d1'}]}
24+
# )
25+
#
26+
# @param params [Hash] A hash of input targeting criteria values
27+
#
28+
# @return [Hash] A hash containing the min and max audience size.
29+
#
30+
# @since 7.0.0
31+
# @see https://developer.twitter.com/en/docs/ads/campaign-management/api-reference/audience-summary
32+
def fetch(account, params)
33+
resource = RESOURCE % { account_id: account.id }
34+
headers = { 'Content-Type' => 'application/json' }
35+
36+
response = TwitterAds::Request.new(account.client,
37+
:post,
38+
resource,
39+
headers: headers,
40+
body: params.to_json).perform
41+
response.body[:data]
42+
end
43+
44+
end
45+
46+
end
47+
end

lib/twitter-ads/targeting/reach_estimate.rb

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

0 commit comments

Comments
 (0)