twitter-ads 5.1.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -2
- data/README.md +1 -1
- data/lib/twitter-ads.rb +8 -4
- data/lib/twitter-ads/account.rb +6 -25
- data/lib/twitter-ads/audiences/tailored_audience.rb +98 -3
- data/lib/twitter-ads/{targeting_criteria/behavior_taxonomy.rb → campaign/advertiser_business_categories.rb} +6 -6
- data/lib/twitter-ads/campaign/campaign.rb +1 -2
- data/lib/twitter-ads/campaign/content_categories.rb +23 -0
- data/lib/twitter-ads/campaign/funding_instrument.rb +1 -2
- data/lib/twitter-ads/campaign/line_item.rb +4 -4
- data/lib/twitter-ads/campaign/organic_tweet.rb +1 -3
- data/lib/twitter-ads/campaign/targeting_criteria.rb +0 -1
- data/lib/twitter-ads/campaign/tweet.rb +4 -49
- data/lib/twitter-ads/client.rb +2 -2
- data/lib/twitter-ads/creative/account_media.rb +4 -6
- data/lib/twitter-ads/creative/draft_tweet.rb +40 -0
- data/lib/twitter-ads/creative/image_app_download_card.rb +2 -2
- data/lib/twitter-ads/creative/image_conversation_card.rb +3 -2
- data/lib/twitter-ads/creative/media_creative.rb +2 -3
- data/lib/twitter-ads/creative/media_library.rb +12 -13
- data/lib/twitter-ads/creative/promoted_account.rb +1 -2
- data/lib/twitter-ads/creative/promoted_tweet.rb +1 -2
- data/lib/twitter-ads/creative/scheduled_tweet.rb +1 -12
- data/lib/twitter-ads/creative/tweets.rb +52 -0
- data/lib/twitter-ads/creative/video_app_download_card.rb +4 -6
- data/lib/twitter-ads/creative/video_conversation_card.rb +6 -6
- data/lib/twitter-ads/creative/video_website_card.rb +3 -5
- data/lib/twitter-ads/creative/website_card.rb +2 -2
- data/lib/twitter-ads/cursor.rb +6 -0
- data/lib/twitter-ads/enum.rb +19 -9
- data/lib/twitter-ads/error.rb +5 -15
- data/lib/twitter-ads/http/request.rb +37 -2
- data/lib/twitter-ads/http/response.rb +1 -13
- data/lib/twitter-ads/resources/analytics.rb +99 -47
- data/lib/twitter-ads/resources/dsl.rb +8 -1
- data/lib/twitter-ads/restapi.rb +29 -0
- data/lib/twitter-ads/settings/tax.rb +13 -1
- data/lib/twitter-ads/targeting/audience_summary.rb +47 -0
- data/lib/twitter-ads/targeting_criteria/{behavior.rb → conversation.rb} +3 -7
- data/lib/twitter-ads/utils.rb +23 -0
- data/lib/twitter-ads/version.rb +1 -1
- data/spec/fixtures/audience_summary.json +14 -0
- data/spec/fixtures/line_items_all.json +2 -10
- data/spec/fixtures/line_items_load.json +0 -1
- data/spec/fixtures/tweet_previews.json +23 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/twitter-ads/campaign/line_item_spec.rb +0 -1
- data/spec/twitter-ads/campaign/targeting_criteria_spec.rb +0 -1
- data/spec/twitter-ads/campaign/tweet_spec.rb +0 -59
- data/spec/twitter-ads/client_spec.rb +17 -1
- data/spec/twitter-ads/creative/media_creative_spec.rb +1 -1
- data/spec/twitter-ads/creative/tweet_previews_spec.rb +41 -0
- data/spec/twitter-ads/rate_limit_spec.rb +247 -0
- data/spec/twitter-ads/retry_count_spec.rb +61 -0
- data/spec/twitter-ads/{creative/image_app_download_card_spec.rb → targeting/audience_summary_spec.rb} +16 -18
- metadata +46 -47
- data/lib/twitter-ads/audiences/audience_intelligence.rb +0 -68
- data/lib/twitter-ads/targeting/reach_estimate.rb +0 -78
- data/spec/fixtures/tweet_preview.json +0 -24
- data/spec/twitter-ads/campaign/reach_estimate_spec.rb +0 -103
- data/spec/twitter-ads/creative/account_media_spec.rb +0 -32
- data/spec/twitter-ads/creative/image_conversation_card_spec.rb +0 -40
- data/spec/twitter-ads/creative/video_app_download_card_spec.rb +0 -42
- data/spec/twitter-ads/creative/video_conversation_card_spec.rb +0 -51
- data/spec/twitter-ads/creative/website_card_spec.rb +0 -42
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright (C) 2019 Twitter, Inc.
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe TwitterAds::Campaign do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow_any_instance_of(Object).to receive(:sleep)
|
10
|
+
stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:client) do
|
14
|
+
Client.new(
|
15
|
+
Faker::Lorem.characters(40),
|
16
|
+
Faker::Lorem.characters(40),
|
17
|
+
Faker::Lorem.characters(40),
|
18
|
+
Faker::Lorem.characters(40),
|
19
|
+
options: {
|
20
|
+
retry_max: 1,
|
21
|
+
retry_delay: 3000,
|
22
|
+
retry_on_status: [404, 500, 503]
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
let(:account) { client.accounts('2iqph') }
|
27
|
+
|
28
|
+
it 'test retry count - success' do
|
29
|
+
stub = stub_request(:get, "#{ADS_API}/accounts/2iqph/campaigns").to_return(
|
30
|
+
{
|
31
|
+
body: fixture(:campaigns_all),
|
32
|
+
status: 404
|
33
|
+
},
|
34
|
+
{
|
35
|
+
body: fixture(:campaigns_all),
|
36
|
+
status: 200
|
37
|
+
}
|
38
|
+
)
|
39
|
+
cusor = described_class.all(account)
|
40
|
+
expect(cusor).to be_instance_of(Cursor)
|
41
|
+
expect(stub).to have_been_requested.times(2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'test retry count - fail' do
|
45
|
+
stub = stub_request(:get, "#{ADS_API}/accounts/2iqph/campaigns").to_return(
|
46
|
+
{
|
47
|
+
body: fixture(:campaigns_all),
|
48
|
+
status: 404
|
49
|
+
}
|
50
|
+
).times(2)
|
51
|
+
|
52
|
+
begin
|
53
|
+
cusor = described_class.all(account)
|
54
|
+
rescue NotFound => e
|
55
|
+
cusor = e
|
56
|
+
end
|
57
|
+
expect(cusor).to be_instance_of(NotFound)
|
58
|
+
expect(stub).to have_been_requested.times(2)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -3,11 +3,12 @@
|
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
|
-
describe TwitterAds::
|
6
|
+
describe TwitterAds::AudienceSummary do
|
7
7
|
|
8
8
|
before(:each) do
|
9
9
|
stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
|
10
10
|
stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
|
11
|
+
stub_fixture(:post, :audience_summary, "#{ADS_API}/accounts/2iqph/audience_summary")
|
11
12
|
end
|
12
13
|
|
13
14
|
let(:client) do
|
@@ -20,24 +21,21 @@ describe TwitterAds::Creative::ImageAppDownloadCard do
|
|
20
21
|
end
|
21
22
|
|
22
23
|
let(:account) { client.accounts.first }
|
24
|
+
let(:params) {
|
25
|
+
{
|
26
|
+
targeting_criteria: [{
|
27
|
+
targeting_type: 'LOCATION',
|
28
|
+
targeting_value: '96683cc9126741d1'
|
29
|
+
}]
|
30
|
+
}
|
31
|
+
}
|
23
32
|
|
24
33
|
# check model properties
|
25
|
-
subject { described_class.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
iphone_app_id
|
32
|
-
iphone_deep_link
|
33
|
-
ipad_app_id
|
34
|
-
ipad_deep_link
|
35
|
-
googleplay_app_id
|
36
|
-
googleplay_deep_link
|
37
|
-
app_cta
|
38
|
-
wide_app_image_media_id
|
39
|
-
)
|
40
|
-
|
41
|
-
include_examples 'object property check', read, write
|
34
|
+
subject { described_class.fetch(account, params) }
|
35
|
+
|
36
|
+
it 'has all the correct properties' do
|
37
|
+
expect(subject[:audience_size][:min]).to eq(41133600)
|
38
|
+
expect(subject[:audience_size][:max]).to eq(50274400)
|
39
|
+
end
|
42
40
|
|
43
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-ads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Babich
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: multi_json
|
@@ -57,10 +57,11 @@ files:
|
|
57
57
|
- bin/twitter-ads
|
58
58
|
- lib/twitter-ads.rb
|
59
59
|
- lib/twitter-ads/account.rb
|
60
|
-
- lib/twitter-ads/audiences/audience_intelligence.rb
|
61
60
|
- lib/twitter-ads/audiences/tailored_audience.rb
|
61
|
+
- lib/twitter-ads/campaign/advertiser_business_categories.rb
|
62
62
|
- lib/twitter-ads/campaign/app_list.rb
|
63
63
|
- lib/twitter-ads/campaign/campaign.rb
|
64
|
+
- lib/twitter-ads/campaign/content_categories.rb
|
64
65
|
- lib/twitter-ads/campaign/funding_instrument.rb
|
65
66
|
- lib/twitter-ads/campaign/iab_category.rb
|
66
67
|
- lib/twitter-ads/campaign/line_item.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- lib/twitter-ads/client.rb
|
72
73
|
- lib/twitter-ads/creative/account_media.rb
|
73
74
|
- lib/twitter-ads/creative/cards_fetch.rb
|
75
|
+
- lib/twitter-ads/creative/draft_tweet.rb
|
74
76
|
- lib/twitter-ads/creative/image_app_download_card.rb
|
75
77
|
- lib/twitter-ads/creative/image_conversation_card.rb
|
76
78
|
- lib/twitter-ads/creative/media_creative.rb
|
@@ -80,6 +82,7 @@ files:
|
|
80
82
|
- lib/twitter-ads/creative/promoted_tweet.rb
|
81
83
|
- lib/twitter-ads/creative/scheduled_tweet.rb
|
82
84
|
- lib/twitter-ads/creative/tweet_previews.rb
|
85
|
+
- lib/twitter-ads/creative/tweets.rb
|
83
86
|
- lib/twitter-ads/creative/video_app_download_card.rb
|
84
87
|
- lib/twitter-ads/creative/video_conversation_card.rb
|
85
88
|
- lib/twitter-ads/creative/video_website_card.rb
|
@@ -97,12 +100,12 @@ files:
|
|
97
100
|
- lib/twitter-ads/resources/dsl.rb
|
98
101
|
- lib/twitter-ads/resources/persistence.rb
|
99
102
|
- lib/twitter-ads/resources/resource.rb
|
103
|
+
- lib/twitter-ads/restapi.rb
|
100
104
|
- lib/twitter-ads/settings/tax.rb
|
101
105
|
- lib/twitter-ads/settings/user.rb
|
102
|
-
- lib/twitter-ads/targeting/
|
106
|
+
- lib/twitter-ads/targeting/audience_summary.rb
|
103
107
|
- lib/twitter-ads/targeting_criteria/app_store_category.rb
|
104
|
-
- lib/twitter-ads/targeting_criteria/
|
105
|
-
- lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb
|
108
|
+
- lib/twitter-ads/targeting_criteria/conversation.rb
|
106
109
|
- lib/twitter-ads/targeting_criteria/device.rb
|
107
110
|
- lib/twitter-ads/targeting_criteria/event.rb
|
108
111
|
- lib/twitter-ads/targeting_criteria/interest.rb
|
@@ -120,6 +123,7 @@ files:
|
|
120
123
|
- spec/fixtures/accounts_load.json
|
121
124
|
- spec/fixtures/app_lists_all.json
|
122
125
|
- spec/fixtures/app_lists_load.json
|
126
|
+
- spec/fixtures/audience_summary.json
|
123
127
|
- spec/fixtures/campaigns_all.json
|
124
128
|
- spec/fixtures/campaigns_load.json
|
125
129
|
- spec/fixtures/funding_instruments_all.json
|
@@ -135,7 +139,7 @@ files:
|
|
135
139
|
- spec/fixtures/reach_estimate.json
|
136
140
|
- spec/fixtures/tailored_audiences_all.json
|
137
141
|
- spec/fixtures/tailored_audiences_load.json
|
138
|
-
- spec/fixtures/
|
142
|
+
- spec/fixtures/tweet_previews.json
|
139
143
|
- spec/fixtures/videos_all.json
|
140
144
|
- spec/fixtures/videos_load.json
|
141
145
|
- spec/quality_spec.rb
|
@@ -146,21 +150,18 @@ files:
|
|
146
150
|
- spec/twitter-ads/audiences/tailored_audience_spec.rb
|
147
151
|
- spec/twitter-ads/campaign/app_list_spec.rb
|
148
152
|
- spec/twitter-ads/campaign/line_item_spec.rb
|
149
|
-
- spec/twitter-ads/campaign/reach_estimate_spec.rb
|
150
153
|
- spec/twitter-ads/campaign/targeting_criteria_spec.rb
|
151
154
|
- spec/twitter-ads/campaign/tweet_spec.rb
|
152
155
|
- spec/twitter-ads/client_spec.rb
|
153
|
-
- spec/twitter-ads/creative/account_media_spec.rb
|
154
|
-
- spec/twitter-ads/creative/image_app_download_card_spec.rb
|
155
|
-
- spec/twitter-ads/creative/image_conversation_card_spec.rb
|
156
156
|
- spec/twitter-ads/creative/media_creative_spec.rb
|
157
157
|
- spec/twitter-ads/creative/promoted_account_spec.rb
|
158
158
|
- spec/twitter-ads/creative/promoted_tweet_spec.rb
|
159
|
-
- spec/twitter-ads/creative/
|
160
|
-
- spec/twitter-ads/creative/video_conversation_card_spec.rb
|
161
|
-
- spec/twitter-ads/creative/website_card_spec.rb
|
159
|
+
- spec/twitter-ads/creative/tweet_previews_spec.rb
|
162
160
|
- spec/twitter-ads/cursor_spec.rb
|
163
161
|
- spec/twitter-ads/placements_spec.rb
|
162
|
+
- spec/twitter-ads/rate_limit_spec.rb
|
163
|
+
- spec/twitter-ads/retry_count_spec.rb
|
164
|
+
- spec/twitter-ads/targeting/audience_summary_spec.rb
|
164
165
|
- spec/twitter-ads/utils_spec.rb
|
165
166
|
- twitter-ads.gemspec
|
166
167
|
homepage: https://github.com/twitterdev/twitter-ruby-ads-sdk
|
@@ -187,50 +188,48 @@ signing_key:
|
|
187
188
|
specification_version: 4
|
188
189
|
summary: The officially supported Twitter Ads API SDK for Ruby.
|
189
190
|
test_files:
|
190
|
-
- spec/
|
191
|
-
- spec/
|
191
|
+
- spec/support/helpers.rb
|
192
|
+
- spec/quality_spec.rb
|
193
|
+
- spec/shared/properties.rb
|
192
194
|
- spec/twitter-ads/cursor_spec.rb
|
193
|
-
- spec/twitter-ads/
|
194
|
-
- spec/twitter-ads/
|
195
|
-
- spec/twitter-ads/
|
196
|
-
- spec/twitter-ads/campaign/targeting_criteria_spec.rb
|
197
|
-
- spec/twitter-ads/campaign/app_list_spec.rb
|
198
|
-
- spec/twitter-ads/campaign/reach_estimate_spec.rb
|
195
|
+
- spec/twitter-ads/rate_limit_spec.rb
|
196
|
+
- spec/twitter-ads/audiences/tailored_audience_spec.rb
|
197
|
+
- spec/twitter-ads/targeting/audience_summary_spec.rb
|
199
198
|
- spec/twitter-ads/campaign/line_item_spec.rb
|
199
|
+
- spec/twitter-ads/campaign/targeting_criteria_spec.rb
|
200
200
|
- spec/twitter-ads/campaign/tweet_spec.rb
|
201
|
-
- spec/twitter-ads/
|
202
|
-
- spec/twitter-ads/creative/website_card_spec.rb
|
203
|
-
- spec/twitter-ads/creative/video_app_download_card_spec.rb
|
204
|
-
- spec/twitter-ads/creative/media_creative_spec.rb
|
201
|
+
- spec/twitter-ads/campaign/app_list_spec.rb
|
205
202
|
- spec/twitter-ads/creative/promoted_tweet_spec.rb
|
206
|
-
- spec/twitter-ads/creative/
|
207
|
-
- spec/twitter-ads/creative/
|
203
|
+
- spec/twitter-ads/creative/tweet_previews_spec.rb
|
204
|
+
- spec/twitter-ads/creative/media_creative_spec.rb
|
208
205
|
- spec/twitter-ads/creative/promoted_account_spec.rb
|
209
|
-
- spec/twitter-ads/
|
206
|
+
- spec/twitter-ads/account_spec.rb
|
210
207
|
- spec/twitter-ads/utils_spec.rb
|
211
|
-
- spec/
|
212
|
-
- spec/
|
213
|
-
- spec/
|
214
|
-
- spec/
|
215
|
-
- spec/fixtures/
|
216
|
-
- spec/fixtures/
|
217
|
-
- spec/fixtures/
|
208
|
+
- spec/twitter-ads/client_spec.rb
|
209
|
+
- spec/twitter-ads/placements_spec.rb
|
210
|
+
- spec/twitter-ads/retry_count_spec.rb
|
211
|
+
- spec/spec_helper.rb
|
212
|
+
- spec/fixtures/promoted_tweets_all.json
|
213
|
+
- spec/fixtures/campaigns_load.json
|
214
|
+
- spec/fixtures/promoted_tweets_load.json
|
218
215
|
- spec/fixtures/videos_all.json
|
216
|
+
- spec/fixtures/accounts_load.json
|
219
217
|
- spec/fixtures/line_items_all.json
|
220
|
-
- spec/fixtures/
|
221
|
-
- spec/fixtures/
|
222
|
-
- spec/fixtures/tailored_audiences_all.json
|
223
|
-
- spec/fixtures/promoted_tweets_all.json
|
218
|
+
- spec/fixtures/accounts_features.json
|
219
|
+
- spec/fixtures/line_items_load.json
|
224
220
|
- spec/fixtures/funding_instruments_load.json
|
221
|
+
- spec/fixtures/videos_load.json
|
222
|
+
- spec/fixtures/funding_instruments_all.json
|
223
|
+
- spec/fixtures/tweet_previews.json
|
225
224
|
- spec/fixtures/tailored_audiences_load.json
|
225
|
+
- spec/fixtures/placements.json
|
226
|
+
- spec/fixtures/tailored_audiences_all.json
|
227
|
+
- spec/fixtures/reach_estimate.json
|
226
228
|
- spec/fixtures/app_lists_load.json
|
227
|
-
- spec/fixtures/
|
228
|
-
- spec/fixtures/
|
229
|
-
- spec/fixtures/campaigns_load.json
|
229
|
+
- spec/fixtures/audience_summary.json
|
230
|
+
- spec/fixtures/campaigns_all.json
|
230
231
|
- spec/fixtures/app_lists_all.json
|
231
|
-
- spec/fixtures/
|
232
|
+
- spec/fixtures/promotable_users_all.json
|
232
233
|
- spec/fixtures/no_content.json
|
233
|
-
- spec/fixtures/campaigns_all.json
|
234
234
|
- spec/fixtures/accounts_all.json
|
235
|
-
- spec/fixtures/
|
236
|
-
- spec/quality_spec.rb
|
235
|
+
- spec/fixtures/promotable_users_load.json
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright (C) 2019 Twitter, Inc.
|
3
|
-
|
4
|
-
module TwitterAds
|
5
|
-
class AudienceIntelligence
|
6
|
-
|
7
|
-
include TwitterAds::DSL
|
8
|
-
include TwitterAds::Resource::InstanceMethods
|
9
|
-
|
10
|
-
attr_reader :account
|
11
|
-
|
12
|
-
# writable
|
13
|
-
property :conversation_type
|
14
|
-
property :targeting_inputs
|
15
|
-
property :audience_definition
|
16
|
-
|
17
|
-
# demographics-only
|
18
|
-
property :start_time, type: :time
|
19
|
-
property :end_time, type: :time
|
20
|
-
|
21
|
-
# read
|
22
|
-
property :operator_type, read_only: true
|
23
|
-
property :targeting_type, read_only: true
|
24
|
-
property :targeting_value, read_only: true
|
25
|
-
property :localized, read_only: true
|
26
|
-
|
27
|
-
RESOURCE_CONVERSATIONS = "/#{TwitterAds::API_VERSION}/" \
|
28
|
-
'accounts/%{account_id}/audience_intelligence/' \
|
29
|
-
'conversations' # @api private
|
30
|
-
RESOURCE_DEMOGRAPHICS = "/#{TwitterAds::API_VERSION}/" \
|
31
|
-
'accounts/%{account_id}/audience_intelligence/' \
|
32
|
-
'demographics' # @api private
|
33
|
-
|
34
|
-
def initialize(account)
|
35
|
-
@account = account
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
def conversations
|
40
|
-
headers = { 'Content-Type' => 'application/json' }
|
41
|
-
params = {
|
42
|
-
conversation_type: conversation_type,
|
43
|
-
audience_definition: audience_definition,
|
44
|
-
targeting_inputs: targeting_inputs
|
45
|
-
}
|
46
|
-
resource = RESOURCE_CONVERSATIONS % { account_id: account.id }
|
47
|
-
request = Request.new(account.client, :post, resource, body: params.to_json, headers: headers)
|
48
|
-
Cursor.new(self.class, request, init_with: [account])
|
49
|
-
end
|
50
|
-
|
51
|
-
def demographics
|
52
|
-
headers = { 'Content-Type' => 'application/json' }
|
53
|
-
params = {
|
54
|
-
audience_definition: audience_definition,
|
55
|
-
targeting_inputs: targeting_inputs
|
56
|
-
}
|
57
|
-
resource = RESOURCE_DEMOGRAPHICS % { account_id: account.id }
|
58
|
-
response = Request.new(
|
59
|
-
account.client,
|
60
|
-
:post,
|
61
|
-
resource,
|
62
|
-
body: params.to_json,
|
63
|
-
headers: headers).perform
|
64
|
-
response.body[:data]
|
65
|
-
# cannot use cursor here given that the response "keys" are dynmaic based on input values
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright (C) 2019 Twitter, Inc.
|
3
|
-
|
4
|
-
module TwitterAds
|
5
|
-
module ReachEstimate
|
6
|
-
|
7
|
-
class << self
|
8
|
-
|
9
|
-
# Get a reach estimate for the specified line item details.
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
# TwitterAds::ReachEstimate.fetch(
|
13
|
-
# account,
|
14
|
-
# 'PROMOTED_TWEETS',
|
15
|
-
# 'WEBSITE_CLICKS',
|
16
|
-
# 5500000,
|
17
|
-
# 30000000,
|
18
|
-
# similar_to_followers_of_user: 2153688540,
|
19
|
-
# gender: 2
|
20
|
-
# )
|
21
|
-
#
|
22
|
-
# @param client [Client] The Client object instance.
|
23
|
-
# @param product_type [String] The product type being targeted.
|
24
|
-
# @param objective [String] The objective being targeted.
|
25
|
-
# @param campaign_daily_budget_amount_local_micro [Long] Daily budget in micros.
|
26
|
-
# @param opts [Hash] A Hash of extended options.
|
27
|
-
#
|
28
|
-
# @option opts [Long] :bid_amount_local_micro Bid amount in local currency micros.
|
29
|
-
# @option opts [String] :bid_type The bidding mechanism.
|
30
|
-
# @option opts [String] :currency ISO-4217 Currency code for bid amount.
|
31
|
-
# @option opts [String] :followers_of_users Comma-separated user IDs.
|
32
|
-
# @option opts [String] :similar_to_followers_of_users Comma-separated user IDs.
|
33
|
-
# @option opts [String] :locations Comma-separated location IDs.
|
34
|
-
# @option opts [String] :interests Comma-seaprated interest IDs.
|
35
|
-
# @option opts [String] :gender Gender identifier.
|
36
|
-
# @option opts [String] :platforms Comma-separated platform IDs.
|
37
|
-
# @option opts [String] :tailored_audiences Comma-separated tailored audience IDs.
|
38
|
-
# @option opts [String] :tailored_audiences_expanded Comma-separated tailoerd audience IDs.
|
39
|
-
# @option opts [String] :languages Comma-separated language IDs.
|
40
|
-
# @option opts [String] :platform_versions Comma-separated platform version IDs.
|
41
|
-
# @option opts [String] :devices Comma-separated device IDs.
|
42
|
-
# @option opts [String] :behaviors Comma-separated behavior IDs.
|
43
|
-
# @option opts [String] :behaviors_expanded Comma-separated behaviors IDs.
|
44
|
-
# @option opts [String] :campaign engagement Campaign ID for Tweet Engager Retargeting.
|
45
|
-
# @option opts [String] :user_engagement Promoted User ID for Tweet Engager Retargeting.
|
46
|
-
# @option opts [String] :engagement_type engagement type for Tweet Engager Retargeting.
|
47
|
-
# @option opts [String] :network_operators Network operators to target
|
48
|
-
# @option opts [String] :app_store_categories App store categories to target.
|
49
|
-
# @option opts [String] :app_store_categories_expanded App store categories with lookalikes.
|
50
|
-
#
|
51
|
-
# @return [Hash] A hash containing count and infinite_bid_count.
|
52
|
-
#
|
53
|
-
# @since 1.0.0
|
54
|
-
# @see https://developer.twitter.com/en/docs/ads/campaign-management/api-reference/reach-estimate
|
55
|
-
def fetch(account, product_type, objective, campaign_daily_budget,
|
56
|
-
opts = {})
|
57
|
-
resource = "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/reach_estimate"
|
58
|
-
params = {
|
59
|
-
product_type: product_type,
|
60
|
-
objective: objective,
|
61
|
-
campaign_daily_budget_amount_local_micro: campaign_daily_budget
|
62
|
-
}.merge!(opts)
|
63
|
-
|
64
|
-
# The response value count is "bid sensitive", we default to bid_type=AUTO here to preserve
|
65
|
-
# expected behavior despite an API change that occurred in December 2015.
|
66
|
-
unless params.keys.include?(:bid_type) || params.keys.include?(:bid_amount_local_micro)
|
67
|
-
params = { bid_type: 'AUTO' }.merge!(params)
|
68
|
-
end
|
69
|
-
|
70
|
-
response = TwitterAds::Request.new(account.client, :get,
|
71
|
-
resource, params: params).perform
|
72
|
-
response.body[:data]
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"data_type": "tweet_preview",
|
3
|
-
"data": [
|
4
|
-
{
|
5
|
-
"platform": "web",
|
6
|
-
"preview": " <div><img><div><div><div><a>AdsAPI</a><a>@AdsAPI</a></div></div><div>Hello World!</div><div><div><img><div><div></div><div><span> Ratings/pricing not available for preview </span><span> Ratings/pricing not available for preview </span></div><div></div> INSTALL </div></div></div><a><img></a><div><div><span></span><span>Promoted by AdsAPI</span></div></div></div></div>"
|
7
|
-
},
|
8
|
-
{
|
9
|
-
"platform": "android",
|
10
|
-
"preview": " <div><img><div><div><div><a>AdsAPI</a><a>@AdsAPI</a></div></div><div>Hello World!</div><div><div><img><div><div></div><div><span> Ratings/pricing not available for preview </span><span> Ratings/pricing not available for preview </span></div><div></div> INSTALL </div></div></div><a><img></a><div><div><span></span><span>Promoted by AdsAPI</span></div></div></div></div>"
|
11
|
-
},
|
12
|
-
{
|
13
|
-
"platform": "iphone",
|
14
|
-
"preview": " <div><img><div><div><div><a>AdsAPI</a><a>@AdsAPI</a></div></div><div>Hello World!</div><div><div><img><div><div></div><div><span> Ratings/pricing not available for preview </span><span> Ratings/pricing not available for preview </span></div><div></div> INSTALL </div></div></div><a><img></a><div><div><span></span><span>Promoted by AdsAPI</span></div></div></div></div>"
|
15
|
-
}
|
16
|
-
],
|
17
|
-
"request": {
|
18
|
-
"params": {
|
19
|
-
"status": "Hello World!",
|
20
|
-
"card_id": "pfs",
|
21
|
-
"account_id": "2iqph"
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|