blurb 0.4.8 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92ab9498ffa51bc559bac7ee7b4294bef3b0f8f106c5375531af20f8ae026649
4
- data.tar.gz: b7709d612fecbeb4bbd634a716fae4b259ea9d77a0bf4701125856cf90b5726b
3
+ metadata.gz: 637f9566c6691149db022ed83f8e63af8a49aab3cf9ac04259445e80715c9965
4
+ data.tar.gz: 0fa942a78f9cb8a0dae1cf1f29521c1629e0d72add6db5c5b334e4a90da2d427
5
5
  SHA512:
6
- metadata.gz: 4e0e4ac917c156469d58b9bc9a33fa63f94cf88e79cbaf90bd999536a89773cf47ba460acb8e538fb180e583e0a6f7e52240623aec120a39aa9f3d3fc69cbc49
7
- data.tar.gz: e9d09bbc20847bfe92d177e87cfb689bc5a6c59e89fd7d0928e4b27051574b656639027236130d24c71c57e28e906cdd898a5f138bf86805a0936347ba45661e
6
+ metadata.gz: 91e9d8f908a076de92769f0ef7d094505f9ffc1aa03c4cea4600d47a76df066de82db4d2ca5ae18dd41af57dc50e51b30304dba3ba41653128c2636763b90571
7
+ data.tar.gz: 33b4474711cb676df700c72c84ba383d4e8c76881a7c21d810bda8e0a9cb0702359c14766649445d40200ab36ced70d483a40a4ce95d8be5157212640a3b8e1a
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "blurb"
7
- spec.version = "0.4.8"
7
+ spec.version = "0.5.1"
8
8
  spec.authors = ["dlbunker", "eamigo13", "smithworx"]
9
9
  spec.email = ["evan@pattern.com"]
10
10
 
@@ -2,7 +2,8 @@ class Blurb
2
2
  class BaseClass
3
3
  CAMPAIGN_TYPE_CODES = {
4
4
  sp: 'sp',
5
- sb: 'hsa'
5
+ sb: 'hsa',
6
+ sd: 'sd'
6
7
  }.freeze
7
8
  end
8
9
  end
@@ -0,0 +1,24 @@
1
+ require 'blurb/request_collection_with_campaign_type'
2
+
3
+ class Blurb
4
+ class CampaignRequests < RequestCollectionWithCampaignType
5
+ def create_bulk(create_array)
6
+ create_array = map_campaign_payload(create_array)
7
+ super(create_array)
8
+ end
9
+
10
+ def update_bulk(update_array)
11
+ update_array = map_campaign_payload(update_array)
12
+ super(update_array)
13
+ end
14
+
15
+ private
16
+
17
+ def map_campaign_payload(payload)
18
+ campaign_type_string = "sponsoredProducts" if @campaign_type == CAMPAIGN_TYPE_CODES[:sp]
19
+ campaign_type_string = "sponsoredBrands" if @campaign_type == CAMPAIGN_TYPE_CODES[:sb]
20
+ campaign_type_string = "sponsoredDisplays" if @campaign_type == CAMPAIGN_TYPE_CODES[:sd]
21
+ payload.each{ |p| p[:campaign_type] = campaign_type_string }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'blurb/request_collection'
2
+
3
+ class Blurb
4
+ class HistoryRequest < RequestCollection
5
+ FROM_DATE = (DateTime.now - 30).strftime('%Q')
6
+ TO_DATE = DateTime.now.strftime('%Q')
7
+ MAX_COUNT = 200.freeze
8
+ MIN_COUNT = 50.freeze
9
+ FILTERS = []
10
+ PARENT_CAMPAIGN_ID = nil
11
+
12
+ def initialize(base_url:, headers:)
13
+ @base_url = base_url
14
+ @headers = headers
15
+ end
16
+
17
+ def retrieve(
18
+ from_date: FROM_DATE,
19
+ to_date: TO_DATE,
20
+ campaign_ids:,
21
+ filters: FILTERS,
22
+ parent_campaign_id: PARENT_CAMPAIGN_ID,
23
+ count: MAX_COUNT
24
+ )
25
+
26
+ count = MIN_COUNT if count < MIN_COUNT
27
+ count = MAX_COUNT if count > MAX_COUNT
28
+
29
+ payload = {
30
+ sort: {
31
+ key: 'DATE',
32
+ direction: 'ASC'
33
+ },
34
+ fromDate: from_date.to_i,
35
+ toDate: to_date.to_i,
36
+ eventTypes: {
37
+ CAMPAIGN: {
38
+ eventTypeIds: campaign_ids
39
+ }
40
+ },
41
+ count: count
42
+ }
43
+
44
+ payload[:eventTypes][:CAMPAIGN].merge!({ filters: filters }) if filters.present?
45
+ payload[:eventTypes][:CAMPAIGN].merge!({ parents: [{ campaignId: parent_campaign_id }] }) if parent_campaign_id.present?
46
+
47
+ execute_request(
48
+ api_path: "/history",
49
+ request_type: :post,
50
+ payload: payload
51
+ )
52
+ end
53
+ end
54
+ end
@@ -1,9 +1,11 @@
1
1
  require "blurb/account"
2
+ require "blurb/campaign_requests"
2
3
  require "blurb/snapshot_requests"
3
4
  require "blurb/report_requests"
4
5
  require "blurb/request_collection"
5
6
  require "blurb/request_collection_with_campaign_type"
6
7
  require "blurb/suggested_keyword_requests"
8
+ require "blurb/history_request"
7
9
 
8
10
  class Blurb
9
11
  class Profile < BaseClass
@@ -11,29 +13,40 @@ class Blurb
11
13
  attr_accessor(
12
14
  :account,
13
15
  :ad_groups,
16
+ :sd_ad_groups,
14
17
  :campaign_negative_keywords,
15
18
  :portfolios,
16
19
  :product_ads,
20
+ :sd_product_ads,
17
21
  :profile_id,
18
22
  :suggested_keywords,
19
- :targets
23
+ :targets,
24
+ :history
20
25
  )
21
26
 
22
27
  def initialize(profile_id:, account:)
23
28
  @profile_id = profile_id
24
29
  @account = account
25
30
 
26
- @sp_campaigns = RequestCollectionWithCampaignType.new(
31
+ @sp_campaigns = CampaignRequests.new(
27
32
  headers: headers_hash,
28
33
  base_url: @account.api_url,
29
34
  resource: "campaigns",
30
35
  campaign_type: CAMPAIGN_TYPE_CODES[:sp]
31
36
  )
32
- @sb_campaigns = RequestCollectionWithCampaignType.new(
37
+ @sb_campaigns = CampaignRequests.new(
33
38
  headers: headers_hash,
34
39
  base_url: @account.api_url,
35
40
  resource: "campaigns",
36
- campaign_type: CAMPAIGN_TYPE_CODES[:sb]
41
+ campaign_type: CAMPAIGN_TYPE_CODES[:sb],
42
+ bulk_api_limit: 10
43
+ )
44
+ @sd_campaigns = CampaignRequests.new(
45
+ headers: headers_hash,
46
+ base_url: @account.api_url,
47
+ resource: "campaigns",
48
+ campaign_type: CAMPAIGN_TYPE_CODES[:sd],
49
+ bulk_api_limit: 10
37
50
  )
38
51
  @sp_keywords = RequestCollectionWithCampaignType.new(
39
52
  headers: headers_hash,
@@ -62,6 +75,11 @@ class Blurb
62
75
  base_url: @account.api_url,
63
76
  campaign_type: CAMPAIGN_TYPE_CODES[:sp]
64
77
  )
78
+ @sd_reports = ReportRequests.new(
79
+ headers: headers_hash,
80
+ base_url: @account.api_url,
81
+ campaign_type: CAMPAIGN_TYPE_CODES[:sd]
82
+ )
65
83
  @sb_reports = ReportRequests.new(
66
84
  headers: headers_hash,
67
85
  base_url: @account.api_url,
@@ -71,10 +89,18 @@ class Blurb
71
89
  headers: headers_hash,
72
90
  base_url: "#{@account.api_url}/v2/sp/adGroups"
73
91
  )
92
+ @sd_ad_groups = RequestCollection.new(
93
+ headers: headers_hash,
94
+ base_url: "#{@account.api_url}/sd/adGroups"
95
+ )
74
96
  @product_ads = RequestCollection.new(
75
97
  headers: headers_hash,
76
98
  base_url: "#{account.api_url}/v2/sp/productAds"
77
99
  )
100
+ @sd_product_ads = RequestCollection.new(
101
+ headers: headers_hash,
102
+ base_url: "#{account.api_url}/sd/productAds"
103
+ )
78
104
  @sp_negative_keywords = RequestCollectionWithCampaignType.new(
79
105
  headers: headers_hash,
80
106
  base_url: @account.api_url,
@@ -103,11 +129,16 @@ class Blurb
103
129
  headers: headers_hash,
104
130
  base_url: "#{@account.api_url}/v2/sp"
105
131
  )
132
+ @history = HistoryRequest.new(
133
+ headers: headers_hash,
134
+ base_url: @account.api_url
135
+ )
106
136
  end
107
137
 
108
138
  def campaigns(campaign_type)
109
139
  return @sp_campaigns if campaign_type == :sp
110
140
  return @sb_campaigns if campaign_type == :sb || campaign_type == :hsa
141
+ return @sd_campaigns if campaign_type == :sd
111
142
  end
112
143
 
113
144
  def keywords(campaign_type)
@@ -128,6 +159,7 @@ class Blurb
128
159
  def reports(campaign_type)
129
160
  return @sp_reports if campaign_type == :sp
130
161
  return @sb_reports if campaign_type == :sb || campaign_type == :hsa
162
+ return @sd_reports if campaign_type == :sd
131
163
  end
132
164
 
133
165
  def request(api_path: "",request_type: :get, payload: nil, url_params: nil, headers: headers_hash)
@@ -2,6 +2,8 @@ require 'blurb/request_collection_with_campaign_type'
2
2
 
3
3
  class Blurb
4
4
  class ReportRequests < RequestCollectionWithCampaignType
5
+ SD_TACTIC = 'T00020'.freeze
6
+
5
7
  def initialize(campaign_type:, base_url:, headers:)
6
8
  @campaign_type = campaign_type
7
9
  @base_url = "#{base_url}/v2/#{@campaign_type}"
@@ -21,6 +23,7 @@ class Blurb
21
23
  report_date: report_date
22
24
  }
23
25
  payload[:segment] = segment if segment
26
+ payload[:tactic] = SD_TACTIC if @campaign_type.to_sym == :sd
24
27
 
25
28
  execute_request(
26
29
  api_path: "/#{record_type.to_s.camelize(:lower)}/report",
@@ -242,6 +245,118 @@ class Blurb
242
245
  "attributedSales14dSameSKU",
243
246
  "attributedSales30dSameSKU"
244
247
  ] if record_type == :portfolios
248
+ elsif @campaign_type == CAMPAIGN_TYPE_CODES[:sd]
249
+ return [
250
+ "campaignId",
251
+ "impressions",
252
+ "clicks",
253
+ "cost",
254
+ "currency",
255
+ "attributedConversions1d",
256
+ "attributedConversions7d",
257
+ "attributedConversions14d",
258
+ "attributedConversions30d",
259
+ "attributedConversions1dSameSKU",
260
+ "attributedConversions7dSameSKU",
261
+ "attributedConversions14dSameSKU",
262
+ "attributedConversions30dSameSKU",
263
+ "attributedUnitsOrdered1d",
264
+ "attributedUnitsOrdered7d",
265
+ "attributedUnitsOrdered14d",
266
+ "attributedUnitsOrdered30d",
267
+ "attributedSales1d",
268
+ "attributedSales7d",
269
+ "attributedSales14d",
270
+ "attributedSales30d",
271
+ "attributedSales1dSameSKU",
272
+ "attributedSales7dSameSKU",
273
+ "attributedSales14dSameSKU",
274
+ "attributedSales30dSameSKU"
275
+ ] if record_type == :campaigns
276
+ return [
277
+ "campaignId",
278
+ "adGroupId",
279
+ "impressions",
280
+ "clicks",
281
+ "cost",
282
+ "currency",
283
+ "attributedConversions1d",
284
+ "attributedConversions7d",
285
+ "attributedConversions14d",
286
+ "attributedConversions30d",
287
+ "attributedConversions1dSameSKU",
288
+ "attributedConversions7dSameSKU",
289
+ "attributedConversions14dSameSKU",
290
+ "attributedConversions30dSameSKU",
291
+ "attributedUnitsOrdered1d",
292
+ "attributedUnitsOrdered7d",
293
+ "attributedUnitsOrdered14d",
294
+ "attributedUnitsOrdered30d",
295
+ "attributedSales1d",
296
+ "attributedSales7d",
297
+ "attributedSales14d",
298
+ "attributedSales30d",
299
+ "attributedSales1dSameSKU",
300
+ "attributedSales7dSameSKU",
301
+ "attributedSales14dSameSKU",
302
+ "attributedSales30dSameSKU"
303
+ ] if record_type == :ad_groups
304
+ return [
305
+ "campaignId",
306
+ "adGroupId",
307
+ "impressions",
308
+ "clicks",
309
+ "cost",
310
+ "currency",
311
+ "attributedConversions1d",
312
+ "attributedConversions7d",
313
+ "attributedConversions14d",
314
+ "attributedConversions30d",
315
+ "attributedConversions1dSameSKU",
316
+ "attributedConversions7dSameSKU",
317
+ "attributedConversions14dSameSKU",
318
+ "attributedConversions30dSameSKU",
319
+ "attributedUnitsOrdered1d",
320
+ "attributedUnitsOrdered7d",
321
+ "attributedUnitsOrdered14d",
322
+ "attributedUnitsOrdered30d",
323
+ "attributedSales1d",
324
+ "attributedSales7d",
325
+ "attributedSales14d",
326
+ "attributedSales30d",
327
+ "attributedSales1dSameSKU",
328
+ "attributedSales7dSameSKU",
329
+ "attributedSales14dSameSKU",
330
+ "attributedSales30dSameSKU"
331
+ ] if record_type == :product_ads
332
+ return [
333
+ "campaignId",
334
+ "targetId",
335
+ "impressions",
336
+ "clicks",
337
+ "cost",
338
+ "currency",
339
+ "attributedConversions1d",
340
+ "attributedConversions7d",
341
+ "attributedConversions14d",
342
+ "attributedConversions30d",
343
+ "attributedConversions1dSameSKU",
344
+ "attributedConversions7dSameSKU",
345
+ "attributedConversions14dSameSKU",
346
+ "attributedConversions30dSameSKU",
347
+ "attributedUnitsOrdered1d",
348
+ "attributedUnitsOrdered7d",
349
+ "attributedUnitsOrdered14d",
350
+ "attributedUnitsOrdered30d",
351
+ "attributedSales1d",
352
+ "attributedSales7d",
353
+ "attributedSales14d",
354
+ "attributedSales30d",
355
+ "attributedSales1dSameSKU",
356
+ "attributedSales7dSameSKU",
357
+ "attributedSales14dSameSKU",
358
+ "attributedSales30dSameSKU"
359
+ ] if record_type == :targets
245
360
  end
246
361
  end
247
362
  end
@@ -83,6 +83,7 @@ class Blurb
83
83
  end
84
84
 
85
85
  def camelcase_key(k)
86
+ return k if k.to_s == k.to_s.upcase
86
87
  k.to_s.camelize(:lower)
87
88
  end
88
89
 
@@ -4,9 +4,10 @@ require "blurb/base_class"
4
4
  class Blurb
5
5
  class RequestCollection < BaseClass
6
6
 
7
- def initialize(headers:, base_url:)
7
+ def initialize(headers:, base_url:, bulk_api_limit: 100)
8
8
  @base_url = base_url
9
9
  @headers = headers
10
+ @api_limit = bulk_api_limit
10
11
  end
11
12
 
12
13
  def list(url_params=nil)
@@ -46,7 +47,6 @@ class Blurb
46
47
  execute_bulk_request(
47
48
  request_type: :post,
48
49
  payload: create_array,
49
- api_limit: 100
50
50
  )
51
51
  end
52
52
 
@@ -58,7 +58,6 @@ class Blurb
58
58
  execute_bulk_request(
59
59
  request_type: :put,
60
60
  payload: update_array,
61
- api_limit: 100
62
61
  )
63
62
  end
64
63
 
@@ -73,6 +72,7 @@ class Blurb
73
72
 
74
73
  def execute_request(api_path: "", request_type:, payload: nil, url_params: nil)
75
74
  url = "#{@base_url}#{api_path}"
75
+ url.sub!('/sd/', '/') if request_type == :get && url.include?('sd/reports') && url_params.nil?
76
76
 
77
77
  request = Request.new(
78
78
  url: url,
@@ -86,9 +86,9 @@ class Blurb
86
86
  end
87
87
 
88
88
  # Split up bulk requests to match the api limit
89
- def execute_bulk_request(api_limit:, **execute_request_params)
89
+ def execute_bulk_request(**execute_request_params)
90
90
  results = []
91
- payloads = execute_request_params[:payload].each_slice(api_limit).to_a
91
+ payloads = execute_request_params[:payload].each_slice(@api_limit).to_a
92
92
  payloads.each do |p|
93
93
  execute_request_params[:payload] = p
94
94
  results << execute_request(execute_request_params)
@@ -3,10 +3,12 @@ require 'blurb/request_collection'
3
3
  class Blurb
4
4
  class RequestCollectionWithCampaignType < RequestCollection
5
5
 
6
- def initialize(campaign_type:, resource:, base_url:, headers:)
6
+ def initialize(campaign_type:, resource:, base_url:, headers:, bulk_api_limit: 100)
7
7
  @campaign_type = campaign_type
8
- @base_url = "#{base_url}/v2/#{@campaign_type}/#{resource}"
8
+ base_url = campaign_type.to_s == 'sd' ? base_url : "#{base_url}/v2"
9
+ @base_url = "#{base_url}/#{@campaign_type}/#{resource}"
9
10
  @headers = headers
11
+ @api_limit = bulk_api_limit
10
12
  end
11
13
  end
12
- end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blurb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dlbunker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-02-10 00:00:00.000000000 Z
13
+ date: 2020-07-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -175,10 +175,12 @@ files:
175
175
  - lib/blurb.rb
176
176
  - lib/blurb/account.rb
177
177
  - lib/blurb/base_class.rb
178
+ - lib/blurb/campaign_requests.rb
178
179
  - lib/blurb/client.rb
179
180
  - lib/blurb/errors/failed_request.rb
180
181
  - lib/blurb/errors/invalid_report_request.rb
181
182
  - lib/blurb/errors/request_throttled.rb
183
+ - lib/blurb/history_request.rb
182
184
  - lib/blurb/profile.rb
183
185
  - lib/blurb/report_requests.rb
184
186
  - lib/blurb/request.rb