Skip to content

Commit 13fba8b

Browse files
Ads API v9 (#246)
* updated version to v9 * renamed/removed line item props * moved props out of beta * updated enums * added support for cards endpoint * renamed tailored audiences to custom audiences * removed old tailored audiences endpoint * added new cards endpoint with examples * updated tailored audiences to custom audiences * updated tests * merge conflicts Co-authored-by: John Babich <jbabich@twitter.com>
1 parent cd1b07c commit 13fba8b

17 files changed

Lines changed: 302 additions & 156 deletions

examples/audience_permissions.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
# load up the account instance
2323
account = client.accounts(ADS_ACCOUNT)
2424

25-
tailored_audience_id = '36n4f'
25+
custom_audience_id = '36n4f'
2626

2727
# fetch all permissions
28-
permissions = TwitterAds::TailoredAudiencePermission.all(account, tailored_audience_id)
28+
permissions = TwitterAds::CustomAudiencePermission.all(account, custom_audience_id)
2929

3030
permissions.each { |data|
3131
p data.id
@@ -34,10 +34,10 @@
3434
}
3535

3636
# create instance
37-
permission = TwitterAds::TailoredAudiencePermission.new(account)
37+
permission = TwitterAds::CustomAudiencePermission.new(account)
3838

3939
# set required params
40-
permission.tailored_audience_id = tailored_audience_id
40+
permission.custom_audience_id = custom_audience_id
4141
permission.granted_account_id = '18ce54uvbwu'
4242
permission.permission_level = PermissionLevel::READ_ONLY
4343

examples/cards.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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, campaign and line item
20+
account = client.accounts(ADS_ACCOUNT)
21+
22+
# create the card
23+
name = 'video website card'
24+
components = [
25+
{
26+
type: 'MEDIA',
27+
media_key: '13_794652834998325248'
28+
},
29+
{
30+
type: 'DETAILS',
31+
title: 'Twitter',
32+
destination: {
33+
type: 'WEBSITE',
34+
url: 'http://twitter.com/'
35+
}
36+
}
37+
]
38+
39+
vwc = TwitterAds::Creative::Cards.new(account)
40+
video_website_card = vwc.create(account, name, components)
41+
42+
# get user_id for as_user_id parameter
43+
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_screen_name').id
44+
45+
# create a draft tweet using this new card
46+
tweet = TwitterAds::Creative::DraftTweet.new(account)
47+
tweet.text = 'Created from SDK'
48+
tweet.as_user_id = user_id
49+
tweet.card_uri = video_website_card.card_uri
50+
tweet.save
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
# load up the account instance
2323
account = client.accounts(ADS_ACCOUNT)
2424

25-
# create a new placeholder tailored audience
25+
# create a new placeholder custom audience
2626
audience =
27-
TwitterAds::TailoredAudience.create(account, 'Test TA')
27+
TwitterAds::CustomAudience.create(account, 'Test TA')
2828

2929
# sample user
3030
# all values musth be sha256 hashede except 'partner_user_id'
@@ -42,6 +42,6 @@
4242
}
4343
}]
4444

45-
# update the tailored audience
45+
# update the custom audience
4646
success_count, total_count = audience.users(user)
4747
print "Successfully added #{total_count} users" if success_count == total_count

lib/twitter-ads.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
require 'twitter-ads/restapi.rb'
3131

32-
require 'twitter-ads/audiences/tailored_audience'
32+
require 'twitter-ads/audiences/custom_audience'
3333

3434
require 'twitter-ads/campaign/app_list'
3535
require 'twitter-ads/campaign/campaign'
@@ -58,6 +58,7 @@
5858

5959
require 'twitter-ads/creative/account_media'
6060
require 'twitter-ads/creative/cards_fetch'
61+
require 'twitter-ads/creative/cards'
6162
require 'twitter-ads/creative/image_app_download_card'
6263
require 'twitter-ads/creative/image_conversation_card'
6364
require 'twitter-ads/creative/media_creative'

lib/twitter-ads/account.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,18 @@ def app_lists(id = nil, opts = {})
232232
load_resource(AppList, id, opts)
233233
end
234234

235-
# Returns a collection of tailored audiences available to the current account.
235+
# Returns a collection of custom audiences available to the current account.
236236
#
237-
# @param id [String] The TailoredAudience ID value.
237+
# @param id [String] The CustomAudience ID value.
238238
# @param opts [Hash] A Hash of extended options.
239239
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
240240
# @option opts [String] :sort_by The object param to sort the API response by.
241241
#
242242
# @since 0.3.0
243243
#
244244
# @return A Cursor or object instance.
245-
def tailored_audiences(id = nil, opts = {})
246-
load_resource(TailoredAudience, id, opts)
245+
def custom_audiences(id = nil, opts = {})
246+
load_resource(CustomAudience, id, opts)
247247
end
248248

249249
def authenticated_user_access

lib/twitter-ads/audiences/tailored_audience.rb renamed to lib/twitter-ads/audiences/custom_audience.rb

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

44
module TwitterAds
5-
class TailoredAudience
5+
class CustomAudience
66

77
include TwitterAds::DSL
88
include TwitterAds::Resource
@@ -19,19 +19,19 @@ class TailoredAudience
1919

2020
property :audience_size, read_only: true
2121
property :audience_type, read_only: true
22-
property :metadata, read_only: true
23-
property :owner_account_id, read_only: true
2422
property :partner_source, read_only: true
2523
property :reasons_not_targetable, read_only: true
2624
property :targetable, type: :bool, read_only: true
2725
property :targetable_types, read_only: true
26+
property :permission_level, read_only: true
27+
property :owner_account_id, read_only: true
2828

2929
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
30-
'accounts/%{account_id}/tailored_audiences' # @api private
30+
'accounts/%{account_id}/custom_audiences' # @api private
3131
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
32-
'accounts/%{account_id}/tailored_audiences/%{id}' # @api private
32+
'accounts/%{account_id}/custom_audiences/%{id}' # @api private
3333
RESOURCE_USERS = "/#{TwitterAds::API_VERSION}/" \
34-
'accounts/%{account_id}/tailored_audiences/' \
34+
'accounts/%{account_id}/custom_audiences/' \
3535
'%{id}/users' # @api private
3636

3737
LIST_TYPES = %w(
@@ -55,17 +55,17 @@ def initialize(account)
5555

5656
class << self
5757

58-
# Creates a new tailored audience.
58+
# Creates a new custom audience.
5959
#
6060
# @example
61-
# audience = TailoredAudience.create(account, 'my list')
61+
# audience = CustomAudience.create(account, 'my list')
6262
#
6363
# @param account [Account] The account object instance.
64-
# @param name [String] The tailored audience name.
64+
# @param name [String] The custom audience name.
6565
#
6666
# @since 4.0
6767
#
68-
# @return [TailoredAudience] The newly created tailored audience instance.
68+
# @return [CustomAudience] The newly created custom audience instance.
6969
def create(account, name)
7070
audience = new(account)
7171
params = { name: name }
@@ -76,7 +76,7 @@ def create(account, name)
7676

7777
end
7878

79-
# Deletes the current tailored audience instance.
79+
# Deletes the current custom audience instance.
8080
#
8181
# @example
8282
# audience.delete!
@@ -85,7 +85,7 @@ def create(account, name)
8585
#
8686
# @since 0.3.0
8787
#
88-
# @return [self] Returns the tailored audience instance refreshed from the API.
88+
# @return [self] Returns the custom audience instance refreshed from the API.
8989
def delete!
9090
resource = RESOURCE % { account_id: account.id, id: id }
9191
response = Request.new(account.client, :delete, resource).perform
@@ -95,11 +95,11 @@ def delete!
9595
# This is a private API and requires allowlisting from Twitter.
9696
#
9797
# This endpoint will allow partners to add, update and remove users from a given
98-
# tailored_audience_id.
98+
# custom_audience_id.
9999
# The endpoint will also accept multiple user identifier types per user as well.
100100
#
101101
# @example
102-
# tailored_audience.users(
102+
# custom_audience.users(
103103
# account,
104104
# [
105105
# {
@@ -194,7 +194,7 @@ def load(account, tailored_audience_id, params)
194194
end
195195
end
196196

197-
class TailoredAudiencePermission
197+
class CustomAudiencePermission
198198

199199
include TwitterAds::DSL
200200
include TwitterAds::Resource
@@ -207,16 +207,16 @@ class TailoredAudiencePermission
207207
property :deleted, type: :bool, read_only: true
208208

209209
property :id
210-
property :tailored_audience_id
210+
property :custom_audience_id
211211
property :granted_account_id
212212
property :permission_level
213213

214214
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
215-
'accounts/%{account_id}/tailored_audiences/' \
216-
'%{tailored_audience_id}/permissions' # @api private
215+
'accounts/%{account_id}/custom_audiences/' \
216+
'%{custom_audience_id}/permissions' # @api private
217217
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
218-
'accounts/%{account_id}/tailored_audiences/' \
219-
'%{tailored_audience_id}/permissions/%{id}' # @api private
218+
'accounts/%{account_id}/custom_audiences/' \
219+
'%{custom_audience_id}/permissions/%{id}' # @api private
220220

221221
def initialize(account)
222222
@account = account
@@ -226,22 +226,22 @@ def initialize(account)
226226
class << self
227227

228228
# Retrieve details for some or
229-
# all permissions associated with the specified tailored audience.
229+
# all permissions associated with the specified custom audience.
230230
#
231231
# @exapmle
232-
# permissions = TailoredAudiencePermission.all(account, '36n4f')
232+
# permissions = CustomAudiencePermission.all(account, '36n4f')
233233
#
234234
# @param account [Account] The account object instance.
235-
# @param tailored_audience_id [String] The tailored audience id.
235+
# @param custom_audience_id [String] The custom audience id.
236236
#
237237
# @since 5.2.0
238238
#
239-
# @return [TailoredAudiencePermission] The tailored audience permission instance.
240-
def all(account, tailored_audience_id, opts = {})
239+
# @return [CustomAudiencePermission] The custom audience permission instance.
240+
def all(account, custom_audience_id, opts = {})
241241
params = {}.merge!(opts)
242242
resource = RESOURCE_COLLECTION % {
243243
account_id: account.id,
244-
tailored_audience_id: tailored_audience_id
244+
custom_audience_id: custom_audience_id
245245
}
246246
request = Request.new(account.client, :get, resource, params: params)
247247
Cursor.new(self, request, init_with: [account])
@@ -250,7 +250,7 @@ def all(account, tailored_audience_id, opts = {})
250250
end
251251

252252
# Saves or updates the current object instance
253-
# depending on the presence of `object.tailored_audience_id`.
253+
# depending on the presence of `object.custom_audience_id`.
254254
#
255255
# @exapmle
256256
# object.save
@@ -261,14 +261,14 @@ def all(account, tailored_audience_id, opts = {})
261261
def save
262262
resource = RESOURCE_COLLECTION % {
263263
account_id: account.id,
264-
tailored_audience_id: tailored_audience_id
264+
custom_audience_id: custom_audience_id
265265
}
266266
params = to_params
267267
response = Request.new(account.client, :post, resource, params: params).perform
268268
from_response(response.body[:data])
269269
end
270270

271-
# Deletes the current or specified tailored audience permission.
271+
# Deletes the current or specified custom audience permission.
272272
#
273273
# @example
274274
# object.delete!
@@ -281,7 +281,7 @@ def save
281281
def delete!
282282
resource = RESOURCE % {
283283
account_id: account.id,
284-
tailored_audience_id: tailored_audience_id,
284+
custom_audience_id: custom_audience_id,
285285
id: @id
286286
}
287287
response = Request.new(account.client, :delete, resource).perform

lib/twitter-ads/campaign/line_item.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ class LineItem < Analytics
1818

1919
property :advertiser_domain
2020
property :android_app_store_identifier
21+
property :audience_expansion
2122
property :automatically_select_bid
2223
property :bid_amount_local_micro
23-
property :bid_unit
24+
property :bid_strategy
2425
property :campaign_id
2526
property :categories
26-
property :charge_by
2727
property :end_time, type: :time
2828
property :entity_status
29+
property :goal
2930
property :ios_app_store_identifier
3031
property :name
3132
property :objective
32-
property :optimization
33+
property :pay_by
3334
property :placements
3435
property :primary_web_event_tag
3536
property :product_type
@@ -38,9 +39,7 @@ class LineItem < Analytics
3839

3940
# beta (not yet generally available)
4041
property :advertiser_user_id
41-
property :bid_type
4242
property :tracking_tags
43-
property :audience_expansion
4443

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

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

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

0 commit comments

Comments
 (0)