Skip to content

Commit

Permalink
Ads api v10 (#255)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
osowskit and tushdante authored Nov 18, 2021
1 parent 90881db commit d0acddd
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
]
}

audience_summary = TwitterAds::AudienceSummary.fetch(account, params)
puts audience_summary
audience_estimate = TwitterAds::AudienceEstimate.fetch(account, params)
puts audience_estimate
3 changes: 2 additions & 1 deletion lib/twitter-ads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require 'twitter-ads/campaign/line_item'
require 'twitter-ads/campaign/promotable_user'
require 'twitter-ads/campaign/targeting_criteria'
require 'twitter-ads/campaign/tracking_tags'
require 'twitter-ads/campaign/tweet'
require 'twitter-ads/campaign/organic_tweet'
require 'twitter-ads/campaign/iab_category'
Expand Down Expand Up @@ -75,7 +76,7 @@
require 'twitter-ads/creative/tweet_previews'
require 'twitter-ads/creative/tweets'

require 'twitter-ads/targeting/audience_summary'
require 'twitter-ads/targeting/audience_estimate'

require 'twitter-ads/measurement/web_event_tag'
require 'twitter-ads/measurement/app_event_tag'
Expand Down
18 changes: 17 additions & 1 deletion lib/twitter-ads/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Account

property :id, read_only: true
property :name, read_only: true
property :salt, read_only: true
property :timezone, read_only: true
property :timezone_switch_at, type: :time, read_only: true
property :created_at, type: :time, read_only: true
Expand Down Expand Up @@ -218,6 +217,23 @@ def line_items(id = nil, opts = {})
load_resource(LineItem, id, opts)
end

# Returns a collection of tracking tags available to the
# current account.
#
# @param id [String] The LineItem ID value.
# @param opts [Hash] A Hash of extended options.
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
# @option opts [String] :sort_by The object param to sort the API response by.
# @option opts [String] :line_item_ids The object param to sort the API response by.
# @option opts [String] :tracking_tag_ids The object param to sort the API response by.
#
# @return A Cursor or object instance.
#
# @since 10.0.0
def tracking_tags(id = nil, opts = {})
load_resource(TrackingTag, id, opts)
end

# Returns a collection of app lists available to the current account.
#
# @param id [String] The AppList ID value.
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter-ads/campaign/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class LineItem < Analytics
property :advertiser_domain
property :android_app_store_identifier
property :audience_expansion
property :automatically_select_bid
property :bid_amount_local_micro
property :bid_strategy
property :campaign_id
Expand All @@ -39,7 +38,6 @@ class LineItem < Analytics

# beta (not yet generally available)
property :advertiser_user_id
property :tracking_tags

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

def tracking_tags(id = nil, opts = {})
id ? TrackingTag.load(account, id, opts) : TrackingTag.all(account, @id, opts)
end
end
end
97 changes: 97 additions & 0 deletions lib/twitter-ads/campaign/tracking_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# frozen_string_literal: true
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
class TrackingTag

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence

attr_reader :account

property :id, read_only: true
property :deleted, type: :bool, read_only: true
property :created_at, type: :time, read_only: true
property :updated_at, type: :time, read_only: true

property :line_item_id
property :tracking_tag_type
property :tracking_tag_url

# sdk only
property :to_delete, type: :bool

RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/tracking_tags' # @api private
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/tracking_tags/%{id}' # @api private

def initialize(account)
@account = account
self
end

# Creates a new Tracking Tag
#
# @param line_item_id [String] The line item id to create tags for.
# @param tracking_tag_url [String] tracking tag URL.
#
# @return [self] Returns the instance refreshed from the API
def create(line_item_id, tracking_tag_url)
resource = self.class::RESOURCE_COLLECTION % { account_id: account.id }
params = to_params.merge!(
line_item_id: line_item_id,
tracking_tag_url: tracking_tag_url,
tracking_tag_type: 'IMPRESSION_TAG'
)
response = Request.new(account.client, :post, resource, params: params).perform
from_response(response.body[:data])
end

class << self

# Returns a Cursor instance for a given resource.
#
# @param account [Account] The Account object instance.
# @param line_item_ids [String] A String or String array of Line Item IDs.
# @param opts [Hash] An optional Hash of extended options.
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
# @option opts [String] :sort_by The object param to sort the API response by.
#
# @return [Cursor] A Cusor object ready to iterate through the API response.
#
# @since 0.3.1
# @see Cursor
# @see https://dev.twitter.com/ads/basics/sorting Sorting
def all(account, line_item_ids, opts = {})
if !line_item_ids.empty?
params = { line_item_ids: Array(line_item_ids).join(',') }.merge!(opts)
end
resource = RESOURCE_COLLECTION % { account_id: account.id }
request = Request.new(account.client, :get, resource, params: params)
Cursor.new(self, request, init_with: [account])
end

# Returns an object instance for a given resource.
#
# @param account [Account] The Account object instance.
# @param id [String] The ID of the specific object to be loaded.
# @param opts [Hash] An optional Hash of extended options.
# @option opts [Boolean] :with_deleted Indicates if deleted items should be included.
# @option opts [String] :sort_by The object param to sort the API response by.
#
# @return [self] The object instance for the specified resource.
#
# @since 0.3.1
def load(account, id, opts = {})
params = { with_deleted: true }.merge!(opts)
resource = RESOURCE % { account_id: account.id, id: id }
response = Request.new(account.client, :get, resource, params: params).perform
new(account).from_response(response.body[:data])
end

end

end
end
2 changes: 1 addition & 1 deletion lib/twitter-ads/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module TwitterAds

API_VERSION = '9'
API_VERSION = '10'

# The Ads API Client class which functions as a
# container for basic API consumer information.
Expand Down
6 changes: 2 additions & 4 deletions lib/twitter-ads/creative/cards_fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class CardsFetch
property :image, read_only: true
property :image_display_height, read_only: true
property :image_display_width, read_only: true
property :ipad_app_id, read_only: true
property :ipad_deep_link, read_only: true
property :iphone_app_id, read_only: true
property :iphone_deep_link, read_only: true
property :ios_app_store_identifier, read_only: true
property :ios_deep_link, read_only: true
property :name, read_only: true
property :recipient_user_id, read_only: true
property :second_choice, read_only: true
Expand Down
6 changes: 2 additions & 4 deletions lib/twitter-ads/creative/image_app_download_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class ImageAppDownloadCard
property :app_cta
property :googleplay_app_id
property :googleplay_deep_link
property :iphone_app_id
property :iphone_deep_link
property :ipad_app_id
property :ipad_deep_link
property :ios_app_store_identifier
property :ios_deep_link
property :name
property :media_key

Expand Down
6 changes: 2 additions & 4 deletions lib/twitter-ads/creative/video_app_download_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ class VideoAppDownloadCard
property :country_code
property :app_cta
property :poster_media_key
property :ipad_app_id
property :ipad_deep_link
property :iphone_app_id
property :iphone_deep_link
property :ios_app_store_identifier
property :ios_deep_link
property :googleplay_app_id
property :googleplay_deep_link
property :name
Expand Down
1 change: 1 addition & 0 deletions lib/twitter-ads/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module BidStrategy

module PayBy
APP_CLICK = 'APP_CLICK'
IMPRESSION = 'IMPRESSION'
end

module MetricGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
module AudienceSummary
module AudienceEstimate

include TwitterAds::DSL
include TwitterAds::Resource

RESOURCE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/audience_summary'
'accounts/%{account_id}/audience_estimate'

property :audience_size, read_only: true

Expand All @@ -17,7 +17,7 @@ class << self
# Get an audience summary for the specified targeting criteria.
#
# @example
# TwitterAds::AudienceSummary.fetch(
# TwitterAds::AudienceEstimate.fetch(
# account,
# params: {targeting_criteria:[{targeting_type:'LOCATION',
# targeting_value:'96683cc9126741d1'}]}
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter-ads/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
VERSION = '9.0.0'
VERSION = '10.0.0'
end
5 changes: 0 additions & 5 deletions spec/fixtures/accounts_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"timezone_switch_at": "2014-11-17T08:00:00Z",
"id": "2iqph",
"created_at": "2015-03-04T10:50:42Z",
"salt": "5ab2pizq7qxjjqrx3z67f4wbko61o7xs",
"updated_at": "2015-04-11T05:20:08Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand All @@ -20,7 +19,6 @@
"timezone_switch_at": "2014-11-17T08:00:00Z",
"id": "pz6ec",
"created_at": "2015-05-29T00:52:16Z",
"salt": "39ku32xvhdt0jax8thps2c70e2fv3yok",
"updated_at": "2015-05-29T00:52:16Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand All @@ -31,7 +29,6 @@
"timezone_switch_at": "2014-11-17T08:00:00Z",
"id": "j9ozo",
"created_at": "2015-05-01T12:08:10Z",
"salt": "winwfne3y6oyikl4tm84bj9r50waxj37",
"updated_at": "2015-05-01T12:08:10Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand All @@ -42,7 +39,6 @@
"timezone_switch_at": "2014-11-17T08:00:00Z",
"id": "9ttgd",
"created_at": "2015-06-24T18:51:20Z",
"salt": "tj9hmt5xylm5zztrq05w7hwh4mkpkg5r",
"updated_at": "2015-06-26T06:13:24Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand All @@ -53,7 +49,6 @@
"timezone_switch_at": "2013-05-22T07:00:00Z",
"id": "47d0v",
"created_at": "2015-05-28T05:42:03Z",
"salt": "1ms1mq1nww7zl7169865gwqt89s9127m",
"updated_at": "2015-05-28T05:42:03Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/accounts_load.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"timezone_switch_at": "2014-11-17T08:00:00Z",
"id": "2iqph",
"created_at": "2015-03-04T10:50:42Z",
"salt": "5ab2pizq7qxjjqrx3z67f4wbko61o7xs",
"updated_at": "2015-04-11T05:20:08Z",
"approval_status": "ACCEPTED",
"deleted": false
Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions spec/fixtures/line_items_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ALL_ON_TWITTER"
],
"bid_amount_local_micro": 2000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -40,7 +39,6 @@
"ALL_ON_TWITTER"
],
"bid_amount_local_micro": 2000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -67,7 +65,6 @@
"TWITTER_SEARCH"
],
"bid_amount_local_micro": 100000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -94,7 +91,6 @@
"TWITTER_SEARCH"
],
"bid_amount_local_micro": 500000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -121,7 +117,6 @@
"TWITTER_TIMELINE"
],
"bid_amount_local_micro": 50000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand Down Expand Up @@ -149,7 +144,6 @@
"TWITTER_TIMELINE"
],
"bid_amount_local_micro": 50000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand Down Expand Up @@ -177,7 +171,6 @@
"TWITTER_SEARCH"
],
"bid_amount_local_micro": 50000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -204,7 +197,6 @@
"TWITTER_TIMELINE"
],
"bid_amount_local_micro": 500000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -231,7 +223,6 @@
"TWITTER_SEARCH"
],
"bid_amount_local_micro": 50000000,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand All @@ -258,7 +249,6 @@
"TWITTER_TIMELINE"
],
"bid_amount_local_micro": 2009999,
"automatically_select_bid": false,
"advertiser_domain": null,
"primary_web_event_tag": null,
"charge_by": "ENGAGEMENT",
Expand Down
Loading

0 comments on commit d0acddd

Please sign in to comment.