blurb 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blurb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dlbunker
8
+ - eamigo13
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-05-01 00:00:00.000000000 Z
12
+ date: 2019-08-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -16,14 +17,14 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '1.14'
20
+ version: '2.0'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '1.14'
27
+ version: '2.0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +67,48 @@ dependencies:
66
67
  - - "~>"
67
68
  - !ruby/object:Gem::Version
68
69
  version: 0.3.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: dotenv
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: byebug
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: faker
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 2.1.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 2.1.0
69
112
  - !ruby/object:Gem::Dependency
70
113
  name: rest-client
71
114
  requirement: !ruby/object:Gem::Requirement
@@ -94,10 +137,24 @@ dependencies:
94
137
  - - "~>"
95
138
  - !ruby/object:Gem::Version
96
139
  version: 1.4.0
140
+ - !ruby/object:Gem::Dependency
141
+ name: activesupport
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
97
154
  description: Amazon released a new Advertising API in 2017. This gem will integrate
98
155
  and allow you to make API calls to Amazon.
99
156
  email:
100
- - dan@iserve.com
157
+ - evan@pattern.com
101
158
  executables: []
102
159
  extensions: []
103
160
  extra_rdoc_files: []
@@ -115,16 +172,17 @@ files:
115
172
  - bin/setup
116
173
  - blurb.gemspec
117
174
  - lib/blurb.rb
118
- - lib/blurb/ad_group.rb
119
- - lib/blurb/base_resource.rb
120
- - lib/blurb/bid_recommendation.rb
121
- - lib/blurb/campaign.rb
122
- - lib/blurb/keyword.rb
175
+ - lib/blurb/account.rb
176
+ - lib/blurb/base_class.rb
177
+ - lib/blurb/campaign_requests.rb
178
+ - lib/blurb/client.rb
123
179
  - lib/blurb/profile.rb
124
- - lib/blurb/report.rb
125
- - lib/blurb/snapshot.rb
126
- - lib/blurb/suggested_keyword.rb
127
- - lib/blurb/version.rb
180
+ - lib/blurb/report_requests.rb
181
+ - lib/blurb/request.rb
182
+ - lib/blurb/request_collection.rb
183
+ - lib/blurb/request_collection_with_campaign_type.rb
184
+ - lib/blurb/snapshot_requests.rb
185
+ - lib/blurb/suggested_keyword_requests.rb
128
186
  homepage: https://github.com/iserve-products/blurb
129
187
  licenses:
130
188
  - MIT
@@ -144,8 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
202
  - !ruby/object:Gem::Version
145
203
  version: '0'
146
204
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.6.14
205
+ rubygems_version: 3.0.3
149
206
  signing_key:
150
207
  specification_version: 4
151
208
  summary: Ruby gem for the Amazon Advertising API
@@ -1,40 +0,0 @@
1
- module Blurb
2
- class AdGroup < BaseResource
3
-
4
- URL_PARAMS = ['startIndex', 'campaignType', 'count', 'matchTypeFilter', 'name', 'state', 'campaignIdFilter', 'adGroupIdFilter']
5
-
6
- def retrieve(keyword_id, campaign_type)
7
- raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
8
- get_request("/v2/#{campaign_type}/adGroups/#{keyword_id}")
9
- end
10
-
11
- def retrieve_extended(keyword_id, campaign_type)
12
- raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
13
- get_request("/v2/#{campaign_type}/adGroups/extended/#{keyword_id}")
14
- end
15
-
16
- def list(campaign_type, params = {}, opts = {})
17
- raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
18
- get_request("/v2/#{campaign_type}/adGroups?#{setup_url_params(params, URL_PARAMS)}")
19
- end
20
-
21
- def list_extended(campaign_type, params = {}, opts = {})
22
- raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
23
- get_request("/v2/#{campaign_type}/adGroups/extended?#{setup_url_params(params, URL_PARAMS)}")
24
- end
25
-
26
- def create(campaign_type, params = {}, opts = {})
27
- # required argument checks
28
- if !params["name"] && !params["targetingType"] && !params["state"] && !params["dailyBudget"] && !params["startDate"]
29
- raise ArgumentError.new("params hash must contain name, targetingType, state, dailyBudget and startDate")
30
- end
31
- raise ArgumentError.new("Only sponsored product adGroups can be created through the api. Sponsored Brands adGroups must be created through the user interface") unless campaign_type == SPONSORED_PRODUCTS
32
-
33
- post_request("/v2/#{campaign_type}/adGroups", [params])
34
- end
35
-
36
- def delete(keyword_id)
37
- delete_request("/v2/adGroups/#{keyword_id}")
38
- end
39
- end
40
- end
@@ -1,172 +0,0 @@
1
- module Blurb
2
- class BaseResource
3
- attr_accessor :client_secret, :client_id, :refresh_token, :profile_id, :test_env, :eu_env
4
-
5
- TOKEN_URL = "https://api.amazon.com"
6
- API_URL = "https://advertising-api.amazon.com"
7
- TEST_API_URL = "https://advertising-api-test.amazon.com"
8
- EU_API_URL = "https://advertising-api-eu.amazon.com"
9
-
10
- SPONSORED_PRODUCTS = "sp"
11
- SPONSORED_BRANDS = "hsa"
12
-
13
- def initialize(account=Blurb.default_account)
14
- @client_secret = account[:client_secret]
15
- @client_id = account[:client_id]
16
- @refresh_token = account[:refresh_token]
17
- @profile_id = account[:profile_id]
18
- @test_env = Blurb.test_env
19
- @eu_env = account[:eu_env]
20
- end
21
-
22
- def active_api_url
23
- if @test_env
24
- return TEST_API_URL
25
- end
26
- if @eu_env
27
- return EU_API_URL
28
- end
29
-
30
- return API_URL
31
- end
32
-
33
- def client
34
- return OAuth2::Client.new(
35
- "",
36
- "",
37
- :site => TOKEN_URL
38
- )
39
- end
40
-
41
- def token_code(auth_code)
42
- response = client.request(:post, "/auth/o2/token",
43
- {
44
- body: {
45
- grant_type: "authorization_code",
46
- client_id: @client_id,
47
- code: auth_code,
48
- client_secret: @client_secret
49
- }
50
- }
51
- )
52
-
53
- return JSON.parse(response.body)
54
- end
55
-
56
- def retrieve_token(params = {}, opts = {})
57
- response = client.request(:post, "/auth/o2/token",
58
- {
59
- body: {
60
- grant_type: "refresh_token",
61
- client_id: @client_id,
62
- refresh_token: @refresh_token,
63
- client_secret: @client_secret
64
- }
65
- }
66
- )
67
-
68
- return JSON.parse(response.body)
69
- end
70
-
71
- def profile_request(api_path)
72
- access_token = retrieve_token()
73
-
74
- request_config = {
75
- method: :get,
76
- url: "#{active_api_url}#{api_path}",
77
- headers: {
78
- "Authorization" => "Bearer #{access_token['access_token']}",
79
- "Content-Type" => "application/json",
80
- "Amazon-Advertising-API-ClientId" => @client_id
81
- }
82
- }
83
-
84
- resp = RestClient::Request.execute(request_config)
85
- return JSON.parse(resp)
86
- end
87
-
88
- def get_request(api_path, opts = {})
89
- url = "#{active_api_url}#{api_path}"
90
- url = api_path if opts[:full_path]
91
-
92
- request_config = {
93
- method: :get,
94
- url: url,
95
- headers: headers_hash(opts),
96
- max_redirects: 0
97
- }
98
-
99
- return make_request(request_config)
100
- end
101
-
102
- def post_request(api_path, payload)
103
- request_config = {
104
- method: :post,
105
- url: "#{active_api_url}#{api_path}",
106
- payload: payload.to_json,
107
- headers: headers_hash
108
- }
109
-
110
- return make_request(request_config)
111
- end
112
-
113
- def put_request(api_path, payload)
114
- request_config = {
115
- method: :put,
116
- url: "#{active_api_url}#{api_path}",
117
- payload: payload.to_json,
118
- headers: headers_hash
119
- }
120
-
121
- return make_request(request_config)
122
- end
123
-
124
- def delete_request(api_path)
125
- request_config = {
126
- method: :delete,
127
- url: "#{active_api_url}#{api_path}",
128
- headers: headers_hash,
129
- }
130
-
131
- return make_request(request_config)
132
- end
133
-
134
- private
135
-
136
- def make_request(request_config)
137
- begin
138
- resp = RestClient::Request.execute(request_config)
139
- rescue RestClient::ExceptionWithResponse => err
140
- # If this happens, then we are downloading a report from the api, so we can simply download the location
141
- if err.response.code == 307
142
- return RestClient.get(err.response.headers[:location])
143
- else
144
- return err.response.body
145
- end
146
- end
147
-
148
- response = JSON.parse(resp) if resp
149
- return response
150
- end
151
-
152
- def headers_hash(opts = {})
153
- access_token = retrieve_token()
154
-
155
- headers_hash = {
156
- "Authorization" => "Bearer #{access_token['access_token']}",
157
- "Content-Type" => "application/json",
158
- "Amazon-Advertising-API-Scope" => @profile_id,
159
- "Amazon-Advertising-API-ClientId" => @client_id
160
- }
161
-
162
- headers_hash["Content-Encoding"] = "gzip" if opts[:gzip]
163
-
164
- return headers_hash
165
- end
166
-
167
- def setup_url_params(params, whitelist)
168
- whitelisted_params = params.select { |k,v| whitelist.include?(k) }
169
- return URI.encode_www_form(whitelisted_params)
170
- end
171
- end
172
- end
@@ -1,24 +0,0 @@
1
- module Blurb
2
- class BidRecommendation < BaseResource
3
- def ad_group_recommendations(params = {}, opts = {})
4
- # required argument checks
5
- raise ArgumentError.new("params hash must contain an adGroupId") unless params["adGroupId"]
6
-
7
- get_request("/v2/adGroups/#{params["adGroupId"]}/bidRecommendations")
8
- end
9
-
10
- def keyword_recommendations(params = {}, opts = {})
11
- # required argument checks
12
- raise ArgumentError.new("params hash must contain an keywordId") unless params["keywordId"]
13
-
14
- get_request("/v2/keywords/#{params["keywordId"]}/bidRecommendations")
15
- end
16
-
17
- def bulk_keyword_recommendations(params = {}, opts = {})
18
- # required argument checks
19
- raise ArgumentError.new("params hash must contain an array of keywordIds") unless params["keywordIds"]
20
-
21
- post_request("/v2/keywords/bidRecommendations", params["keywordIds"])
22
- end
23
- end
24
- end
@@ -1,38 +0,0 @@
1
- module Blurb
2
- class Campaign < BaseResource
3
-
4
- URL_PARAMS = ['count', 'stateFilter', 'startIndex', 'name', 'campaignIdFilter']
5
-
6
- def retrieve(campaign_id, campaign_type)
7
- get_request("/v2/#{campaign_type}/campaigns/#{campaign_id}")
8
- end
9
-
10
- def retrieve_extended(campaign_id, campaign_type)
11
- raise ArgumentError.new("Extended campaigns interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
12
- get_request("/v2/#{campaign_type}/campaigns/extended/#{campaign_id}")
13
- end
14
-
15
- def list(campaign_type, params = {}, opts = {})
16
- get_request("/v2/#{campaign_type}/campaigns?#{setup_url_params(params, URL_PARAMS)}")
17
- end
18
-
19
- def list_extended(campaign_type, params = {}, opts = {})
20
- raise ArgumentError.new("Extended campaigns interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
21
- get_request("/v2/#{campaign_type}/campaigns/extended?#{setup_url_params(params, URL_PARAMS)}")
22
- end
23
-
24
- def create(campaign_type, params = {}, opts = {})
25
- # required argument checks
26
- if !params["name"] && !params["targetingType"] && !params["state"] && !params["dailyBudget"] && !params["startDate"]
27
- raise ArgumentError.new("params hash must contain name, targetingType, state, dailyBudget and startDate")
28
- end
29
- raise ArgumentError.new("Only sponsored product campaigns can be created through the api. Sponsored Brands campaigns must be created through the user interface") unless campaign_type == SPONSORED_PRODUCTS
30
-
31
- post_request("/v2/#{campaign_type}/campaigns", [params])
32
- end
33
-
34
- def delete(campaign_id)
35
- delete_request("/v2/campaigns/#{campaign_id}")
36
- end
37
- end
38
- end
@@ -1,51 +0,0 @@
1
- module Blurb
2
- class Keyword < BaseResource
3
- URL_PARAMS = ['startIndex', 'count', 'matchTypeFilter', 'keywordText', 'state', 'campaignIdFilter', 'adGroupIdFilter']
4
-
5
- def retrieve(keyword_id, campaign_type)
6
- get_request("/v2/#{campaign_type}/keywords/#{keyword_id}")
7
- end
8
-
9
- def retrieve_extended(keyword_id, campaign_type)
10
- raise ArgumentError.new("Extended keywords interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
11
- get_request("/v2/#{campaign_type}/keywords/extended/#{keyword_id}")
12
- end
13
-
14
- def list(campaign_type, params = {}, opts = {})
15
- get_request("/v2/#{campaign_type}/keywords?#{setup_url_params(params, URL_PARAMS)}")
16
- end
17
-
18
- def list_extended(campaign_type, params = {}, opts = {})
19
- raise ArgumentError.new("Extended keywords interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
20
- get_request("/v2/#{campaign_type}/keywords/extended?#{setup_url_params(params, URL_PARAMS)}")
21
- end
22
-
23
- def update(campaign_type, payload, opts = {})
24
- raise ArgumentError.new("Extended keywords interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
25
- payload = [payload] unless payload.class == Array
26
-
27
- # The Amazon Advertising API only accepts bulk changes of up to 1000 keywords
28
- results = []
29
- payloads = payload.each_slice(1000).to_a
30
- payloads.each do |p|
31
- results << put_request("/v2/#{campaign_type}/keywords", p)
32
- end
33
-
34
- return results.flatten
35
- end
36
-
37
- def create(campaign_type, params = {}, opts = {})
38
- # required argument checks
39
- if !params["campaignId"] && !params["adGroupId"] && !params["keywordText"] && !params["matchType"] && !params["state"]
40
- raise ArgumentError.new("params hash must contain campaignId, adGroupId, keywordText, matchType and state")
41
- end
42
- raise ArgumentError.new("Only sponsored product keywords can be created through the api. Sponsored Brands keywords must be created through the user interface") unless campaign_type == SPONSORED_PRODUCTS
43
-
44
- post_request("/v2/#{campaign_type}/keywords", [params])
45
- end
46
-
47
- def delete(keyword_id)
48
- delete_request("/v2/keywords/#{keyword_id}")
49
- end
50
- end
51
- end