From e1f48cac5f18dd801f0424eb2ed939014110b044 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 11:55:22 -0700 Subject: [PATCH 01/10] bump version to 7 --- lib/twitter-ads/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter-ads/version.rb b/lib/twitter-ads/version.rb index 8fe3c1bf..925d7a29 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 = '6.0.1' + VERSION = '7.0.0' end From a64ffb012690aa9d68b30f0400798e5af9720a5f Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 12:34:47 -0700 Subject: [PATCH 02/10] changed serving_status to entity_status for media creatives --- lib/twitter-ads/creative/media_creative.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter-ads/creative/media_creative.rb b/lib/twitter-ads/creative/media_creative.rb index 08b6c2d1..e2623222 100644 --- a/lib/twitter-ads/creative/media_creative.rb +++ b/lib/twitter-ads/creative/media_creative.rb @@ -16,7 +16,7 @@ class MediaCreative < Analytics property :created_at, type: :time, read_only: true property :deleted, type: :bool, read_only: true property :id, read_only: true - property :serving_status, read_only: true + property :entity_status, read_only: true property :updated_at, type: :time, read_only: true property :account_media_id From 1c0c1d0376bdfd57b2b1b777f5f4992da21415f4 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 12:36:26 -0700 Subject: [PATCH 03/10] added granular tap placements --- lib/twitter-ads/enum.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/twitter-ads/enum.rb b/lib/twitter-ads/enum.rb index 58f64d4b..809f2ddc 100644 --- a/lib/twitter-ads/enum.rb +++ b/lib/twitter-ads/enum.rb @@ -28,6 +28,11 @@ module Placement TWITTER_SEARCH = 'TWITTER_SEARCH' TWITTER_TIMELINE = 'TWITTER_TIMELINE' PUBLISHER_NETWORK = 'PUBLISHER_NETWORK' + TAP_FULL = 'TAP_FULL' + TAP_FULL_LANDSCAPE= 'TAP_FULL_LANDSCAPE' + TAP_BANNER = 'TAP_BANNER' + TAP_NATIVE = 'TAP_NATIVE' + TAP_MRECT = 'TAP_MRECT' end module Placement From 26c026af6174ecb6e4ef66045d4515beb0bb7911 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 12:40:37 -0700 Subject: [PATCH 04/10] removed depredcated behavior targeting --- .../targeting_criteria/behavior.rb | 27 ------------------- .../targeting_criteria/behavior_taxonomy.rb | 24 ----------------- 2 files changed, 51 deletions(-) delete mode 100644 lib/twitter-ads/targeting_criteria/behavior.rb delete mode 100644 lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb diff --git a/lib/twitter-ads/targeting_criteria/behavior.rb b/lib/twitter-ads/targeting_criteria/behavior.rb deleted file mode 100644 index 139133a7..00000000 --- a/lib/twitter-ads/targeting_criteria/behavior.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - class Behavior - - include TwitterAds::DSL - include TwitterAds::Resource - - property :id, read_only: true - property :name, read_only: true - property :targeting_type, read_only: true - property :targeting_value, read_only: true - property :audience_code, read_only: true - property :country_code, read_only: true - property :partner_source, read_only: true - property :targetable_type, read_only: true - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \ - 'targeting_criteria/behaviors' # @api private - - def initialize(account) - @account = account - self - end - end -end diff --git a/lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb b/lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb deleted file mode 100644 index 6a495b14..00000000 --- a/lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - class BehaviorTaxonomy - - include TwitterAds::DSL - include TwitterAds::Resource - - property :id, read_only: true - property :name, read_only: true - property :parent_id, read_only: true - property :created_at, read_only: true - property :updated_at, read_only: true - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \ - 'targeting_criteria/behavior_taxonomies' # @api private - - def initialize(account) - @account = account - self - end - end -end From 99c4719f9dd25129d87019cdc36025befd0e3fd5 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 12:47:58 -0700 Subject: [PATCH 05/10] added advertiser business categories endpoint --- .../advertiser_business_categories.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/twitter-ads/campaign/advertiser_business_categories.rb diff --git a/lib/twitter-ads/campaign/advertiser_business_categories.rb b/lib/twitter-ads/campaign/advertiser_business_categories.rb new file mode 100644 index 00000000..ccd51686 --- /dev/null +++ b/lib/twitter-ads/campaign/advertiser_business_categories.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +module TwitterAds + class AdvertiserBusinessCategories + + include TwitterAds::DSL + include TwitterAds::Resource + + attr_reader :account + + property :id, read_only: true + property :name, read_only: true + property :iab_categories, read_only: true + + RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/advertiser_business_categories" # @api private + + def initialize(account) + @account = account + self + end + end +end From b785e20b4e6bcc131b4455361de5a7ae0c9e2b52 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 12:49:20 -0700 Subject: [PATCH 06/10] added missing content categories endpoint --- .../campaign/content_categories.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/twitter-ads/campaign/content_categories.rb diff --git a/lib/twitter-ads/campaign/content_categories.rb b/lib/twitter-ads/campaign/content_categories.rb new file mode 100644 index 00000000..33ca8419 --- /dev/null +++ b/lib/twitter-ads/campaign/content_categories.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +module TwitterAds + class ContentCategories + + include TwitterAds::DSL + include TwitterAds::Resource + + attr_reader :account + + property :id, read_only: true + property :name, read_only: true + property :iab_categories, read_only: true + + RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/content_categories" # @api private + + def initialize(account) + @account = account + self + end + end +end From be90ca1850da5ba8d51c10fbdf468ba95251c051 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 16:51:21 -0700 Subject: [PATCH 07/10] added audience summary and tests --- examples/audience_summary.rb | 45 ++++++++ lib/twitter-ads.rb | 6 +- .../advertiser_business_categories.rb | 3 +- lib/twitter-ads/client.rb | 2 +- lib/twitter-ads/enum.rb | 18 +-- lib/twitter-ads/targeting/audience_summary.rb | 47 ++++++++ lib/twitter-ads/targeting/reach_estimate.rb | 78 ------------- spec/fixtures/audience_summary.json | 14 +++ .../campaign/reach_estimate_spec.rb | 103 ------------------ .../creative/media_creative_spec.rb | 2 +- .../targeting/audience_summary_spec.rb | 41 +++++++ 11 files changed, 163 insertions(+), 196 deletions(-) create mode 100644 examples/audience_summary.rb create mode 100644 lib/twitter-ads/targeting/audience_summary.rb delete mode 100644 lib/twitter-ads/targeting/reach_estimate.rb create mode 100644 spec/fixtures/audience_summary.json delete mode 100644 spec/twitter-ads/campaign/reach_estimate_spec.rb create mode 100644 spec/twitter-ads/targeting/audience_summary_spec.rb diff --git a/examples/audience_summary.rb b/examples/audience_summary.rb new file mode 100644 index 00000000..ee4615f0 --- /dev/null +++ b/examples/audience_summary.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. +require 'twitter-ads' + +CONSUMER_KEY = 'your consumer key' +CONSUMER_SECRET = 'your consumer secret' +ACCESS_TOKEN = 'user access token' +ACCESS_TOKEN_SECRET = 'user access token secret' +ADS_ACCOUNT = 'ads account id' + +# initialize the twitter ads api client +client = TwitterAds::Client.new( + CONSUMER_KEY, + CONSUMER_SECRET, + ACCESS_TOKEN, + ACCESS_TOKEN_SECRET +) + +# load up the account instance +account = client.accounts(ADS_ACCOUNT) + +# targeting criteria params +params = { + targeting_criteria: [ + { + targeting_type: 'LOCATION', + targeting_value: '96683cc9126741d1' + }, + { + targeting_type: 'BROAD_KEYWORD', + targeting_value: 'cats' + }, + { + targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', + targeting_value: '14230524' + }, + { + targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', + targeting_value: '90420314' + } + ] +} + +audience_summary = TwitterAds::AudienceSummary.fetch(account, params) +puts audience_summary \ No newline at end of file diff --git a/lib/twitter-ads.rb b/lib/twitter-ads.rb index 0a20840c..75c58fe0 100644 --- a/lib/twitter-ads.rb +++ b/lib/twitter-ads.rb @@ -40,6 +40,8 @@ require 'twitter-ads/campaign/tweet' require 'twitter-ads/campaign/organic_tweet' require 'twitter-ads/campaign/iab_category' +require 'twitter-ads/campaign/advertiser_business_categories' +require 'twitter-ads/campaign/content_categories' require 'twitter-ads/targeting_criteria/tv_market' require 'twitter-ads/targeting_criteria/tv_show' @@ -52,8 +54,6 @@ require 'twitter-ads/targeting_criteria/location' require 'twitter-ads/targeting_criteria/interest' require 'twitter-ads/targeting_criteria/language' -require 'twitter-ads/targeting_criteria/behavior' -require 'twitter-ads/targeting_criteria/behavior_taxonomy' require 'twitter-ads/targeting_criteria/app_store_category' require 'twitter-ads/creative/account_media' @@ -74,7 +74,7 @@ require 'twitter-ads/creative/tweet_previews' require 'twitter-ads/creative/tweets' -require 'twitter-ads/targeting/reach_estimate' +require 'twitter-ads/targeting/audience_summary' require 'twitter-ads/measurement/web_event_tag' require 'twitter-ads/measurement/app_event_tag' diff --git a/lib/twitter-ads/campaign/advertiser_business_categories.rb b/lib/twitter-ads/campaign/advertiser_business_categories.rb index ccd51686..33e6a62a 100644 --- a/lib/twitter-ads/campaign/advertiser_business_categories.rb +++ b/lib/twitter-ads/campaign/advertiser_business_categories.rb @@ -13,7 +13,8 @@ class AdvertiserBusinessCategories property :name, read_only: true property :iab_categories, read_only: true - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/advertiser_business_categories" # @api private + # @api private + RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/advertiser_business_categories" def initialize(account) @account = account diff --git a/lib/twitter-ads/client.rb b/lib/twitter-ads/client.rb index 341a482b..b8e4646d 100644 --- a/lib/twitter-ads/client.rb +++ b/lib/twitter-ads/client.rb @@ -3,7 +3,7 @@ module TwitterAds - API_VERSION = '6' + API_VERSION = '7' # The Ads API Client class which functions as a # container for basic API consumer information. diff --git a/lib/twitter-ads/enum.rb b/lib/twitter-ads/enum.rb index 809f2ddc..de345be1 100644 --- a/lib/twitter-ads/enum.rb +++ b/lib/twitter-ads/enum.rb @@ -24,15 +24,15 @@ module Product end module Placement - ALL_ON_TWITTER = 'ALL_ON_TWITTER' - TWITTER_SEARCH = 'TWITTER_SEARCH' - TWITTER_TIMELINE = 'TWITTER_TIMELINE' - PUBLISHER_NETWORK = 'PUBLISHER_NETWORK' - TAP_FULL = 'TAP_FULL' - TAP_FULL_LANDSCAPE= 'TAP_FULL_LANDSCAPE' - TAP_BANNER = 'TAP_BANNER' - TAP_NATIVE = 'TAP_NATIVE' - TAP_MRECT = 'TAP_MRECT' + ALL_ON_TWITTER = 'ALL_ON_TWITTER' + TWITTER_SEARCH = 'TWITTER_SEARCH' + TWITTER_TIMELINE = 'TWITTER_TIMELINE' + PUBLISHER_NETWORK = 'PUBLISHER_NETWORK' + TAP_FULL = 'TAP_FULL' + TAP_FULL_LANDSCAPE = 'TAP_FULL_LANDSCAPE' + TAP_BANNER = 'TAP_BANNER' + TAP_NATIVE = 'TAP_NATIVE' + TAP_MRECT = 'TAP_MRECT' end module Placement diff --git a/lib/twitter-ads/targeting/audience_summary.rb b/lib/twitter-ads/targeting/audience_summary.rb new file mode 100644 index 00000000..aeef35fc --- /dev/null +++ b/lib/twitter-ads/targeting/audience_summary.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +module TwitterAds + module AudienceSummary + + include TwitterAds::DSL + include TwitterAds::Resource + + RESOURCE = "/#{TwitterAds::API_VERSION}/" \ + 'accounts/%{account_id}/audience_summary' + + property :audience_size, read_only: true + + class << self + + # Get an audience summary for the specified targeting criteria. + # + # @example + # TwitterAds::AudienceSummary.fetch( + # account, + # params: {targeting_criteria:[{targeting_type:'LOCATION', + # targeting_value:'96683cc9126741d1'}]} + # ) + # + # @param params [Hash] A hash of input targeting criteria values + # + # @return [Hash] A hash containing the min and max audience size. + # + # @since 7.0.0 + # @see https://developer.twitter.com/en/docs/ads/campaign-management/api-reference/audience-summary + def fetch(account, params) + resource = RESOURCE % { account_id: account.id } + headers = { 'Content-Type' => 'application/json' } + + response = TwitterAds::Request.new(account.client, + :post, + resource, + headers: headers, + body: params.to_json).perform + response.body[:data] + end + + end + + end +end diff --git a/lib/twitter-ads/targeting/reach_estimate.rb b/lib/twitter-ads/targeting/reach_estimate.rb deleted file mode 100644 index 652f97f3..00000000 --- a/lib/twitter-ads/targeting/reach_estimate.rb +++ /dev/null @@ -1,78 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - module ReachEstimate - - class << self - - # Get a reach estimate for the specified line item details. - # - # @example - # TwitterAds::ReachEstimate.fetch( - # account, - # 'PROMOTED_TWEETS', - # 'WEBSITE_CLICKS', - # 5500000, - # 30000000, - # similar_to_followers_of_user: 2153688540, - # gender: 2 - # ) - # - # @param client [Client] The Client object instance. - # @param product_type [String] The product type being targeted. - # @param objective [String] The objective being targeted. - # @param campaign_daily_budget_amount_local_micro [Long] Daily budget in micros. - # @param opts [Hash] A Hash of extended options. - # - # @option opts [Long] :bid_amount_local_micro Bid amount in local currency micros. - # @option opts [String] :bid_type The bidding mechanism. - # @option opts [String] :currency ISO-4217 Currency code for bid amount. - # @option opts [String] :followers_of_users Comma-separated user IDs. - # @option opts [String] :similar_to_followers_of_users Comma-separated user IDs. - # @option opts [String] :locations Comma-separated location IDs. - # @option opts [String] :interests Comma-seaprated interest IDs. - # @option opts [String] :gender Gender identifier. - # @option opts [String] :platforms Comma-separated platform IDs. - # @option opts [String] :tailored_audiences Comma-separated tailored audience IDs. - # @option opts [String] :tailored_audiences_expanded Comma-separated tailoerd audience IDs. - # @option opts [String] :languages Comma-separated language IDs. - # @option opts [String] :platform_versions Comma-separated platform version IDs. - # @option opts [String] :devices Comma-separated device IDs. - # @option opts [String] :behaviors Comma-separated behavior IDs. - # @option opts [String] :behaviors_expanded Comma-separated behaviors IDs. - # @option opts [String] :campaign engagement Campaign ID for Tweet Engager Retargeting. - # @option opts [String] :user_engagement Promoted User ID for Tweet Engager Retargeting. - # @option opts [String] :engagement_type engagement type for Tweet Engager Retargeting. - # @option opts [String] :network_operators Network operators to target - # @option opts [String] :app_store_categories App store categories to target. - # @option opts [String] :app_store_categories_expanded App store categories with lookalikes. - # - # @return [Hash] A hash containing count and infinite_bid_count. - # - # @since 1.0.0 - # @see https://developer.twitter.com/en/docs/ads/campaign-management/api-reference/reach-estimate - def fetch(account, product_type, objective, campaign_daily_budget, - opts = {}) - resource = "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/reach_estimate" - params = { - product_type: product_type, - objective: objective, - campaign_daily_budget_amount_local_micro: campaign_daily_budget - }.merge!(opts) - - # The response value count is "bid sensitive", we default to bid_type=AUTO here to preserve - # expected behavior despite an API change that occurred in December 2015. - unless params.keys.include?(:bid_type) || params.keys.include?(:bid_amount_local_micro) - params = { bid_type: 'AUTO' }.merge!(params) - end - - response = TwitterAds::Request.new(account.client, :get, - resource, params: params).perform - response.body[:data] - end - - end - - end -end diff --git a/spec/fixtures/audience_summary.json b/spec/fixtures/audience_summary.json new file mode 100644 index 00000000..74fba43b --- /dev/null +++ b/spec/fixtures/audience_summary.json @@ -0,0 +1,14 @@ +{ + "request": { + "params": { + "targeting_criteria": null, + "account_id": "18ce54d4x5t" + } + }, + "data": { + "audience_size": { + "min": 41133600, + "max": 50274400 + } + } +} \ No newline at end of file diff --git a/spec/twitter-ads/campaign/reach_estimate_spec.rb b/spec/twitter-ads/campaign/reach_estimate_spec.rb deleted file mode 100644 index c8c7579a..00000000 --- a/spec/twitter-ads/campaign/reach_estimate_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -require 'spec_helper' - -describe TwitterAds::ReachEstimate 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 } - - describe '#fetch' do - - let!(:resource) { "#{ADS_API}/accounts/#{account.id}/reach_estimate" } - let!(:rel_path) { "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/reach_estimate" } - - before(:each) do - stub_fixture(:get, :reach_estimate, /#{resource}\?.*/) - end - - it 'creates proper get request with no optional parameters specified' do - expected = { product_type: 'PROMOTED_TWEETS', objective: 'WEBSITE_CLICKS', - campaign_daily_budget_amount_local_micro: 30000000, bid_type: 'AUTO' } - args = [account.client, :get, rel_path, params: expected] - - expect(Request).to receive(:new).with(*args).and_call_original - TwitterAds::ReachEstimate.fetch(account, 'PROMOTED_TWEETS', 'WEBSITE_CLICKS', 30000000) - end - - it 'creates proper get request when optional paremeters are specified' do - - expected = { product_type: 'PROMOTED_TWEETS', objective: 'WEBSITE_CLICKS', - campaign_daily_budget_amount_local_micro: 30000000, - similar_to_followers_of_user: '12', gender: '2', bid_type: 'AUTO' } - args = [account.client, :get, rel_path, params: expected] - - expect(Request).to receive(:new).with(*args).and_call_original - TwitterAds::ReachEstimate.fetch( - account, 'PROMOTED_TWEETS', 'WEBSITE_CLICKS', 30000000, - similar_to_followers_of_user: '12', gender: '2') - - end - - context 'without bid_type specified' do - - it 'defaults bid_type to AUTO for backward compatibility' do - expected = { product_type: 'PROMOTED_TWEETS', objective: 'WEBSITE_CLICKS', - campaign_daily_budget_amount_local_micro: 30000000, - bid_type: 'AUTO' } - args = [account.client, :get, rel_path, params: expected] - - expect(Request).to receive(:new).with(*args).and_call_original - TwitterAds::ReachEstimate.fetch(account, 'PROMOTED_TWEETS', 'WEBSITE_CLICKS', 30000000) - end - - end - - context 'with bid_type specified' do - - it 'does not default bid_type to AUTO' do - expected = { product_type: 'PROMOTED_TWEETS', objective: 'WEBSITE_CLICKS', - bid_amount_local_micro: 3000000, - campaign_daily_budget_amount_local_micro: 30000000, bid_type: 'MAX' } - args = [account.client, :get, rel_path, params: expected] - - expect(Request).to receive(:new).with(*args).and_call_original - TwitterAds::ReachEstimate.fetch( - account, 'PROMOTED_TWEETS', 'WEBSITE_CLICKS', 30000000, - bid_amount_local_micro: 3000000, bid_type: 'MAX') - end - - end - - context 'with bid_amount_local_micro specified' do - - it 'does not default bid_type to AUTO' do - expected = { product_type: 'PROMOTED_TWEETS', objective: 'WEBSITE_CLICKS', - bid_amount_local_micro: 1500000, - campaign_daily_budget_amount_local_micro: 30000000 } - args = [account.client, :get, rel_path, params: expected] - - expect(Request).to receive(:new).with(*args).and_call_original - TwitterAds::ReachEstimate.fetch( - account, 'PROMOTED_TWEETS', 'WEBSITE_CLICKS', 30000000, bid_amount_local_micro: 1500000) - end - - end - - end - -end diff --git a/spec/twitter-ads/creative/media_creative_spec.rb b/spec/twitter-ads/creative/media_creative_spec.rb index 89f8e8b2..19c4060f 100644 --- a/spec/twitter-ads/creative/media_creative_spec.rb +++ b/spec/twitter-ads/creative/media_creative_spec.rb @@ -25,7 +25,7 @@ # check model properties subject { described_class.new(account) } - read = %w(id created_at updated_at deleted approval_status serving_status) + read = %w(id created_at updated_at deleted approval_status entity_status) write = %w(account_media_id line_item_id landing_url) include_examples 'object property check', read, write diff --git a/spec/twitter-ads/targeting/audience_summary_spec.rb b/spec/twitter-ads/targeting/audience_summary_spec.rb new file mode 100644 index 00000000..1e026dc9 --- /dev/null +++ b/spec/twitter-ads/targeting/audience_summary_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +require 'spec_helper' + +describe TwitterAds::AudienceSummary 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") + 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 } + let(:params) { + { + targeting_criteria: [{ + targeting_type: 'LOCATION', + targeting_value: '96683cc9126741d1' + }] + } + } + + # check model properties + subject { described_class.fetch(account, params) } + + it 'has all the correct properties' do + expect(subject[:audience_size][:min]).to eq(41133600) + expect(subject[:audience_size][:max]).to eq(50274400) + end + +end From b397cf1640a2902b98b3d76d04229d479b620abb Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Mon, 16 Mar 2020 16:54:40 -0700 Subject: [PATCH 08/10] removed scoped timeline endpoint --- examples/audience_summary.rb | 40 ++++++++++++++++++------------------ lib/twitter-ads/account.rb | 19 ----------------- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/examples/audience_summary.rb b/examples/audience_summary.rb index ee4615f0..6eb69c29 100644 --- a/examples/audience_summary.rb +++ b/examples/audience_summary.rb @@ -20,26 +20,26 @@ account = client.accounts(ADS_ACCOUNT) # targeting criteria params -params = { - targeting_criteria: [ - { - targeting_type: 'LOCATION', - targeting_value: '96683cc9126741d1' - }, - { - targeting_type: 'BROAD_KEYWORD', - targeting_value: 'cats' - }, - { - targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', - targeting_value: '14230524' - }, - { - targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', - targeting_value: '90420314' - } - ] +params = { + targeting_criteria: [ + { + targeting_type: 'LOCATION', + targeting_value: '96683cc9126741d1' + }, + { + targeting_type: 'BROAD_KEYWORD', + targeting_value: 'cats' + }, + { + targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', + targeting_value: '14230524' + }, + { + targeting_type: 'SIMILAR_TO_FOLLOWERS_OF_USER', + targeting_value: '90420314' + } + ] } audience_summary = TwitterAds::AudienceSummary.fetch(account, params) -puts audience_summary \ No newline at end of file +puts audience_summary diff --git a/lib/twitter-ads/account.rb b/lib/twitter-ads/account.rb index 73c4cbe5..cadfb0df 100644 --- a/lib/twitter-ads/account.rb +++ b/lib/twitter-ads/account.rb @@ -23,7 +23,6 @@ class Account 'accounts/%{id}' # @api private FEATURES = "/#{TwitterAds::API_VERSION}/" \ 'accounts/%{id}/features' # @api private - SCOPED_TIMELINE = '/5/accounts/%{id}/scoped_timeline' # @api private AUTHENTICATED_USER_ACCESS = "/#{TwitterAds::API_VERSION}/" \ 'accounts/%{id}/authenticated_user_access' # @api private @@ -247,24 +246,6 @@ def tailored_audiences(id = nil, opts = {}) load_resource(TailoredAudience, id, opts) end - # Returns the most recent promotable Tweets created by one or more specified Twitter users. - # - # @param ids [Array] An Array of Twitter user IDs. - # @param opts [Hash] A Hash of extended options. - # - # @return [Array] An Array of Tweet objects. - # - # @since 0.2.3 - def scoped_timeline(id, opts = {}) - TwitterAds::Utils.deprecated( - 'Scoped Timeline') - params = { user_id: id }.merge!(opts) - resource = SCOPED_TIMELINE % { id: @id } - request = Request.new(client, :get, resource, params: params) - response = request.perform - response.body[:data] - end - def authenticated_user_access params = {} resource = AUTHENTICATED_USER_ACCESS % { id: @id } From c83b0a10d673f5fd2a3bb076fe7e737ded48dc81 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Tue, 17 Mar 2020 12:03:29 -0700 Subject: [PATCH 09/10] remove codeclimate integration --- Gemfile | 1 - README.md | 2 +- spec/spec_helper.rb | 5 +---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 4ab8ef56..1f3d66f2 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,6 @@ gemspec gem 'rake' group :development, :test do - gem 'codeclimate-test-reporter', platforms: :mri gem 'cucumber' gem 'faker', '~> 1.0' # fix for breaking change in faker 2.x gem 'rspec' diff --git a/README.md b/README.md index 99d5cd20..9336f0f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Getting Started [![Build Status](https://travis-ci.org/twitterdev/twitter-ruby-ads-sdk.svg?branch=master)](https://travis-ci.org/twitterdev/twitter-ruby-ads-sdk) [![Code Climate](https://codeclimate.com/github/twitterdev/twitter-ruby-ads-sdk/badges/gpa.svg)](https://codeclimate.com/github/twitterdev/twitter-ruby-ads-sdk) [![Test Coverage](https://codeclimate.com/github/twitterdev/twitter-ruby-ads-sdk/badges/coverage.svg)](https://codeclimate.com/github/twitterdev/twitter-ruby-ads-sdk/coverage) [![Gem Version](https://badge.fury.io/rb/twitter-ads.svg)](http://badge.fury.io/rb/twitter-ads) +Getting Started [![Build Status](https://travis-ci.org/twitterdev/twitter-ruby-ads-sdk.svg?branch=master)](https://travis-ci.org/twitterdev/twitter-ruby-ads-sdk)[![Gem Version](https://badge.fury.io/rb/twitter-ads.svg)](http://badge.fury.io/rb/twitter-ads) ------ ##### Installation diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dacdb6e6..275b91b9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,12 +3,10 @@ unless RUBY_PLATFORM =~ /java/ || RUBY_ENGINE =~ /rbx/ require 'simplecov' - require 'codeclimate-test-reporter' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( [ - SimpleCov::Formatter::HTMLFormatter, - CodeClimate::TestReporter::Formatter + SimpleCov::Formatter::HTMLFormatter ] ) @@ -22,7 +20,6 @@ require 'faker' require 'webmock/rspec' -WebMock.disable_net_connect!(allow: 'codeclimate.com') require 'twitter-ads' include TwitterAds From 3bd7ae028b8483be10b70ba9aa096a69238b82db Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 18 Mar 2020 09:48:58 -0700 Subject: [PATCH 10/10] update fixture to correct account ID --- spec/fixtures/audience_summary.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fixtures/audience_summary.json b/spec/fixtures/audience_summary.json index 74fba43b..dbd5b1d6 100644 --- a/spec/fixtures/audience_summary.json +++ b/spec/fixtures/audience_summary.json @@ -2,7 +2,7 @@ "request": { "params": { "targeting_criteria": null, - "account_id": "18ce54d4x5t" + "account_id": "2iqph" } }, "data": {