twitter-ads 5.2.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/twitter-ads.rb +4 -1
  3. data/lib/twitter-ads/account.rb +9 -8
  4. data/lib/twitter-ads/campaign/campaign.rb +1 -2
  5. data/lib/twitter-ads/campaign/funding_instrument.rb +1 -2
  6. data/lib/twitter-ads/campaign/line_item.rb +2 -3
  7. data/lib/twitter-ads/campaign/organic_tweet.rb +1 -3
  8. data/lib/twitter-ads/campaign/targeting_criteria.rb +0 -1
  9. data/lib/twitter-ads/campaign/tweet.rb +4 -49
  10. data/lib/twitter-ads/client.rb +2 -2
  11. data/lib/twitter-ads/creative/account_media.rb +4 -6
  12. data/lib/twitter-ads/creative/draft_tweet.rb +40 -0
  13. data/lib/twitter-ads/creative/image_app_download_card.rb +2 -2
  14. data/lib/twitter-ads/creative/image_conversation_card.rb +3 -2
  15. data/lib/twitter-ads/creative/media_creative.rb +1 -2
  16. data/lib/twitter-ads/creative/media_library.rb +2 -4
  17. data/lib/twitter-ads/creative/promoted_account.rb +1 -2
  18. data/lib/twitter-ads/creative/promoted_tweet.rb +1 -2
  19. data/lib/twitter-ads/creative/scheduled_tweet.rb +1 -12
  20. data/lib/twitter-ads/creative/tweets.rb +52 -0
  21. data/lib/twitter-ads/creative/video_app_download_card.rb +4 -6
  22. data/lib/twitter-ads/creative/video_conversation_card.rb +6 -6
  23. data/lib/twitter-ads/creative/video_website_card.rb +3 -5
  24. data/lib/twitter-ads/creative/website_card.rb +2 -2
  25. data/lib/twitter-ads/cursor.rb +6 -0
  26. data/lib/twitter-ads/enum.rb +10 -5
  27. data/lib/twitter-ads/error.rb +5 -15
  28. data/lib/twitter-ads/http/request.rb +30 -1
  29. data/lib/twitter-ads/http/response.rb +1 -13
  30. data/lib/twitter-ads/resources/analytics.rb +99 -47
  31. data/lib/twitter-ads/resources/dsl.rb +8 -1
  32. data/lib/twitter-ads/restapi.rb +29 -0
  33. data/lib/twitter-ads/settings/tax.rb +13 -1
  34. data/lib/twitter-ads/targeting_criteria/conversation.rb +23 -0
  35. data/lib/twitter-ads/utils.rb +23 -0
  36. data/lib/twitter-ads/version.rb +1 -1
  37. data/spec/fixtures/tweet_previews.json +23 -0
  38. data/spec/twitter-ads/campaign/targeting_criteria_spec.rb +0 -1
  39. data/spec/twitter-ads/campaign/tweet_spec.rb +0 -59
  40. data/spec/twitter-ads/client_spec.rb +17 -1
  41. data/spec/twitter-ads/creative/tweet_previews_spec.rb +41 -0
  42. data/spec/twitter-ads/rate_limit_spec.rb +247 -0
  43. data/spec/twitter-ads/retry_count_spec.rb +61 -0
  44. metadata +14 -17
  45. data/lib/twitter-ads/audiences/audience_intelligence.rb +0 -68
  46. data/spec/fixtures/tweet_preview.json +0 -24
  47. data/spec/twitter-ads/creative/account_media_spec.rb +0 -32
  48. data/spec/twitter-ads/creative/image_app_download_card_spec.rb +0 -43
  49. data/spec/twitter-ads/creative/image_conversation_card_spec.rb +0 -40
  50. data/spec/twitter-ads/creative/video_app_download_card_spec.rb +0 -42
  51. data/spec/twitter-ads/creative/video_conversation_card_spec.rb +0 -51
  52. 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
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: 5.2.0
4
+ version: 6.0.0
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: 2019-06-19 00:00:00.000000000 Z
15
+ date: 2019-09-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: multi_json
@@ -57,7 +57,6 @@ 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
62
61
  - lib/twitter-ads/campaign/app_list.rb
63
62
  - lib/twitter-ads/campaign/campaign.rb
@@ -71,6 +70,7 @@ files:
71
70
  - lib/twitter-ads/client.rb
72
71
  - lib/twitter-ads/creative/account_media.rb
73
72
  - lib/twitter-ads/creative/cards_fetch.rb
73
+ - lib/twitter-ads/creative/draft_tweet.rb
74
74
  - lib/twitter-ads/creative/image_app_download_card.rb
75
75
  - lib/twitter-ads/creative/image_conversation_card.rb
76
76
  - lib/twitter-ads/creative/media_creative.rb
@@ -80,6 +80,7 @@ files:
80
80
  - lib/twitter-ads/creative/promoted_tweet.rb
81
81
  - lib/twitter-ads/creative/scheduled_tweet.rb
82
82
  - lib/twitter-ads/creative/tweet_previews.rb
83
+ - lib/twitter-ads/creative/tweets.rb
83
84
  - lib/twitter-ads/creative/video_app_download_card.rb
84
85
  - lib/twitter-ads/creative/video_conversation_card.rb
85
86
  - lib/twitter-ads/creative/video_website_card.rb
@@ -97,12 +98,14 @@ files:
97
98
  - lib/twitter-ads/resources/dsl.rb
98
99
  - lib/twitter-ads/resources/persistence.rb
99
100
  - lib/twitter-ads/resources/resource.rb
101
+ - lib/twitter-ads/restapi.rb
100
102
  - lib/twitter-ads/settings/tax.rb
101
103
  - lib/twitter-ads/settings/user.rb
102
104
  - lib/twitter-ads/targeting/reach_estimate.rb
103
105
  - lib/twitter-ads/targeting_criteria/app_store_category.rb
104
106
  - lib/twitter-ads/targeting_criteria/behavior.rb
105
107
  - 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
@@ -135,7 +138,7 @@ files:
135
138
  - spec/fixtures/reach_estimate.json
136
139
  - spec/fixtures/tailored_audiences_all.json
137
140
  - spec/fixtures/tailored_audiences_load.json
138
- - spec/fixtures/tweet_preview.json
141
+ - spec/fixtures/tweet_previews.json
139
142
  - spec/fixtures/videos_all.json
140
143
  - spec/fixtures/videos_load.json
141
144
  - spec/quality_spec.rb
@@ -150,17 +153,14 @@ files:
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/video_app_download_card_spec.rb
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
164
  - spec/twitter-ads/utils_spec.rb
165
165
  - twitter-ads.gemspec
166
166
  homepage: https://github.com/twitterdev/twitter-ruby-ads-sdk
@@ -188,37 +188,34 @@ specification_version: 4
188
188
  summary: The officially supported Twitter Ads API SDK for Ruby.
189
189
  test_files:
190
190
  - spec/spec_helper.rb
191
+ - spec/twitter-ads/retry_count_spec.rb
191
192
  - spec/twitter-ads/audiences/tailored_audience_spec.rb
192
193
  - spec/twitter-ads/cursor_spec.rb
193
194
  - spec/twitter-ads/account_spec.rb
194
195
  - spec/twitter-ads/client_spec.rb
196
+ - spec/twitter-ads/rate_limit_spec.rb
195
197
  - spec/twitter-ads/placements_spec.rb
196
198
  - spec/twitter-ads/campaign/targeting_criteria_spec.rb
197
199
  - spec/twitter-ads/campaign/app_list_spec.rb
198
200
  - spec/twitter-ads/campaign/reach_estimate_spec.rb
199
201
  - spec/twitter-ads/campaign/line_item_spec.rb
200
202
  - spec/twitter-ads/campaign/tweet_spec.rb
201
- - spec/twitter-ads/creative/account_media_spec.rb
202
- - spec/twitter-ads/creative/website_card_spec.rb
203
- - spec/twitter-ads/creative/video_app_download_card_spec.rb
203
+ - spec/twitter-ads/creative/tweet_previews_spec.rb
204
204
  - spec/twitter-ads/creative/media_creative_spec.rb
205
205
  - spec/twitter-ads/creative/promoted_tweet_spec.rb
206
- - spec/twitter-ads/creative/image_conversation_card_spec.rb
207
- - spec/twitter-ads/creative/video_conversation_card_spec.rb
208
206
  - spec/twitter-ads/creative/promoted_account_spec.rb
209
- - spec/twitter-ads/creative/image_app_download_card_spec.rb
210
207
  - spec/twitter-ads/utils_spec.rb
211
208
  - spec/shared/properties.rb
212
209
  - spec/support/helpers.rb
213
210
  - spec/fixtures/line_items_load.json
214
211
  - spec/fixtures/promotable_users_all.json
215
212
  - spec/fixtures/reach_estimate.json
216
- - spec/fixtures/tweet_preview.json
217
213
  - spec/fixtures/accounts_features.json
218
214
  - spec/fixtures/videos_all.json
219
215
  - spec/fixtures/line_items_all.json
220
216
  - spec/fixtures/placements.json
221
217
  - spec/fixtures/promotable_users_load.json
218
+ - spec/fixtures/tweet_previews.json
222
219
  - spec/fixtures/tailored_audiences_all.json
223
220
  - spec/fixtures/promoted_tweets_all.json
224
221
  - spec/fixtures/funding_instruments_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,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
- }
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (C) 2019 Twitter, Inc.
3
-
4
- require 'spec_helper'
5
-
6
- include TwitterAds::Enum
7
-
8
- describe TwitterAds::Creative::AccountMedia do
9
-
10
- before(:each) do
11
- stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
12
- stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
13
- end
14
-
15
- let(:client) do
16
- Client.new(
17
- Faker::Lorem.characters(15),
18
- Faker::Lorem.characters(40),
19
- "123456-#{Faker::Lorem.characters(40)}",
20
- Faker::Lorem.characters(40)
21
- )
22
- end
23
-
24
- let(:account) { client.accounts.first }
25
-
26
- # check model properties
27
- subject { described_class.new(account) }
28
- read = %w(id created_at updated_at deleted media_url)
29
- write = %w(media_id creative_type video_id)
30
- include_examples 'object property check', read, write
31
-
32
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (C) 2019 Twitter, Inc.
3
-
4
- require 'spec_helper'
5
-
6
- describe TwitterAds::Creative::ImageAppDownloadCard do
7
-
8
- before(:each) do
9
- stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
10
- stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
11
- end
12
-
13
- let(:client) do
14
- Client.new(
15
- Faker::Lorem.characters(15),
16
- Faker::Lorem.characters(40),
17
- "123456-#{Faker::Lorem.characters(40)}",
18
- Faker::Lorem.characters(40)
19
- )
20
- end
21
-
22
- let(:account) { client.accounts.first }
23
-
24
- # check model properties
25
- subject { described_class.new(account) }
26
- read = %w(id created_at updated_at deleted)
27
-
28
- write = %w(
29
- name
30
- country_code
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
42
-
43
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (C) 2019 Twitter, Inc.
3
-
4
- require 'spec_helper'
5
-
6
- describe TwitterAds::Creative::ImageConversationCard do
7
-
8
- before(:each) do
9
- stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
10
- stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
11
- end
12
-
13
- let(:client) do
14
- Client.new(
15
- Faker::Lorem.characters(15),
16
- Faker::Lorem.characters(40),
17
- "123456-#{Faker::Lorem.characters(40)}",
18
- Faker::Lorem.characters(40)
19
- )
20
- end
21
-
22
- let(:account) { client.accounts.first }
23
-
24
- # check model properties
25
- subject { described_class.new(account) }
26
- read = %w(id image deleted created_at updated_at)
27
- write = %w(
28
- name
29
- title
30
- first_cta
31
- first_cta_tweet
32
- second_cta
33
- second_cta_tweet
34
- thank_you_text
35
- thank_you_url
36
- image_media_id
37
- )
38
- include_examples 'object property check', read, write
39
-
40
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (C) 2019 Twitter, Inc.
3
-
4
- require 'spec_helper'
5
-
6
- describe TwitterAds::Creative::VideoAppDownloadCard do
7
-
8
- before(:each) do
9
- stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
10
- stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
11
- end
12
-
13
- let(:client) do
14
- Client.new(
15
- Faker::Lorem.characters(15),
16
- Faker::Lorem.characters(40),
17
- "123456-#{Faker::Lorem.characters(40)}",
18
- Faker::Lorem.characters(40)
19
- )
20
- end
21
-
22
- let(:account) { client.accounts.first }
23
-
24
- # check model properties
25
- subject { described_class.new(account) }
26
- read = %w(id video_url video_poster_url deleted created_at updated_at)
27
- write = %w(
28
- name
29
- country_code
30
- iphone_app_id
31
- iphone_deep_link
32
- ipad_app_id
33
- ipad_deep_link
34
- googleplay_app_id
35
- googleplay_deep_link
36
- app_cta
37
- image_media_id
38
- video_id
39
- )
40
- include_examples 'object property check', read, write
41
-
42
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (C) 2019 Twitter, Inc.
3
-
4
- require 'spec_helper'
5
-
6
- describe TwitterAds::Creative::VideoConversationCard do
7
-
8
- before(:each) do
9
- stub_fixture(:get, :accounts_all, "#{ADS_API}/accounts")
10
- stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph")
11
- end
12
-
13
- let(:client) do
14
- Client.new(
15
- Faker::Lorem.characters(15),
16
- Faker::Lorem.characters(40),
17
- "123456-#{Faker::Lorem.characters(40)}",
18
- Faker::Lorem.characters(40)
19
- )
20
- end
21
-
22
- let(:account) { client.accounts.first }
23
-
24
- # check model properties
25
- subject { described_class.new(account) }
26
-
27
- read = %w(
28
- id
29
- video_url
30
- video_poster_url
31
- deleted
32
- created_at
33
- updated_at
34
- )
35
-
36
- write = %w(
37
- name
38
- title
39
- first_cta
40
- first_cta_tweet
41
- second_cta
42
- second_cta_tweet
43
- thank_you_text
44
- thank_you_url
45
- image_media_id
46
- video_id
47
- )
48
-
49
- include_examples 'object property check', read, write
50
-
51
- end