twitter-ads 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -1
  3. data.tar.gz.sig +0 -0
  4. data/bin/twitter-ads +3 -0
  5. data/lib/twitter-ads.rb +2 -4
  6. data/lib/twitter-ads/account.rb +25 -5
  7. data/lib/twitter-ads/audiences/tailored_audience.rb +47 -5
  8. data/lib/twitter-ads/campaign/app_list.rb +4 -2
  9. data/lib/twitter-ads/campaign/campaign.rb +11 -6
  10. data/lib/twitter-ads/campaign/funding_instrument.rb +4 -2
  11. data/lib/twitter-ads/campaign/iab_category.rb +1 -1
  12. data/lib/twitter-ads/campaign/line_item.rb +13 -7
  13. data/lib/twitter-ads/campaign/organic_tweet.rb +4 -1
  14. data/lib/twitter-ads/campaign/promotable_user.rb +4 -2
  15. data/lib/twitter-ads/campaign/targeting_criteria.rb +6 -3
  16. data/lib/twitter-ads/campaign/tweet.rb +16 -12
  17. data/lib/twitter-ads/client.rb +2 -0
  18. data/lib/twitter-ads/creative/account_media.rb +8 -6
  19. data/lib/twitter-ads/creative/image_app_download_card.rb +15 -9
  20. data/lib/twitter-ads/creative/image_conversation_card.rb +17 -9
  21. data/lib/twitter-ads/creative/media_creative.rb +9 -7
  22. data/lib/twitter-ads/creative/promoted_account.rb +8 -4
  23. data/lib/twitter-ads/creative/promoted_tweet.rb +10 -8
  24. data/lib/twitter-ads/creative/scheduled_tweet.rb +57 -0
  25. data/lib/twitter-ads/creative/video.rb +14 -8
  26. data/lib/twitter-ads/creative/video_app_download_card.rb +18 -12
  27. data/lib/twitter-ads/creative/video_conversation_card.rb +18 -9
  28. data/lib/twitter-ads/creative/video_website_card.rb +53 -0
  29. data/lib/twitter-ads/creative/website_card.rb +14 -16
  30. data/lib/twitter-ads/enum.rb +32 -13
  31. data/lib/twitter-ads/http/request.rb +2 -2
  32. data/lib/twitter-ads/http/ton_upload.rb +33 -17
  33. data/lib/twitter-ads/measurement/app_event_tag.rb +2 -1
  34. data/lib/twitter-ads/measurement/web_event_tag.rb +2 -1
  35. data/lib/twitter-ads/resources/analytics.rb +13 -8
  36. data/lib/twitter-ads/targeting/reach_estimate.rb +2 -2
  37. data/lib/twitter-ads/targeting_criteria/app_store_category.rb +2 -1
  38. data/lib/twitter-ads/targeting_criteria/behavior.rb +2 -1
  39. data/lib/twitter-ads/targeting_criteria/behavior_taxonomy.rb +2 -1
  40. data/lib/twitter-ads/targeting_criteria/device.rb +2 -1
  41. data/lib/twitter-ads/targeting_criteria/event.rb +2 -1
  42. data/lib/twitter-ads/targeting_criteria/interest.rb +2 -1
  43. data/lib/twitter-ads/targeting_criteria/language.rb +2 -1
  44. data/lib/twitter-ads/targeting_criteria/location.rb +2 -1
  45. data/lib/twitter-ads/targeting_criteria/network_operator.rb +2 -1
  46. data/lib/twitter-ads/targeting_criteria/platform.rb +2 -1
  47. data/lib/twitter-ads/targeting_criteria/platform_version.rb +2 -1
  48. data/lib/twitter-ads/targeting_criteria/tv_market.rb +2 -1
  49. data/lib/twitter-ads/targeting_criteria/tv_show.rb +2 -1
  50. data/lib/twitter-ads/utils.rb +3 -3
  51. data/lib/twitter-ads/version.rb +1 -1
  52. data/spec/fixtures/campaigns_all.json +10 -10
  53. data/spec/fixtures/line_items_all.json +10 -10
  54. data/spec/fixtures/line_items_load.json +1 -1
  55. data/spec/fixtures/no_content.json +0 -0
  56. data/spec/fixtures/promoted_tweets_all.json +20 -20
  57. data/spec/fixtures/promoted_tweets_load.json +1 -1
  58. data/spec/spec_helper.rb +1 -1
  59. data/spec/support/helpers.rb +2 -2
  60. data/spec/twitter-ads/campaign/app_list_spec.rb +1 -1
  61. data/spec/twitter-ads/campaign/line_item_spec.rb +1 -1
  62. data/spec/twitter-ads/campaign/reach_estimate_spec.rb +1 -1
  63. data/spec/twitter-ads/campaign/tweet_spec.rb +7 -7
  64. data/spec/twitter-ads/client_spec.rb +2 -1
  65. data/spec/twitter-ads/creative/promoted_tweet_spec.rb +2 -2
  66. data/spec/twitter-ads/creative/website_card_spec.rb +15 -9
  67. data/spec/twitter-ads/http/ton_upload_spec.rb +96 -0
  68. metadata +60 -62
  69. metadata.gz.sig +0 -0
  70. data/lib/twitter-ads/creative/app_download_card.rb +0 -44
  71. data/lib/twitter-ads/creative/lead_gen_card.rb +0 -46
  72. data/lib/twitter-ads/targeting_criteria/tv_channel.rb +0 -20
  73. data/lib/twitter-ads/targeting_criteria/tv_genre.rb +0 -20
  74. data/spec/twitter-ads/creative/app_download_card_spec.rb +0 -44
  75. data/spec/twitter-ads/creative/lead_gen_card_spec.rb +0 -46
@@ -22,7 +22,7 @@
22
22
  "total_budget_amount_local_micro": null,
23
23
  "objective": "CUSTOM",
24
24
  "id": "bw2",
25
- "paused": false,
25
+ "entity_status": "ACTIVE",
26
26
  "account_id": "2iqph",
27
27
  "optimization": "DEFAULT",
28
28
  "categories": [],
@@ -50,7 +50,7 @@
50
50
  "total_budget_amount_local_micro": null,
51
51
  "objective": "CUSTOM",
52
52
  "id": "c4m",
53
- "paused": false,
53
+ "entity_status": "ACTIVE",
54
54
  "account_id": "2iqph",
55
55
  "optimization": "DEFAULT",
56
56
  "categories": [],
@@ -78,7 +78,7 @@
78
78
  "total_budget_amount_local_micro": null,
79
79
  "objective": "CUSTOM",
80
80
  "id": "c5c",
81
- "paused": false,
81
+ "entity_status": "ACTIVE",
82
82
  "account_id": "2iqph",
83
83
  "optimization": "DEFAULT",
84
84
  "categories": [],
@@ -106,7 +106,7 @@
106
106
  "total_budget_amount_local_micro": null,
107
107
  "objective": "CUSTOM",
108
108
  "id": "fhu",
109
- "paused": false,
109
+ "entity_status": "ACTIVE",
110
110
  "account_id": "2iqph",
111
111
  "optimization": "DEFAULT",
112
112
  "categories": [],
@@ -134,7 +134,7 @@
134
134
  "total_budget_amount_local_micro": null,
135
135
  "objective": "CUSTOM",
136
136
  "id": "fxd",
137
- "paused": false,
137
+ "entity_status": "ACTIVE",
138
138
  "account_id": "2iqph",
139
139
  "optimization": "DEFAULT",
140
140
  "categories": [],
@@ -162,7 +162,7 @@
162
162
  "total_budget_amount_local_micro": null,
163
163
  "objective": "CUSTOM",
164
164
  "id": "fxt",
165
- "paused": false,
165
+ "entity_status": "ACTIVE",
166
166
  "account_id": "2iqph",
167
167
  "optimization": "DEFAULT",
168
168
  "categories": [],
@@ -190,7 +190,7 @@
190
190
  "total_budget_amount_local_micro": null,
191
191
  "objective": "CUSTOM",
192
192
  "id": "fya",
193
- "paused": false,
193
+ "entity_status": "ACTIVE",
194
194
  "account_id": "2iqph",
195
195
  "optimization": "DEFAULT",
196
196
  "categories": [],
@@ -218,7 +218,7 @@
218
218
  "total_budget_amount_local_micro": null,
219
219
  "objective": "CUSTOM",
220
220
  "id": "ghj",
221
- "paused": false,
221
+ "entity_status": "ACTIVE",
222
222
  "account_id": "2iqph",
223
223
  "optimization": "DEFAULT",
224
224
  "categories": [],
@@ -246,7 +246,7 @@
246
246
  "total_budget_amount_local_micro": null,
247
247
  "objective": "CUSTOM",
248
248
  "id": "gra",
249
- "paused": false,
249
+ "entity_status": "ACTIVE",
250
250
  "account_id": "2iqph",
251
251
  "optimization": "DEFAULT",
252
252
  "categories": [],
@@ -274,7 +274,7 @@
274
274
  "total_budget_amount_local_micro": null,
275
275
  "objective": "CUSTOM",
276
276
  "id": "gsw",
277
- "paused": false,
277
+ "entity_status": "ACTIVE",
278
278
  "account_id": "2iqph",
279
279
  "optimization": "DEFAULT",
280
280
  "categories": [],
@@ -17,7 +17,7 @@
17
17
  "total_budget_amount_local_micro": null,
18
18
  "objective": "CUSTOM",
19
19
  "id": "bw2",
20
- "paused": false,
20
+ "entity_status": "ACTIVE",
21
21
  "account_id": "2iqph",
22
22
  "optimization": "DEFAULT",
23
23
  "categories": [],
File without changes
@@ -8,7 +8,7 @@
8
8
  {
9
9
  "line_item_id": "2b7xw",
10
10
  "id": "6thl4",
11
- "paused": false,
11
+ "entity_status": "ACTIVE",
12
12
  "created_at": "2015-04-11T20:50:25Z",
13
13
  "updated_at": "2015-04-11T20:50:25Z",
14
14
  "approval_status": "ACCEPTED",
@@ -18,7 +18,7 @@
18
18
  {
19
19
  "line_item_id": "2b7xw",
20
20
  "id": "6thl3",
21
- "paused": false,
21
+ "entity_status": "ACTIVE",
22
22
  "created_at": "2015-04-11T20:50:25Z",
23
23
  "updated_at": "2015-04-11T20:50:25Z",
24
24
  "approval_status": "ACCEPTED",
@@ -28,7 +28,7 @@
28
28
  {
29
29
  "line_item_id": "2b7xw",
30
30
  "id": "6thl5",
31
- "paused": false,
31
+ "entity_status": "ACTIVE",
32
32
  "created_at": "2015-04-11T20:50:25Z",
33
33
  "updated_at": "2015-04-11T20:50:25Z",
34
34
  "approval_status": "ACCEPTED",
@@ -38,7 +38,7 @@
38
38
  {
39
39
  "line_item_id": "2b7xw",
40
40
  "id": "6thl6",
41
- "paused": false,
41
+ "entity_status": "ACTIVE",
42
42
  "created_at": "2015-04-11T20:50:25Z",
43
43
  "updated_at": "2015-04-11T20:50:25Z",
44
44
  "approval_status": "ACCEPTED",
@@ -48,7 +48,7 @@
48
48
  {
49
49
  "line_item_id": "2b7xw",
50
50
  "id": "6thl7",
51
- "paused": false,
51
+ "entity_status": "ACTIVE",
52
52
  "created_at": "2015-04-11T20:50:25Z",
53
53
  "updated_at": "2015-04-11T20:50:25Z",
54
54
  "approval_status": "ACCEPTED",
@@ -58,7 +58,7 @@
58
58
  {
59
59
  "line_item_id": "2b7xw",
60
60
  "id": "6thl8",
61
- "paused": false,
61
+ "entity_status": "ACTIVE",
62
62
  "created_at": "2015-04-11T20:50:25Z",
63
63
  "updated_at": "2015-04-11T20:50:25Z",
64
64
  "approval_status": "ACCEPTED",
@@ -68,7 +68,7 @@
68
68
  {
69
69
  "line_item_id": "2b7xw",
70
70
  "id": "6thlb",
71
- "paused": false,
71
+ "entity_status": "ACTIVE",
72
72
  "created_at": "2015-04-11T20:50:25Z",
73
73
  "updated_at": "2015-04-11T20:50:25Z",
74
74
  "approval_status": "ACCEPTED",
@@ -78,7 +78,7 @@
78
78
  {
79
79
  "line_item_id": "2b7xw",
80
80
  "id": "6thle",
81
- "paused": false,
81
+ "entity_status": "ACTIVE",
82
82
  "created_at": "2015-04-11T20:50:25Z",
83
83
  "updated_at": "2015-04-11T20:50:25Z",
84
84
  "approval_status": "ACCEPTED",
@@ -88,7 +88,7 @@
88
88
  {
89
89
  "line_item_id": "2b7xw",
90
90
  "id": "6thlf",
91
- "paused": false,
91
+ "entity_status": "ACTIVE",
92
92
  "created_at": "2015-04-11T20:50:25Z",
93
93
  "updated_at": "2015-04-11T20:50:25Z",
94
94
  "approval_status": "ACCEPTED",
@@ -98,7 +98,7 @@
98
98
  {
99
99
  "line_item_id": "2b7xw",
100
100
  "id": "6thlg",
101
- "paused": false,
101
+ "entity_status": "ACTIVE",
102
102
  "created_at": "2015-04-11T20:50:25Z",
103
103
  "updated_at": "2015-04-11T20:50:25Z",
104
104
  "approval_status": "ACCEPTED",
@@ -108,7 +108,7 @@
108
108
  {
109
109
  "line_item_id": "2b7xw",
110
110
  "id": "6thlh",
111
- "paused": false,
111
+ "entity_status": "ACTIVE",
112
112
  "created_at": "2015-04-11T20:50:25Z",
113
113
  "updated_at": "2015-04-11T20:50:25Z",
114
114
  "approval_status": "ACCEPTED",
@@ -118,7 +118,7 @@
118
118
  {
119
119
  "line_item_id": "2b7xw",
120
120
  "id": "6thln",
121
- "paused": false,
121
+ "entity_status": "ACTIVE",
122
122
  "created_at": "2015-04-11T20:50:25Z",
123
123
  "updated_at": "2015-04-11T20:50:25Z",
124
124
  "approval_status": "ACCEPTED",
@@ -128,7 +128,7 @@
128
128
  {
129
129
  "line_item_id": "2b7xw",
130
130
  "id": "6thlo",
131
- "paused": false,
131
+ "entity_status": "ACTIVE",
132
132
  "created_at": "2015-04-11T20:50:25Z",
133
133
  "updated_at": "2015-04-11T20:50:25Z",
134
134
  "approval_status": "ACCEPTED",
@@ -138,7 +138,7 @@
138
138
  {
139
139
  "line_item_id": "2b7xw",
140
140
  "id": "6thlp",
141
- "paused": false,
141
+ "entity_status": "ACTIVE",
142
142
  "created_at": "2015-04-11T20:50:25Z",
143
143
  "updated_at": "2015-04-11T20:50:25Z",
144
144
  "approval_status": "ACCEPTED",
@@ -148,7 +148,7 @@
148
148
  {
149
149
  "line_item_id": "2b7xw",
150
150
  "id": "6thlq",
151
- "paused": false,
151
+ "entity_status": "ACTIVE",
152
152
  "created_at": "2015-04-11T20:50:25Z",
153
153
  "updated_at": "2015-04-11T20:50:25Z",
154
154
  "approval_status": "ACCEPTED",
@@ -158,7 +158,7 @@
158
158
  {
159
159
  "line_item_id": "2b7xw",
160
160
  "id": "6tt7l",
161
- "paused": false,
161
+ "entity_status": "ACTIVE",
162
162
  "created_at": "2015-04-12T23:47:44Z",
163
163
  "updated_at": "2015-04-12T23:47:44Z",
164
164
  "approval_status": "ACCEPTED",
@@ -168,7 +168,7 @@
168
168
  {
169
169
  "line_item_id": "2b7xw",
170
170
  "id": "6tt7m",
171
- "paused": false,
171
+ "entity_status": "ACTIVE",
172
172
  "created_at": "2015-04-12T23:47:44Z",
173
173
  "updated_at": "2015-04-12T23:47:44Z",
174
174
  "approval_status": "ACCEPTED",
@@ -178,7 +178,7 @@
178
178
  {
179
179
  "line_item_id": "2b7xw",
180
180
  "id": "6ugv1",
181
- "paused": false,
181
+ "entity_status": "ACTIVE",
182
182
  "created_at": "2015-04-13T22:19:08Z",
183
183
  "updated_at": "2015-04-13T22:19:08Z",
184
184
  "approval_status": "ACCEPTED",
@@ -188,7 +188,7 @@
188
188
  {
189
189
  "line_item_id": "2b7xw",
190
190
  "id": "6w7b5",
191
- "paused": false,
191
+ "entity_status": "ACTIVE",
192
192
  "created_at": "2015-04-16T17:01:56Z",
193
193
  "updated_at": "2015-04-16T17:01:56Z",
194
194
  "approval_status": "ACCEPTED",
@@ -198,7 +198,7 @@
198
198
  {
199
199
  "line_item_id": "2dw80",
200
200
  "id": "70dbj",
201
- "paused": false,
201
+ "entity_status": "ACTIVE",
202
202
  "created_at": "2015-04-23T20:27:27Z",
203
203
  "updated_at": "2015-04-23T20:27:27Z",
204
204
  "approval_status": "ACCEPTED",
@@ -3,7 +3,7 @@
3
3
  "data": {
4
4
  "line_item_id": "2b7xw",
5
5
  "id": "6thl4",
6
- "paused": false,
6
+ "entity_status": "ACTIVE",
7
7
  "created_at": "2015-04-11T20:50:25Z",
8
8
  "updated_at": "2015-04-11T20:50:25Z",
9
9
  "approval_status": "ACCEPTED",
@@ -28,7 +28,7 @@ include TwitterAds
28
28
  # Require All Support Files
29
29
  Dir['./spec/support/*.rb'].sort.each { |file| require file }
30
30
 
31
- ADS_API = 'https://ads-api.twitter.com/1'.freeze
31
+ ADS_API = "https://ads-api.twitter.com/#{TwitterAds::API_VERSION}".freeze
32
32
  TON_API = 'https://ton.twitter.com'.freeze
33
33
  UPLOAD_API = 'https://upload.twitter.com/1.1'.freeze
34
34
 
@@ -35,8 +35,8 @@ module Helpers
35
35
  # @param name [String] The fixture name.
36
36
  # @param url [String] The URL match pattern or regular expression.
37
37
  # @param status [Integer] The response code to return with the fixture.
38
- def stub_fixture(method, name, url, status = 200)
39
- stub_request(method, url).to_return(body: fixture(name), status: status)
38
+ def stub_fixture(method, name, url, status: 200, headers: {})
39
+ stub_request(method, url).to_return(body: fixture(name), status: status, headers: headers)
40
40
  end
41
41
 
42
42
  end
@@ -31,7 +31,7 @@ describe TwitterAds::AppList do
31
31
 
32
32
  let(:app_list) { TwitterAds::AppList.new(account) }
33
33
  let!(:resource) { "#{ADS_API}/accounts/#{account.id}/app_lists" }
34
- let!(:rel_path) { "/1/accounts/#{account.id}/app_lists" }
34
+ let!(:rel_path) { "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/app_lists" }
35
35
 
36
36
  before(:each) do
37
37
  stub_fixture(:post, :app_lists_load, /#{resource}\?.*/)
@@ -34,7 +34,7 @@ describe TwitterAds::LineItem do
34
34
  charge_by
35
35
  include_sentiment
36
36
  objective
37
- paused
37
+ entity_status
38
38
  primary_web_event_tag
39
39
  product_type
40
40
  placements
@@ -24,7 +24,7 @@ describe TwitterAds::ReachEstimate do
24
24
  describe '#fetch' do
25
25
 
26
26
  let!(:resource) { "#{ADS_API}/accounts/#{account.id}/reach_estimate" }
27
- let!(:rel_path) { "/1/accounts/#{account.id}/reach_estimate" }
27
+ let!(:rel_path) { "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/reach_estimate" }
28
28
 
29
29
  before(:each) do
30
30
  stub_fixture(:get, :reach_estimate, /#{resource}\?.*/)
@@ -43,7 +43,7 @@ describe TwitterAds::Tweet do
43
43
  context 'when previewing a new tweet' do
44
44
 
45
45
  it 'url encodes the status content' do
46
- params = { status: 'Hello World!', card_id: '19v69' }
46
+ params = { text: 'Hello World!', card_id: '19v69' }
47
47
  expect(URI).to receive(:escape).at_least(:once).and_call_original
48
48
  result = subject.preview(account, params)
49
49
  expect(result.size).not_to be_nil
@@ -51,26 +51,26 @@ describe TwitterAds::Tweet do
51
51
  end
52
52
 
53
53
  it 'allows a single value for the media_ids param' do
54
- resource = "/1/accounts/#{account.id}/tweet/preview"
55
- expected = { status: 'Hello%20World!', media_ids: 634458428836962304 }
54
+ resource = "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/tweet/preview"
55
+ expected = { text: 'Hello%20World!', media_ids: 634458428836962304 }
56
56
 
57
57
  expect(TwitterAds::Request).to receive(:new).with(
58
58
  account.client, :get, resource, params: expected).and_call_original
59
59
 
60
- params = { status: 'Hello World!', media_ids: 634458428836962304 }
60
+ params = { text: 'Hello World!', media_ids: 634458428836962304 }
61
61
  result = subject.preview(account, params)
62
62
  expect(result.size).not_to be_nil
63
63
  expect(result).to all(include(:platform, :preview))
64
64
  end
65
65
 
66
66
  it 'allows an array of values for the media_ids param' do
67
- resource = "/1/accounts/#{account.id}/tweet/preview"
68
- expected = { status: 'Hello%20World!', media_ids: '634458428836962304,634458428836962305' }
67
+ resource = "/#{TwitterAds::API_VERSION}/accounts/#{account.id}/tweet/preview"
68
+ expected = { text: 'Hello%20World!', media_ids: '634458428836962304,634458428836962305' }
69
69
 
70
70
  expect(TwitterAds::Request).to receive(:new).with(
71
71
  account.client, :get, resource, params: expected).and_call_original
72
72
 
73
- params = { status: 'Hello World!', media_ids: [634458428836962304, 634458428836962305] }
73
+ params = { text: 'Hello World!', media_ids: [634458428836962304, 634458428836962305] }
74
74
  result = subject.preview(account, params)
75
75
  expect(result.size).not_to be_nil
76
76
  expect(result).to all(include(:platform, :preview))
@@ -99,7 +99,8 @@ describe TwitterAds::Client do
99
99
  let!(:account_id) { '2iqph' }
100
100
 
101
101
  before(:all) do
102
- stub_fixture(:get, :accounts_load, /(.*\/1\/accounts\/)([a-zA-Z0-9]*)\z/)
102
+ stub_fixture(:get, :accounts_load,
103
+ /(.*\/#{TwitterAds::API_VERSION}\/accounts\/)([a-zA-Z0-9]*)\z/)
103
104
  end
104
105
 
105
106
  it 'returns a specific Account object' do
@@ -23,8 +23,8 @@ describe TwitterAds::Creative::PromotedTweet do
23
23
 
24
24
  # check model properties
25
25
  subject { described_class.new(account) }
26
- read = %w(id approval_status created_at updated_at deleted)
27
- write = %w(line_item_id tweet_id paused)
26
+ read = %w(id approval_status created_at updated_at deleted entity_status)
27
+ write = %w(line_item_id tweet_id)
28
28
  include_examples 'object property check', read, write
29
29
 
30
30
  describe '#save' do
@@ -23,15 +23,21 @@ describe TwitterAds::Creative::WebsiteCard do
23
23
 
24
24
  # check model properties
25
25
  subject { described_class.new(account) }
26
- read = %w(id preview_url created_at updated_at deleted)
27
- write = %w(name website_title website_url website_cta image_media_id)
26
+ read = %w(
27
+ card_type
28
+ card_uri
29
+ created_at
30
+ deleted
31
+ id
32
+ image
33
+ image_display_height
34
+ image_display_width
35
+ preview_url
36
+ website_dest_url
37
+ website_display_url
38
+ updated_at
39
+ )
40
+ write = %w(image_media_id name website_title website_url)
28
41
  include_examples 'object property check', read, write
29
42
 
30
- it 'raises a warning message each time website_cta is set' do
31
- expect(TwitterAds::Utils).to receive(:deprecated).with(
32
- 'TwitterAds::Creative::WebsiteCard#website_cta',
33
- refer: 'https://t.co/deprecated-website-card-cta')
34
- subject.website_cta = 'any value'
35
- end
36
-
37
43
  end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+ # Copyright (C) 2015 Twitter, Inc.
3
+
4
+ require 'spec_helper'
5
+ require 'tempfile'
6
+
7
+ describe TwitterAds::TONUpload do
8
+ before(:each) do
9
+ stub_fixture(
10
+ :post, :no_content, "#{TON_API}/1.1/ton/bucket/#{bucket_name}",
11
+ headers: {
12
+ 'location' => location_path
13
+ }
14
+ )
15
+ stub_fixture(
16
+ :post, :no_content, "#{TON_API}/1.1/ton/bucket/#{bucket_name}?resumable=true",
17
+ headers: {
18
+ 'location' => "#{location_path}?resumable=true&resumeId=1234567",
19
+ 'x-ton-min-chunk-size' => '1048576'
20
+ }
21
+ )
22
+ end
23
+ let(:bucket_name) { 'ta_partner' }
24
+ let(:location_path) { '/1.1/ton/data/ta_partner/123456789/tYfALUIK-F3ZMxj.txt' }
25
+
26
+ around(:each) do |example|
27
+ example.run
28
+ file.unlink
29
+ end
30
+ let!(:file) do
31
+ Tempfile.open(['', '.dat'], File.expand_path('../../../tmp/', __FILE__)) do |fp|
32
+ fp.tap { |f| f.write(SecureRandom.random_bytes(file_size)) }
33
+ end
34
+ end
35
+ let(:file_size) { 100 }
36
+
37
+ let(:ton_upload) { described_class.new(client, file_path) }
38
+ let(:client) do
39
+ Client.new(
40
+ Faker::Lorem.characters(15),
41
+ Faker::Lorem.characters(40),
42
+ "123456-#{Faker::Lorem.characters(40)}",
43
+ Faker::Lorem.characters(40)
44
+ )
45
+ end
46
+ let(:file_path) { file.path }
47
+
48
+ describe '#initialize' do
49
+
50
+ subject { ton_upload }
51
+ it { is_expected.to be_an_instance_of described_class }
52
+
53
+ context 'when the file path is invalid' do
54
+ let(:file_path) { '/invalid/file/path' }
55
+
56
+ it do
57
+ expect { subject }.to raise_error ArgumentError
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#perform' do
63
+ subject { ton_upload.perform }
64
+
65
+ it 'should call TwitterAds::Request#perform exactly once' do
66
+ expect_any_instance_of(TwitterAds::Request).to receive(:perform).once.and_call_original
67
+ subject
68
+ end
69
+
70
+ it { is_expected.to eq '/1.1/ton/data/ta_partner/123456789/tYfALUIK-F3ZMxj.txt' }
71
+
72
+ context 'when the file size is larger than 64MB' do
73
+ before(:each) do
74
+ allow(ton_upload).to receive(:upload_chunk)
75
+ end
76
+ let(:file_size) { 65 * 1024 * 1024 }
77
+
78
+ it { is_expected.to eq '/1.1/ton/data/ta_partner/123456789/tYfALUIK-F3ZMxj.txt' }
79
+ it 'should call TwitterAds::Request#perform exactly once' do
80
+ expect(ton_upload).to receive(:upload_chunk).at_least(:twice)
81
+ subject
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#inspect' do
87
+ subject { ton_upload.inspect }
88
+
89
+ it do
90
+ is_expected.to include(described_class.name)
91
+ is_expected.to include(ton_upload.object_id.to_s)
92
+ is_expected.to include(bucket_name)
93
+ is_expected.to include(file_path)
94
+ end
95
+ end
96
+ end