blurb 0.4.12 → 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: f51804779721ce8f8d372f54e8d81b4a04595803cefe311407d2ee8dbb445789
4
- data.tar.gz: 7962d3726afd7d7fbdcd8d7cf8721bf8b8db483ea5c8abb9540fa0cc7e65c62e
3
+ metadata.gz: 637f9566c6691149db022ed83f8e63af8a49aab3cf9ac04259445e80715c9965
4
+ data.tar.gz: 0fa942a78f9cb8a0dae1cf1f29521c1629e0d72add6db5c5b334e4a90da2d427
5
5
  SHA512:
6
- metadata.gz: 2ed1f87374153e5064b0112cdec7ecf74b1e7078ab2197315fdb6429afbaeb0ce57ee824232cfefa19357d3e1698544794b77dad44d355370a2dd6dbc0bba8b0
7
- data.tar.gz: af34fd65630827543685bf9f7367bae7bf44b3b904f3958892e42b0bc0c1d50dc6cf45b121540021e69648b80a0eb7b753aab3a30a4ef6e34a392215998fcc4e
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.12"
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
@@ -17,6 +17,7 @@ class Blurb
17
17
  def map_campaign_payload(payload)
18
18
  campaign_type_string = "sponsoredProducts" if @campaign_type == CAMPAIGN_TYPE_CODES[:sp]
19
19
  campaign_type_string = "sponsoredBrands" if @campaign_type == CAMPAIGN_TYPE_CODES[:sb]
20
+ campaign_type_string = "sponsoredDisplays" if @campaign_type == CAMPAIGN_TYPE_CODES[:sd]
20
21
  payload.each{ |p| p[:campaign_type] = campaign_type_string }
21
22
  end
22
23
  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
@@ -5,6 +5,7 @@ require "blurb/report_requests"
5
5
  require "blurb/request_collection"
6
6
  require "blurb/request_collection_with_campaign_type"
7
7
  require "blurb/suggested_keyword_requests"
8
+ require "blurb/history_request"
8
9
 
9
10
  class Blurb
10
11
  class Profile < BaseClass
@@ -12,12 +13,15 @@ class Blurb
12
13
  attr_accessor(
13
14
  :account,
14
15
  :ad_groups,
16
+ :sd_ad_groups,
15
17
  :campaign_negative_keywords,
16
18
  :portfolios,
17
19
  :product_ads,
20
+ :sd_product_ads,
18
21
  :profile_id,
19
22
  :suggested_keywords,
20
- :targets
23
+ :targets,
24
+ :history
21
25
  )
22
26
 
23
27
  def initialize(profile_id:, account:)
@@ -37,6 +41,13 @@ class Blurb
37
41
  campaign_type: CAMPAIGN_TYPE_CODES[:sb],
38
42
  bulk_api_limit: 10
39
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
50
+ )
40
51
  @sp_keywords = RequestCollectionWithCampaignType.new(
41
52
  headers: headers_hash,
42
53
  base_url: @account.api_url,
@@ -64,6 +75,11 @@ class Blurb
64
75
  base_url: @account.api_url,
65
76
  campaign_type: CAMPAIGN_TYPE_CODES[:sp]
66
77
  )
78
+ @sd_reports = ReportRequests.new(
79
+ headers: headers_hash,
80
+ base_url: @account.api_url,
81
+ campaign_type: CAMPAIGN_TYPE_CODES[:sd]
82
+ )
67
83
  @sb_reports = ReportRequests.new(
68
84
  headers: headers_hash,
69
85
  base_url: @account.api_url,
@@ -73,10 +89,18 @@ class Blurb
73
89
  headers: headers_hash,
74
90
  base_url: "#{@account.api_url}/v2/sp/adGroups"
75
91
  )
92
+ @sd_ad_groups = RequestCollection.new(
93
+ headers: headers_hash,
94
+ base_url: "#{@account.api_url}/sd/adGroups"
95
+ )
76
96
  @product_ads = RequestCollection.new(
77
97
  headers: headers_hash,
78
98
  base_url: "#{account.api_url}/v2/sp/productAds"
79
99
  )
100
+ @sd_product_ads = RequestCollection.new(
101
+ headers: headers_hash,
102
+ base_url: "#{account.api_url}/sd/productAds"
103
+ )
80
104
  @sp_negative_keywords = RequestCollectionWithCampaignType.new(
81
105
  headers: headers_hash,
82
106
  base_url: @account.api_url,
@@ -105,11 +129,16 @@ class Blurb
105
129
  headers: headers_hash,
106
130
  base_url: "#{@account.api_url}/v2/sp"
107
131
  )
132
+ @history = HistoryRequest.new(
133
+ headers: headers_hash,
134
+ base_url: @account.api_url
135
+ )
108
136
  end
109
137
 
110
138
  def campaigns(campaign_type)
111
139
  return @sp_campaigns if campaign_type == :sp
112
140
  return @sb_campaigns if campaign_type == :sb || campaign_type == :hsa
141
+ return @sd_campaigns if campaign_type == :sd
113
142
  end
114
143
 
115
144
  def keywords(campaign_type)
@@ -130,6 +159,7 @@ class Blurb
130
159
  def reports(campaign_type)
131
160
  return @sp_reports if campaign_type == :sp
132
161
  return @sb_reports if campaign_type == :sb || campaign_type == :hsa
162
+ return @sd_reports if campaign_type == :sd
133
163
  end
134
164
 
135
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
 
@@ -72,6 +72,7 @@ class Blurb
72
72
 
73
73
  def execute_request(api_path: "", request_type:, payload: nil, url_params: nil)
74
74
  url = "#{@base_url}#{api_path}"
75
+ url.sub!('/sd/', '/') if request_type == :get && url.include?('sd/reports') && url_params.nil?
75
76
 
76
77
  request = Request.new(
77
78
  url: url,
@@ -5,9 +5,10 @@ class Blurb
5
5
 
6
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
10
11
  @api_limit = bulk_api_limit
11
12
  end
12
13
  end
13
- 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.12
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-03-24 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
@@ -180,6 +180,7 @@ files:
180
180
  - lib/blurb/errors/failed_request.rb
181
181
  - lib/blurb/errors/invalid_report_request.rb
182
182
  - lib/blurb/errors/request_throttled.rb
183
+ - lib/blurb/history_request.rb
183
184
  - lib/blurb/profile.rb
184
185
  - lib/blurb/report_requests.rb
185
186
  - lib/blurb/request.rb