Skip to content

Commit d0acddd

Browse files
Tom Osowskitushdante
andauthored
Ads api v10 (#255)
* Updates to switch to ios for Cards (#252) * Removing deprecated field salt * Removing deprecated field salt in tests * Add enum for Pay By Impression * renamed/removed line item props * moved props out of beta * updated enums * added support for cards endpoint * removed old tailored audiences endpoint * added new cards endpoint with examples * updated tailored audiences to custom audiences * update audience_summary to audience_estimate * removed automatically_select_bid from line items * Remove deprecated tracking_tags field from line items * Add Tracking Tags support Co-authored-by: Tushar Bhushan <tushar.bhushan@yahoo.com>
1 parent 90881db commit d0acddd

21 files changed

Lines changed: 210 additions & 43 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
]
4242
}
4343

44-
audience_summary = TwitterAds::AudienceSummary.fetch(account, params)
45-
puts audience_summary
44+
audience_estimate = TwitterAds::AudienceEstimate.fetch(account, params)
45+
puts audience_estimate

lib/twitter-ads.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
require 'twitter-ads/campaign/line_item'
3838
require 'twitter-ads/campaign/promotable_user'
3939
require 'twitter-ads/campaign/targeting_criteria'
40+
require 'twitter-ads/campaign/tracking_tags'
4041
require 'twitter-ads/campaign/tweet'
4142
require 'twitter-ads/campaign/organic_tweet'
4243
require 'twitter-ads/campaign/iab_category'
@@ -75,7 +76,7 @@
7576
require 'twitter-ads/creative/tweet_previews'
7677
require 'twitter-ads/creative/tweets'
7778

78-
require 'twitter-ads/targeting/audience_summary'
79+
require 'twitter-ads/targeting/audience_estimate'
7980

8081
require 'twitter-ads/measurement/web_event_tag'
8182
require 'twitter-ads/measurement/app_event_tag'

lib/twitter-ads/account.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class Account
1010

1111
property :id, read_only: true
1212
property :name, read_only: true
13-
property :salt, read_only: true
1413
property :timezone, read_only: true
1514
property :timezone_switch_at, type: :time, read_only: true
1615
property :created_at, type: :time, read_only: true
@@ -218,6 +217,23 @@ def line_items(id = nil, opts = {})
218217
load_resource(LineItem, id, opts)
219218
end
220219

220+
# Returns a collection of tracking tags available to the
221+
# current account.
222+
#
223+
# @param id [String] The LineItem ID value.
224+
# @param opts [Hash] A Hash of extended options.
225+
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
226+
# @option opts [String] :sort_by The object param to sort the API response by.
227+
# @option opts [String] :line_item_ids The object param to sort the API response by.
228+
# @option opts [String] :tracking_tag_ids The object param to sort the API response by.
229+
#
230+
# @return A Cursor or object instance.
231+
#
232+
# @since 10.0.0
233+
def tracking_tags(id = nil, opts = {})
234+
load_resource(TrackingTag, id, opts)
235+
end
236+
221237
# Returns a collection of app lists available to the current account.
222238
#
223239
# @param id [String] The AppList ID value.

lib/twitter-ads/campaign/line_item.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class LineItem < Analytics
1919
property :advertiser_domain
2020
property :android_app_store_identifier
2121
property :audience_expansion
22-
property :automatically_select_bid
2322
property :bid_amount_local_micro
2423
property :bid_strategy
2524
property :campaign_id
@@ -39,7 +38,6 @@ class LineItem < Analytics
3938

4039
# beta (not yet generally available)
4140
property :advertiser_user_id
42-
property :tracking_tags
4341

4442
# sdk only
4543
property :to_delete, type: :bool
@@ -94,5 +92,8 @@ def targeting_criteria(id = nil, opts = {})
9492
id ? TargetingCriteria.load(account, id, opts) : TargetingCriteria.all(account, @id, opts)
9593
end
9694

95+
def tracking_tags(id = nil, opts = {})
96+
id ? TrackingTag.load(account, id, opts) : TrackingTag.all(account, @id, opts)
97+
end
9798
end
9899
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# frozen_string_literal: true
2+
# Copyright (C) 2019 Twitter, Inc.
3+
4+
module TwitterAds
5+
class TrackingTag
6+
7+
include TwitterAds::DSL
8+
include TwitterAds::Resource
9+
include TwitterAds::Persistence
10+
11+
attr_reader :account
12+
13+
property :id, read_only: true
14+
property :deleted, type: :bool, read_only: true
15+
property :created_at, type: :time, read_only: true
16+
property :updated_at, type: :time, read_only: true
17+
18+
property :line_item_id
19+
property :tracking_tag_type
20+
property :tracking_tag_url
21+
22+
# sdk only
23+
property :to_delete, type: :bool
24+
25+
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
26+
'accounts/%{account_id}/tracking_tags' # @api private
27+
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
28+
'accounts/%{account_id}/tracking_tags/%{id}' # @api private
29+
30+
def initialize(account)
31+
@account = account
32+
self
33+
end
34+
35+
# Creates a new Tracking Tag
36+
#
37+
# @param line_item_id [String] The line item id to create tags for.
38+
# @param tracking_tag_url [String] tracking tag URL.
39+
#
40+
# @return [self] Returns the instance refreshed from the API
41+
def create(line_item_id, tracking_tag_url)
42+
resource = self.class::RESOURCE_COLLECTION % { account_id: account.id }
43+
params = to_params.merge!(
44+
line_item_id: line_item_id,
45+
tracking_tag_url: tracking_tag_url,
46+
tracking_tag_type: 'IMPRESSION_TAG'
47+
)
48+
response = Request.new(account.client, :post, resource, params: params).perform
49+
from_response(response.body[:data])
50+
end
51+
52+
class << self
53+
54+
# Returns a Cursor instance for a given resource.
55+
#
56+
# @param account [Account] The Account object instance.
57+
# @param line_item_ids [String] A String or String array of Line Item IDs.
58+
# @param opts [Hash] An optional Hash of extended options.
59+
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
60+
# @option opts [String] :sort_by The object param to sort the API response by.
61+
#
62+
# @return [Cursor] A Cusor object ready to iterate through the API response.
63+
#
64+
# @since 0.3.1
65+
# @see Cursor
66+
# @see https://dev.twitter.com/ads/basics/sorting Sorting
67+
def all(account, line_item_ids, opts = {})
68+
if !line_item_ids.empty?
69+
params = { line_item_ids: Array(line_item_ids).join(',') }.merge!(opts)
70+
end
71+
resource = RESOURCE_COLLECTION % { account_id: account.id }
72+
request = Request.new(account.client, :get, resource, params: params)
73+
Cursor.new(self, request, init_with: [account])
74+
end
75+
76+
# Returns an object instance for a given resource.
77+
#
78+
# @param account [Account] The Account object instance.
79+
# @param id [String] The ID of the specific object to be loaded.
80+
# @param opts [Hash] An optional Hash of extended options.
81+
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
82+
# @option opts [String] :sort_by The object param to sort the API response by.
83+
#
84+
# @return [self] The object instance for the specified resource.
85+
#
86+
# @since 0.3.1
87+
def load(account, id, opts = {})
88+
params = { with_deleted: true }.merge!(opts)
89+
resource = RESOURCE % { account_id: account.id, id: id }
90+
response = Request.new(account.client, :get, resource, params: params).perform
91+
new(account).from_response(response.body[:data])
92+
end
93+
94+
end
95+
96+
end
97+
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 = '9'
6+
API_VERSION = '10'
77

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

lib/twitter-ads/creative/cards_fetch.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ class CardsFetch
3535
property :image, read_only: true
3636
property :image_display_height, read_only: true
3737
property :image_display_width, read_only: true
38-
property :ipad_app_id, read_only: true
39-
property :ipad_deep_link, read_only: true
40-
property :iphone_app_id, read_only: true
41-
property :iphone_deep_link, read_only: true
38+
property :ios_app_store_identifier, read_only: true
39+
property :ios_deep_link, read_only: true
4240
property :name, read_only: true
4341
property :recipient_user_id, read_only: true
4442
property :second_choice, read_only: true

lib/twitter-ads/creative/image_app_download_card.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class ImageAppDownloadCard
2626
property :app_cta
2727
property :googleplay_app_id
2828
property :googleplay_deep_link
29-
property :iphone_app_id
30-
property :iphone_deep_link
31-
property :ipad_app_id
32-
property :ipad_deep_link
29+
property :ios_app_store_identifier
30+
property :ios_deep_link
3331
property :name
3432
property :media_key
3533

lib/twitter-ads/creative/video_app_download_card.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ class VideoAppDownloadCard
2525
property :country_code
2626
property :app_cta
2727
property :poster_media_key
28-
property :ipad_app_id
29-
property :ipad_deep_link
30-
property :iphone_app_id
31-
property :iphone_deep_link
28+
property :ios_app_store_identifier
29+
property :ios_deep_link
3230
property :googleplay_app_id
3331
property :googleplay_deep_link
3432
property :name

lib/twitter-ads/enum.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module BidStrategy
8484

8585
module PayBy
8686
APP_CLICK = 'APP_CLICK'
87+
IMPRESSION = 'IMPRESSION'
8788
end
8889

8990
module MetricGroup

0 commit comments

Comments
 (0)