diff --git a/examples/audience_summary.rb b/examples/audience_estimate.rb similarity index 91% rename from examples/audience_summary.rb rename to examples/audience_estimate.rb index 6eb69c29..aa88dbc0 100644 --- a/examples/audience_summary.rb +++ b/examples/audience_estimate.rb @@ -41,5 +41,5 @@ ] } -audience_summary = TwitterAds::AudienceSummary.fetch(account, params) -puts audience_summary +audience_estimate = TwitterAds::AudienceEstimate.fetch(account, params) +puts audience_estimate diff --git a/lib/twitter-ads.rb b/lib/twitter-ads.rb index ea706324..824874f0 100644 --- a/lib/twitter-ads.rb +++ b/lib/twitter-ads.rb @@ -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' @@ -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' diff --git a/lib/twitter-ads/account.rb b/lib/twitter-ads/account.rb index df49ff1e..45959c8e 100644 --- a/lib/twitter-ads/account.rb +++ b/lib/twitter-ads/account.rb @@ -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 @@ -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. diff --git a/lib/twitter-ads/campaign/line_item.rb b/lib/twitter-ads/campaign/line_item.rb index c1e9990b..1a347d67 100644 --- a/lib/twitter-ads/campaign/line_item.rb +++ b/lib/twitter-ads/campaign/line_item.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/twitter-ads/campaign/tracking_tags.rb b/lib/twitter-ads/campaign/tracking_tags.rb new file mode 100644 index 00000000..a0af83f7 --- /dev/null +++ b/lib/twitter-ads/campaign/tracking_tags.rb @@ -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 diff --git a/lib/twitter-ads/client.rb b/lib/twitter-ads/client.rb index a179f520..aec0e996 100644 --- a/lib/twitter-ads/client.rb +++ b/lib/twitter-ads/client.rb @@ -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. diff --git a/lib/twitter-ads/creative/cards_fetch.rb b/lib/twitter-ads/creative/cards_fetch.rb index a29b07c9..1a4d1a0c 100644 --- a/lib/twitter-ads/creative/cards_fetch.rb +++ b/lib/twitter-ads/creative/cards_fetch.rb @@ -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 diff --git a/lib/twitter-ads/creative/image_app_download_card.rb b/lib/twitter-ads/creative/image_app_download_card.rb index 58d6a43e..bb95726b 100644 --- a/lib/twitter-ads/creative/image_app_download_card.rb +++ b/lib/twitter-ads/creative/image_app_download_card.rb @@ -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 diff --git a/lib/twitter-ads/creative/video_app_download_card.rb b/lib/twitter-ads/creative/video_app_download_card.rb index cadea730..9038b24b 100644 --- a/lib/twitter-ads/creative/video_app_download_card.rb +++ b/lib/twitter-ads/creative/video_app_download_card.rb @@ -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 diff --git a/lib/twitter-ads/enum.rb b/lib/twitter-ads/enum.rb index 8d3be480..9eb42361 100644 --- a/lib/twitter-ads/enum.rb +++ b/lib/twitter-ads/enum.rb @@ -84,6 +84,7 @@ module BidStrategy module PayBy APP_CLICK = 'APP_CLICK' + IMPRESSION = 'IMPRESSION' end module MetricGroup diff --git a/lib/twitter-ads/targeting/audience_summary.rb b/lib/twitter-ads/targeting/audience_estimate.rb similarity index 90% rename from lib/twitter-ads/targeting/audience_summary.rb rename to lib/twitter-ads/targeting/audience_estimate.rb index aeef35fc..4a3dcfbb 100644 --- a/lib/twitter-ads/targeting/audience_summary.rb +++ b/lib/twitter-ads/targeting/audience_estimate.rb @@ -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 @@ -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'}]} diff --git a/lib/twitter-ads/version.rb b/lib/twitter-ads/version.rb index b70e79db..6378c96c 100644 --- a/lib/twitter-ads/version.rb +++ b/lib/twitter-ads/version.rb @@ -2,5 +2,5 @@ # Copyright (C) 2019 Twitter, Inc. module TwitterAds - VERSION = '9.0.0' + VERSION = '10.0.0' end diff --git a/spec/fixtures/accounts_all.json b/spec/fixtures/accounts_all.json index d2656991..7ab5ba1c 100644 --- a/spec/fixtures/accounts_all.json +++ b/spec/fixtures/accounts_all.json @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/fixtures/accounts_load.json b/spec/fixtures/accounts_load.json index 411fd689..84044ad8 100644 --- a/spec/fixtures/accounts_load.json +++ b/spec/fixtures/accounts_load.json @@ -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 diff --git a/spec/fixtures/audience_summary.json b/spec/fixtures/audience_estimate.json similarity index 100% rename from spec/fixtures/audience_summary.json rename to spec/fixtures/audience_estimate.json diff --git a/spec/fixtures/line_items_all.json b/spec/fixtures/line_items_all.json index edd1623f..cc93506a 100644 --- a/spec/fixtures/line_items_all.json +++ b/spec/fixtures/line_items_all.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/spec/fixtures/line_items_load.json b/spec/fixtures/line_items_load.json index 76174ec1..b78240f8 100644 --- a/spec/fixtures/line_items_load.json +++ b/spec/fixtures/line_items_load.json @@ -8,7 +8,6 @@ "ALL_ON_TWITTER" ], "bid_amount_local_micro": 2000000, - "automatically_select_bid": false, "advertiser_domain": null, "primary_web_event_tag": null, "charge_by": "ENGAGEMENT", diff --git a/spec/fixtures/tracking_tags_load.json b/spec/fixtures/tracking_tags_load.json new file mode 100644 index 00000000..8dd7b895 --- /dev/null +++ b/spec/fixtures/tracking_tags_load.json @@ -0,0 +1,17 @@ +{ + "request": { + "params": { + "tracking_tag_id": "7035", + "account_id": "18ce54uhdu0" + } + }, + "data": { + "line_item_id": "dmbc0", + "tracking_tag_url": "https://ad.doubleclick.net/ddm/trackimp/N1234.2061500TWITTER-OFFICIAL/B9156151.125630439;dc_trk_aid=1355;dc_trk_cid=8675309", + "tracking_tag_type": "IMPRESSION_TAG", + "id": "7035", + "created_at": "2021-11-16T00:12:26Z", + "updated_at": "2021-11-16T00:12:26Z", + "deleted": false + } +} diff --git a/spec/twitter-ads/campaign/line_item_spec.rb b/spec/twitter-ads/campaign/line_item_spec.rb index de0c08ad..c3299b70 100644 --- a/spec/twitter-ads/campaign/line_item_spec.rb +++ b/spec/twitter-ads/campaign/line_item_spec.rb @@ -40,7 +40,6 @@ product_type placements bid_strategy - automatically_select_bid bid_amount_local_micro total_budget_amount_local_micro goal diff --git a/spec/twitter-ads/campaign/tracking_tag_spec.rb b/spec/twitter-ads/campaign/tracking_tag_spec.rb new file mode 100644 index 00000000..cbe24c00 --- /dev/null +++ b/spec/twitter-ads/campaign/tracking_tag_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +require 'spec_helper' + +describe TwitterAds::TrackingTag do + + before(:each) do + stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts") + stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph") + end + + let(:client) do + Client.new( + Faker::Lorem.characters(15), + Faker::Lorem.characters(40), + "123456-#{Faker::Lorem.characters(40)}", + Faker::Lorem.characters(40) + ) + end + + let(:account) { client.accounts.first } + + # check model properties + subject { described_class.new(account) } + read = %w(id) + write = %w(line_item_id tracking_tag_type tracking_tag_url) + include_examples 'object property check', read, write + + describe '#create' do + + let(:tracking_tag) { TwitterAds::TrackingTag.new(account) } + let!(:resource) { "#{ADS_API}/accounts/#{account.id}/tracking_tags" } + let!(:rel_path) { "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/tracking_tags" } + + before(:each) do + stub_fixture(:post, :tracking_tags_load, /#{resource}\?.*/) + end + + it 'creates post request with line item ID and url' do + line_item_id = 'axe123' + tracking_tag_url = 'https://ad.doubleclick.net/ddm/trackimp/N1234.2061500TWITTER-OFFICIAL/B9156151.125630439;dc_trk_aid=1355;dc_trk_cid=8675309' + tracking_tag_type = 'IMPRESSION_TAG' + + params = { + line_item_id: line_item_id, + tracking_tag_url: tracking_tag_url, + tracking_tag_type: tracking_tag_type + } + args = [account.client, :post, rel_path, params: params] + + expect(Request).to receive(:new).with(*args).and_call_original + tracking_tag.create(line_item_id, tracking_tag_url) + end + + end + +end diff --git a/spec/twitter-ads/targeting/audience_summary_spec.rb b/spec/twitter-ads/targeting/audience_estimate_spec.rb similarity index 87% rename from spec/twitter-ads/targeting/audience_summary_spec.rb rename to spec/twitter-ads/targeting/audience_estimate_spec.rb index 1e026dc9..cd1e33d0 100644 --- a/spec/twitter-ads/targeting/audience_summary_spec.rb +++ b/spec/twitter-ads/targeting/audience_estimate_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' -describe TwitterAds::AudienceSummary do +describe TwitterAds::AudienceEstimate do before(:each) do stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts") stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph") - stub_fixture(:post, :audience_summary, "#{ADS_API}/accounts/2iqph/audience_summary") + stub_fixture(:post, :audience_estimate, "#{ADS_API}/accounts/2iqph/audience_estimate") end let(:client) do