genba 0.1.7 → 0.1.8

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
- SHA1:
3
- metadata.gz: 15c9e806373cf470aedb8c8ce8c962f12536dfea
4
- data.tar.gz: 61aaddf75c054e433ed1892b7bd5e92437a42498
2
+ SHA256:
3
+ metadata.gz: ad9f501aed7cdc7d927b252bc618c11b16b3d151839702c38b335dc36ff4793c
4
+ data.tar.gz: 0c939146254fc219d87aa36cd690fe6d1f5065546a4dfc361b88dac23406bf30
5
5
  SHA512:
6
- metadata.gz: 52ef2a1c13b0b5bcab7856488389ed8d088a76db12fecc68dddab83951a9b4c9cf4b384fe27414dbc670c92790ecc59dae7e0281bf8561b979112fcac9917c53
7
- data.tar.gz: a97bfe9998883b1b7f7c4e8542fdad2cbcfe2a931da8e6bfcefa581076b0eb301ec5c93bf1e6933c92f5e7de69df69a443e085adf47b618615a9e91c857e04ad
6
+ metadata.gz: '08aced13b92d592786558fe1f36c078fdc3bed7531ad4c32ee16b255da6935098b95dbd0d6b5484a986d7ce5205f2b25b2714fed3a4da02c6c4d20a7032ff413'
7
+ data.tar.gz: f11bdbe020d5ef078bf48369ad0bbfbe9076767b109e54b7caff21fbedb16bede609f518ec288c0258fe143d500407f1f627bfd25104fffad3c7e82a9a9d94fa
data/.gitignore CHANGED
@@ -10,3 +10,6 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .byebug_history
13
+ *.log
14
+ .DS_Store
15
+ *.txt
data/.rspec CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem 'activemodel', require: 'active_model'
10
10
  group :development do
11
11
  gem 'rake'
12
12
  gem 'webmock'
13
+ gem 'uuidtools'
13
14
 
14
15
  platforms :mri do
15
16
  # to avoid problems, bring Byebug in on just versions of Ruby under which
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- genba (0.1.7)
4
+ genba (0.1.8)
5
5
  oj (~> 2.18)
6
6
  rest-client (~> 2.0)
7
7
  ruby-mcrypt (= 0.2.0)
@@ -32,9 +32,9 @@ GEM
32
32
  i18n (1.0.1)
33
33
  concurrent-ruby (~> 1.0)
34
34
  method_source (0.9.0)
35
- mime-types (3.1)
35
+ mime-types (3.2.2)
36
36
  mime-types-data (~> 3.2015)
37
- mime-types-data (3.2016.0521)
37
+ mime-types-data (3.2018.0812)
38
38
  minitest (5.11.3)
39
39
  netrc (0.11.0)
40
40
  oj (2.18.5)
@@ -71,6 +71,7 @@ GEM
71
71
  unf (0.1.4)
72
72
  unf_ext
73
73
  unf_ext (0.0.7.5)
74
+ uuidtools (2.1.5)
74
75
  webmock (3.4.1)
75
76
  addressable (>= 2.3.6)
76
77
  crack (>= 0.3.2)
@@ -88,7 +89,8 @@ DEPENDENCIES
88
89
  pry-byebug
89
90
  rake
90
91
  rspec (~> 3.0)
92
+ uuidtools
91
93
  webmock
92
94
 
93
95
  BUNDLED WITH
94
- 1.16.1
96
+ 1.17.1
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -4,65 +4,91 @@
4
4
  [![CircleCI](https://circleci.com/gh/iscreen/genba-ruby.svg?style=shield)](https://circleci.com/gh/iscreen/genba-ruby)
5
5
  [![Gem Version](https://badge.fury.io/rb/genba-ruby.svg)](https://badge.fury.io/rb/genba-ruby)
6
6
 
7
- The Genba Library provides convenient access to the [Genba API](https://api.genbagames.com/doc/) from applications written in the Ruby language.
7
+ The Genba Library provides convenient access to the [Genba API](https://api.genbagames.com/doc/) from applications written in the Ruby language.
8
8
 
9
9
  ## Basic Usage
10
10
 
11
+ ```ruby
11
12
  require 'genba'
12
13
 
13
14
  genba_client = Genba.client(
14
15
  username: 'api_genba_user',
15
- app_id: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
16
- api_key: 'e6a69096fb94d91971ccc69b1770b9f3'
16
+ app_id: '00000000-0000-0000-0000-000000000000',
17
+ api_key: '00000000000000000000000000000000',
18
+ customer_account_id: '00000000-0000-0000-0000-000000000000'
17
19
  )
20
+ ```
18
21
 
19
22
  ## Products
20
23
  [Genba Products API](https://api.genbagames.com/doc/#api-Product)
21
24
 
22
- Call products.get_products to get all products.
25
+ ### Product - Changes
26
+
27
+ Return a list of products which have changed since a given date, including basic or advanced metadata.
23
28
 
24
29
  ```ruby
25
30
  payload = {
26
- countryISO: 'US',
27
- includeMeta: false
31
+ from_date: DateTime.now - 1,
32
+ country_iso: 'US',
33
+ include_meta: false
34
+ }
35
+
36
+ response = genba_client.products.get_changes(payload)
37
+ ```
38
+
39
+ ```ruby
40
+ payload = {
41
+ include_meta: false
42
+ }
43
+
44
+ response = genba_client.products.get_changes(payload)
45
+ ```
46
+
47
+ ### Product - Get
48
+
49
+ Return a list of product objects, including basic or advanced metadata.
50
+
51
+ ```ruby
52
+ payload = {
53
+ include_meta: false
28
54
  }
29
55
 
30
56
  response = genba_client.products.get_products(payload)
31
57
  ```
32
58
 
33
- Retrieve an existing product
59
+ Return a list of product objects with countryISO
34
60
 
35
61
  ```ruby
36
62
  payload = {
37
- skuId: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
38
- countryISO: 'US',
39
- includeMeta: false
63
+ country_iso: 'US',
64
+ include_meta: false
40
65
  }
41
-
42
- product = genba_client.products.get_products(payload)
66
+
67
+ response = genba_client.products.get_products(payload)
43
68
  ```
44
69
 
45
- Return a list of products which have changed since a given date, including basic or advanced metadata.
70
+ Retrieve an existing product
46
71
 
47
72
  ```ruby
48
73
  payload = {
49
- fromDate: 1.days.ago.strftime('%FT%T'),
50
- countryISO: 'US',
51
- includeMeta: false
74
+ sku_id: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
75
+ include_meta: true
52
76
  }
53
-
54
- response = genba_client.products.get_changes(payload)
77
+
78
+ product = genba_client.products.get_products(payload)
55
79
  ```
56
80
 
81
+ ### Product - Removed
82
+
57
83
  Return a list of products which have been removed since a given date.
58
84
 
59
85
  ```ruby
60
86
  payload = {
61
- fromDate: 1.days.ago.strftime('%FT%T'),
62
- countryISO: 'US',
63
- includeMeta: false
87
+ from_date: DateTime.now - 1,
88
+ country_iso: 'US',
89
+ include_meta: false
64
90
  }
65
-
91
+
66
92
  response = genba_client.products.get_removed(payload)
67
93
  ```
68
94
 
@@ -78,22 +104,39 @@ response = genba_client.prices.get_prices
78
104
  ## Restrictions
79
105
  [Genba Restrictions API](https://api.genbagames.com/doc/#api-Restrictions)
80
106
 
107
+ ### Restrictions - Get
108
+
81
109
  Returns a list of product sku restrictions, whitelist - can only sold in countries, blacklist - cannot be sold in countries.
82
110
 
111
+ Returns a list of product sku restrictions by countryISO
112
+
83
113
  ```ruby
84
114
  payload = {
85
- productId: '84d90a06-f458-4ed8-8f3d-91aa84cc6577',
86
- fromDate: 1.days.ago.strftime('%FT%T'),
87
- countryISO: 'US'
115
+ country_iso: 'US'
88
116
  }
89
117
 
90
- response = genba_client.restrictions.get_restrictions
118
+ response = genba_client.restrictions.get_restrictions(payload)
119
+ response[:productRestriction]
120
+ ```
121
+
122
+ Returns a list of product sku restrictions by countryISO, productID and fromDate
123
+
124
+ ```ruby
125
+ payload = {
126
+ product_id: '84d90a06-f458-4ed8-8f3d-91aa84cc6577',
127
+ from_date: 1.days.ago.strftime('%FT%T'),
128
+ country_iso: 'US'
129
+ }
130
+
131
+ response = genba_client.restrictions.get_restrictions(payload)
91
132
  response[:productRestriction]
92
133
  ```
93
134
 
94
135
  ## Keys
95
136
  [Genba Keys API](https://api.genbagames.com/doc/#api-Keys)
96
137
 
138
+ ### Keys - Get Test Keys
139
+
97
140
  Request Product Test Keys for a SKU
98
141
 
99
142
  ```ruby
@@ -106,8 +149,89 @@ response[:keys]
106
149
  Request Product Keys for a SKU
107
150
 
108
151
  ```ruby
109
- response = genba_client.keys.get_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577', 1)
152
+
153
+ response = genba_client.keys.get_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577', 1, customerAccountId)
110
154
 
111
155
  response[:status]
112
156
  response[:keys]
113
157
  ```
158
+
159
+ ### Keys - Report Usage
160
+
161
+ Report usage with keyCode
162
+
163
+ ```ruby
164
+ key = KeyReportRequest.new(
165
+ key: '00000000000000000000000000000000',
166
+ country_iso: 'US',
167
+ sale_date: DateTime.now,
168
+ user_ip_address: '182.212.212.22',
169
+ e_tailer_buying_price: 3.8,
170
+ e_tailer_buying_price_currency_code: 'USD',
171
+ e_tailer_selling_price_net: 3.2,
172
+ e_tailer_selling_price_gross: 3.8,
173
+ e_tailer_selling_price_currency_code: 'USD'
174
+ )
175
+
176
+ response = genba_client.keys.get_report_usage([key])
177
+
178
+ response[:acceptedCount]
179
+ response[:rejectedCount]
180
+ ```
181
+
182
+ Report usage with key
183
+ ```ruby
184
+ key = KeyReportRequest.new(
185
+ key_id: '00000000-ffff-2222-3333-444444444444',
186
+ country_iso: 'US',
187
+ sale_date: DateTime.now,
188
+ user_ip_address: '182.212.212.22',
189
+ e_tailer_buying_price: 3.8,
190
+ e_tailer_buying_price_currency_code: 'USD',
191
+ e_tailer_selling_price_net: 3.2,
192
+ e_tailer_selling_price_gross: 3.8,
193
+ e_tailer_selling_price_currency_code: 'USD'
194
+ )
195
+ key_res = @client.keys.get_report_usage([key])
196
+ response = genba_client.keys.get_report_usage([key])
197
+
198
+ response[:acceptedCount]
199
+ response[:rejectedCount]
200
+ ```
201
+
202
+ ## DirectEntitlement
203
+
204
+ ### DirectEntitlement - Activate
205
+
206
+ Use this method to get and activate keys for a Direct Entitlement SKU. You will be charged at the point of calling this method.
207
+
208
+ ```ruby
209
+ payload = {
210
+ sku_id: 'd972e0c7-5ddb-4e0d-9138-a78a6b269e99',
211
+ country_iso: 'US',
212
+ end_user_ip_address: '182.212.212.22',
213
+ sale_date: DateTime.now,
214
+ end_user_id: '0000001',
215
+ end_user_ticket: 'ticket0000001',
216
+ e_tailer_buying_price: 18.29,
217
+ e_tailer_buying_price_currency_code: 'USD',
218
+ e_tailer_selling_price_net: 19.89,
219
+ e_tailer_selling_price_gross: 20.29,
220
+ e_tailer_selling_price_currency_code: 'USD',
221
+ }
222
+ key_res = @client.direct_entitlements.activate(payload)
223
+ ```
224
+
225
+ ### DirectEntitlement - Redeem
226
+
227
+ Use this method to redeem keys already sold for a Direct Entitlement SKU and link them to the end-user's account. You will not be charged at the point of calling this method.
228
+
229
+ ```ruby
230
+ payload = {
231
+ sku_id: 'd972e0c7-5ddb-4e0d-9138-a78a6b269e99',
232
+ key_id: '00000000-0000-0000-0000-000000000000',
233
+ end_user_id: '00001',
234
+ end_user_ticket: 'ticket00001'
235
+ }
236
+ key_res = @client.direct_entitlements.redeem(payload)
237
+ ```
data/Rakefile CHANGED
File without changes
data/circle.yml CHANGED
File without changes
data/genba.gemspec CHANGED
File without changes
data/lib/genba.rb CHANGED
@@ -2,21 +2,74 @@ require 'base64'
2
2
  require 'digest'
3
3
  require 'mcrypt'
4
4
  require 'rest-client'
5
+ require 'logger'
5
6
  require 'oj'
6
7
  require 'active_model'
7
8
 
8
9
  require 'genba/version'
9
10
  require 'genba/key_black_list_request'
10
11
  require 'genba/key_report_request'
12
+ require 'genba/util'
13
+ require 'genba/client/direct_entitlements'
11
14
  require 'genba/client/keys'
12
15
  require 'genba/client/prices'
13
16
  require 'genba/client/products'
17
+ require 'genba/client/reports'
14
18
  require 'genba/client/restrictions'
15
19
  require 'genba/client'
16
20
 
17
21
  # Genba API module
18
22
  module Genba
23
+ @logger = nil
24
+
25
+ # map to the same values as the standard library's logger
26
+ LEVEL_DEBUG = Logger::DEBUG
27
+ LEVEL_ERROR = Logger::ERROR
28
+ LEVEL_INFO = Logger::INFO
29
+
19
30
  def self.client(credentials = {})
20
31
  Client.new(credentials)
21
32
  end
33
+
34
+ # When set prompts the library to log some extra information to $stdout and
35
+ # $stderr about what it's doing. For example, it'll produce information about
36
+ # requests, responses, and errors that are received. Valid log levels are
37
+ # `debug` and `info`, with `debug` being a little more verbose in places.
38
+ #
39
+ # Use of this configuration is only useful when `.logger` is _not_ set. When
40
+ # it is, the decision what levels to print is entirely deferred to the logger.
41
+ def self.log_level
42
+ @log_level
43
+ end
44
+
45
+ def self.log_level=(val)
46
+ # Backwards compatibility for values that we briefly allowed
47
+ if val == 'debug'
48
+ val = LEVEL_DEBUG
49
+ elsif val == 'info'
50
+ val = LEVEL_INFO
51
+ end
52
+
53
+ if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
54
+ raise ArgumentError, "log_level should only be set to `nil`, `debug` or `info`"
55
+ end
56
+ @log_level = val
57
+ end
58
+
59
+ # Sets a logger to which logging output will be sent. The logger should
60
+ # support the same interface as the `Logger` class that's part of Ruby's
61
+ # standard library (hint, anything in `Rails.logger` will likely be
62
+ # suitable).
63
+ #
64
+ # If `.logger` is set, the value of `.log_level` is ignored. The decision on
65
+ # what levels to print is entirely deferred to the logger.
66
+ def self.logger
67
+ @logger
68
+ end
69
+
70
+ def self.logger=(val)
71
+ @logger = val
72
+ end
22
73
  end
74
+
75
+ Genba.log_level = ENV['GENBA_LOG'] unless ENV['GENBA_LOG'].nil?
data/lib/genba/client.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  module Genba
4
4
  # Genba API Client
5
5
  class Client
6
+ attr_accessor :customer_account_id
7
+
6
8
  API_URL = 'https://api.genbagames.com/api'.freeze
7
9
 
8
10
  @expires_on = nil
@@ -15,10 +17,11 @@ module Genba
15
17
  # * +config+ - Genba API credential attribute
16
18
  #
17
19
  # ==== Options
18
- def initialize(config = {})
19
- @app_id = config[:app_id]
20
- @username = config[:username]
21
- @api_key = config[:api_key]
20
+ def initialize(app_id:, username:, api_key:, customer_account_id:)
21
+ @app_id = app_id.strip
22
+ @username = username.strip
23
+ @api_key = api_key.strip
24
+ @customer_account_id = customer_account_id.strip
22
25
  end
23
26
 
24
27
  def generate_token
@@ -27,7 +30,7 @@ module Genba
27
30
  response = RestClient.post(
28
31
  "#{API_URL}/token",
29
32
  body,
30
- headers: { accept: 'application/json' }
33
+ headers: { accept: 'application/json', 'Content-Type': 'application/json' }
31
34
  )
32
35
  parsed_response = decode_json(response.body)
33
36
  @id_token = parsed_response['token']
@@ -38,19 +41,27 @@ module Genba
38
41
 
39
42
  def rest_get_with_token(path, query_params = {}, headers = {})
40
43
  genba_headers = token.merge(headers)
41
- headers[:params] = query_params unless query_params.empty?
42
- response = RestClient.get("#{API_URL}#{path}", genba_headers)
44
+ Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
45
+ api_url = "#{API_URL}#{path}"
46
+ api_url += "?#{query_params.to_query}" unless query_params.empty?
47
+ Genba::Util.log_info "api_url: #{api_url}"
48
+ response = RestClient.get(api_url, genba_headers)
43
49
  from_rest_client_response(response)
44
50
  end
45
51
 
46
52
  def rest_put_with_token(path, body = {}, headers = {})
47
53
  genba_headers = token.merge(headers)
54
+ Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
55
+ Genba::Util.log_info "api_url: #{API_URL}#{path}"
48
56
  response = RestClient.put("#{API_URL}#{path}", encode_json(body), genba_headers)
49
57
  from_rest_client_response(response)
50
58
  end
51
59
 
52
60
  def rest_post_with_token(path, body = {}, headers = {})
53
61
  genba_headers = token.merge(headers)
62
+ Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
63
+ Genba::Util.log_info "api_url: #{API_URL}#{path}"
64
+ Genba::Util.log_info "body: #{body}"
54
65
  response = RestClient.post("#{API_URL}#{path}", encode_json(body), genba_headers)
55
66
  from_rest_client_response(response)
56
67
  end
@@ -71,6 +82,14 @@ module Genba
71
82
  Keys.new(self)
72
83
  end
73
84
 
85
+ def direct_entitlements
86
+ DirectEntitlements.new(self)
87
+ end
88
+
89
+ def reports
90
+ Reports.new(self)
91
+ end
92
+
74
93
  private
75
94
 
76
95
  def encode_json(data)
@@ -97,7 +116,8 @@ module Genba
97
116
  {
98
117
  token: @id_token,
99
118
  appId: @app_id,
100
- accept: 'application/json'
119
+ accept: 'application/json',
120
+ 'Content-Type': 'application/json'
101
121
  }
102
122
  else
103
123
  {}
@@ -116,12 +136,15 @@ module Genba
116
136
  def from_rest_client_response(response)
117
137
  if response.code < 200 &&
118
138
  response.code >= 400
139
+ Genba::Util.log_error "Invalid response object from API: #{response.body}" \
140
+ "(HTTP response code was #{response.code})"
119
141
  raise "Invalid response object from API: #{response.body}" \
120
142
  "(HTTP response code was #{response.code})"
121
143
  end
122
144
  # default decode by json
123
145
  return decode_json(response.body) unless response.headers[:content_type]
124
- if (response.headers[:content_type] =~ %r{application\/json}) > 0
146
+ if (response.headers[:content_type] =~ %r{application\/json}) >= 0
147
+ Genba::Util.log_info "response body\n#{response.body}"
125
148
  decode_json(response.body)
126
149
  end
127
150
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ # DirectEntitlements client
6
+ class DirectEntitlements
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def activate(
12
+ sku_id:,
13
+ country_iso:,
14
+ end_user_ip_address:,
15
+ sale_date: DateTime.now,
16
+ end_user_id: nil,
17
+ end_user_ticket: nil,
18
+ e_tailer_buying_price:,
19
+ e_tailer_buying_price_currency_code:,
20
+ e_tailer_selling_price_net:,
21
+ e_tailer_selling_price_gross:,
22
+ e_tailer_selling_price_currency_code:,
23
+ headers: {}
24
+ )
25
+ params = {
26
+ skuId: sku_id,
27
+ customerAccountId: @client.customer_account_id,
28
+ countryISO: country_iso,
29
+ endUserIpAddress: end_user_ip_address,
30
+ endUserId: end_user_id,
31
+ endUserTicket: end_user_ticket,
32
+ ETailerBuyingPrice: e_tailer_buying_price,
33
+ ETailerBuyingPriceCurrencyCode: e_tailer_buying_price_currency_code,
34
+ ETailerSellingPriceNet: e_tailer_selling_price_net,
35
+ ETailerSellingPriceGross: e_tailer_selling_price_gross,
36
+ ETailerSellingPriceCurrencyCode: e_tailer_selling_price_currency_code
37
+ }.select { |_, v| !v.nil? }
38
+ params[:saleDate] = sale_date.strftime('%FT%T') if sale_date
39
+ Genba::Util.log_debug "DirectEntitlements activate payload: #{params.inspect}"
40
+ @client.rest_get_with_token('/directentitlement/activate', params, headers)
41
+ end
42
+
43
+ # Use this method to redeem keys already sold for a Direct Entitlement SKU and link them to the
44
+ # end-user's account. You will not be charged at the point of calling this method.
45
+ def redeem(sku_id:, key_id:, end_user_id:, end_user_ticket:, headers: {})
46
+ params = {
47
+ customerAccountId: @client.customer_account_id,
48
+ skuId: sku_id,
49
+ keyId: key_id,
50
+ endUserId: end_user_id,
51
+ endUserTicket: end_user_ticket
52
+ }
53
+ @client.rest_get_with_token('/directentitlement/redeem', params, headers)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -18,7 +18,8 @@ module Genba
18
18
  def get_keys(sku_id, quantity = 1, params = {}, headers = {})
19
19
  payload = params.merge(
20
20
  skuId: sku_id,
21
- quantity: quantity
21
+ quantity: quantity,
22
+ customerAccountId: @client.customer_account_id
22
23
  )
23
24
  @client.rest_get_with_token('/keys', payload, headers)
24
25
  end
@@ -31,16 +32,14 @@ module Genba
31
32
  end
32
33
 
33
34
  def get_key_status(key_id, params = {}, headers = {})
34
- payload = params.merge(
35
- id: key_id
36
- )
37
- @client.rest_get_with_token('/keys', payload, headers)
35
+ @client.rest_get_with_token("/keys/#{key_id}", params, headers)
38
36
  end
39
37
 
40
38
  def get_report_usage(keys = nil, headers = {})
41
39
  raise 'ReportUsage keys should be array' unless keys.is_a?(Array)
42
40
  raise 'ReportUseag keys should be a KeyReportRequest class' unless key_report_request?(keys)
43
41
  payload = keys.map(&:to_genba_json_payload)
42
+ Genba::Util.log_debug "get_report_usage payload: #{payload.inspect}"
44
43
  @client.rest_post_with_token('/keyReport', payload, headers)
45
44
  end
46
45
 
@@ -8,11 +8,11 @@ module Genba
8
8
  @client = client
9
9
  end
10
10
 
11
- def get_prices(customer_account_id, headers = {})
12
- params = {
13
- customerAccountId: customer_account_id
14
- }
15
- @client.rest_get_with_token('/prices', params, headers)
11
+ def get_prices(params = {}, headers = {})
12
+ payload = params.merge(
13
+ customerAccountId: @client.customer_account_id
14
+ )
15
+ @client.rest_get_with_token('/prices', payload, headers)
16
16
  end
17
17
  end
18
18
  end
@@ -8,19 +8,32 @@ module Genba
8
8
  @client = client
9
9
  end
10
10
 
11
- def get_products(params = {}, headers = {})
12
- @client.rest_get_with_token('/product', params, headers)
11
+ def get_products(sku_id: nil, country_iso: nil, include_meta: false, headers: {})
12
+ payload = {
13
+ skuId: sku_id,
14
+ countryISO: country_iso,
15
+ includeMeta: include_meta
16
+ }.select { |_, v| !v.nil? }
17
+
18
+ @client.rest_get_with_token('/product', payload, headers)
13
19
  end
14
20
 
15
- def get_changes(from_date, params = {}, headers = {})
21
+ def get_changes(from_date: nil, country_iso: nil, include_meta: false, params: {}, headers: {})
16
22
  payload = params.merge(
17
- fromDate: from_date
18
- )
23
+ countryISO: country_iso,
24
+ includeMeta: include_meta
25
+ ).select { |_, v| !v.nil? }
26
+ payload[:fromDate] = from_date.strftime('%FT%T') if from_date
19
27
  @client.rest_get_with_token('/product/changes', payload, headers)
20
28
  end
21
29
 
22
- def get_removed(params = {}, headers = {})
23
- @client.rest_get_with_token('/product/removed', params, headers)
30
+ def get_removed(from_date: nil, country_iso: nil, params: {}, headers: {})
31
+ payload = params.merge(
32
+ countryISO: country_iso,
33
+ customerAccountId: @client.customer_account_id
34
+ ).select { |_, v| !v.nil? }
35
+ payload[:fromDate] = from_date.strftime('%FT%T') if from_date
36
+ @client.rest_get_with_token('/product/removed', payload, headers)
24
37
  end
25
38
  end
26
39
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ # Reports client
6
+ class Reports
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def publisher_raw_data(year = nil, params = {}, headers = {})
12
+ payload = params.merge({
13
+ Year: year || Time.now.strftime('%Y')
14
+ })
15
+ @client.rest_get_with_token('/report/publisher/rawdata', payload, headers)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,8 +8,13 @@ module Genba
8
8
  @client = client
9
9
  end
10
10
 
11
- def get_restrictions(params = {}, headers = {})
12
- @client.rest_get_with_token('/restrictions', params, headers)
11
+ def get_restrictions(product_id: nil, country_iso: nil, from_date: nil, params: {}, headers: {})
12
+ payload = params.merge(
13
+ productId: product_id,
14
+ countryISO: country_iso
15
+ ).select { |_, v| !v.nil? }
16
+ payload[:fromDate] = from_date.strftime('%FT%T') if from_date
17
+ @client.rest_get_with_token('/restrictions', payload, headers)
13
18
  end
14
19
  end
15
20
  end
File without changes
@@ -7,19 +7,29 @@ class KeyReportRequest
7
7
  :e_tailer_selling_price_net, :e_tailer_selling_price_gross,
8
8
  :e_tailer_selling_price_currency_code
9
9
 
10
- def initialize(data = {})
11
- @key = data[:key]
12
- @key_id = data[:key_id]
13
- @country_iso = data[:country_iso]
14
- @user_ip_address = data[:user_ip_address]
10
+ def initialize(
11
+ key: nil, key_id: nil, country_iso:, user_ip_address:, sale_date: nil,
12
+ e_tailer_buying_price:, e_tailer_buying_price_currency_code:,
13
+ e_tailer_selling_price_net:, e_tailer_selling_price_gross:, e_tailer_selling_price_currency_code:
14
+ )
15
+ @key = key
16
+ @key_id = key_id
17
+ @country_iso = country_iso
18
+ @user_ip_address = user_ip_address
19
+ @sale_date = sale_date
20
+ @e_tailer_buying_price = e_tailer_buying_price
21
+ @e_tailer_buying_price_currency_code = e_tailer_buying_price_currency_code
22
+ @e_tailer_selling_price_net = e_tailer_selling_price_net
23
+ @e_tailer_selling_price_gross = e_tailer_selling_price_gross
24
+ @e_tailer_selling_price_currency_code = e_tailer_selling_price_currency_code
25
+ raise 'at least one of key or key_id' if key.nil? && key_id.nil?
15
26
  end
16
27
 
17
28
  def to_genba_json_payload
18
- {
29
+ payload ={
19
30
  key: @key,
20
31
  keyId: @key_id,
21
32
  countryISO: @country_iso,
22
- saleDate: @sale_date,
23
33
  userIpAddress: @user_ip_address,
24
34
  ETailerBuyingPrice: @e_tailer_buying_price,
25
35
  ETailerBuyingPriceCurrencyCode: @e_tailer_buying_price_currency_code,
@@ -27,5 +37,8 @@ class KeyReportRequest
27
37
  ETailerSellingPriceGross: @e_tailer_selling_price_gross,
28
38
  ETailerSellingPriceCurrencyCode: @e_tailer_selling_price_currency_code
29
39
  }.select { |_, v| !v.nil? }
40
+
41
+ payload[:saleDate] = @sale_date.strftime('%FT%T') if @sale_date
42
+ payload
30
43
  end
31
44
  end
data/lib/genba/util.rb ADDED
@@ -0,0 +1,109 @@
1
+ require 'cgi'
2
+
3
+ module Genba
4
+ module Util
5
+ def self.log_error(message, data = {})
6
+ if !Genba.logger.nil? ||
7
+ !Genba.log_level.nil? && Genba.log_level <= Genba::LEVEL_ERROR
8
+ log_internal(message, data, color: :cyan,
9
+ level: Genba::LEVEL_ERROR, logger: Genba.logger, out: $stderr)
10
+ end
11
+ end
12
+
13
+ def self.log_info(message, data = {})
14
+ if !Genba.logger.nil? ||
15
+ !Genba.log_level.nil? && Genba.log_level <= Genba::LEVEL_INFO
16
+ log_internal(message, data, color: :cyan,
17
+ level: Genba::LEVEL_INFO, logger: Genba.logger, out: $stdout)
18
+ end
19
+ end
20
+
21
+ def self.log_debug(message, data = {})
22
+ if !Genba.logger.nil? ||
23
+ !Genba.log_level.nil? && Genba.log_level <= Genba::LEVEL_DEBUG
24
+ log_internal(message, data, color: :blue,
25
+ level: Genba::LEVEL_DEBUG, logger: Genba.logger, out: $stdout)
26
+ end
27
+ end
28
+
29
+ COLOR_CODES = {
30
+ black: 0, light_black: 60,
31
+ red: 1, light_red: 61,
32
+ green: 2, light_green: 62,
33
+ yellow: 3, light_yellow: 63,
34
+ blue: 4, light_blue: 64,
35
+ magenta: 5, light_magenta: 65,
36
+ cyan: 6, light_cyan: 66,
37
+ white: 7, light_white: 67,
38
+ default: 9,
39
+ }.freeze
40
+ private_constant :COLOR_CODES
41
+
42
+ # Uses an ANSI escape code to colorize text if it's going to be sent to a
43
+ # TTY.
44
+ def self.colorize(val, color, isatty)
45
+ return val unless isatty
46
+
47
+ mode = 0 # default
48
+ foreground = 30 + COLOR_CODES.fetch(color)
49
+ background = 40 + COLOR_CODES.fetch(:default)
50
+
51
+ "\033[#{mode};#{foreground};#{background}m#{val}\033[0m"
52
+ end
53
+ private_class_method :colorize
54
+
55
+ # Turns an integer log level into a printable name.
56
+ def self.level_name(level)
57
+ case level
58
+ when LEVEL_DEBUG then 'debug'
59
+ when LEVEL_ERROR then 'error'
60
+ when LEVEL_INFO then 'info'
61
+ else level
62
+ end
63
+ end
64
+ private_class_method :level_name
65
+
66
+ # TODO: Make these named required arguments when we drop support for Ruby
67
+ # 2.0.
68
+ def self.log_internal(message, data = {}, color: nil, level: nil, logger: nil, out: nil)
69
+ data_str = data.reject { |_k, v| v.nil? }
70
+ .map do |(k, v)|
71
+ format("%s=%s", colorize(k, color, logger.nil? && !out.nil? && out.isatty), wrap_logfmt_value(v))
72
+ end.join(' ')
73
+
74
+ if !logger.nil?
75
+ # the library's log levels are mapped to the same values as the
76
+ # standard library's logger
77
+ logger.log(level, message)
78
+ elsif out.isatty
79
+ out.puts format("%s %s %s", colorize(level_name(level)[0, 4].upcase, color, out.isatty), message, data_str)
80
+ else
81
+ out.puts format("message=%s level=%s %s", wrap_logfmt_value(message), level_name(level), data_str)
82
+ end
83
+ end
84
+ private_class_method :log_internal
85
+
86
+ # Wraps a value in double quotes if it looks sufficiently complex so that
87
+ # it can be read by logfmt parsers.
88
+ def self.wrap_logfmt_value(val)
89
+ # If value is any kind of number, just allow it to be formatted directly
90
+ # to a string (this will handle integers or floats).
91
+ return val if val.is_a?(Numeric)
92
+
93
+ # Hopefully val is a string, but protect in case it's not.
94
+ val = val.to_s
95
+
96
+ if %r{[^\w\-/]} =~ val
97
+ # If the string contains any special characters, escape any double
98
+ # quotes it has, remove newlines, and wrap the whole thing in quotes.
99
+ format(%("%s"), val.gsub('"', '\"').delete("\n"))
100
+ else
101
+ # Otherwise use the basic value if it looks like a standard set of
102
+ # characters (and allow a few special characters like hyphens, and
103
+ # slashes)
104
+ val
105
+ end
106
+ end
107
+ private_class_method :wrap_logfmt_value
108
+ end
109
+ end
data/lib/genba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Genba
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -114,14 +114,19 @@ files:
114
114
  - bin/setup
115
115
  - circle.yml
116
116
  - genba.gemspec
117
+ - lib/.DS_Store
117
118
  - lib/genba.rb
119
+ - lib/genba/.DS_Store
118
120
  - lib/genba/client.rb
121
+ - lib/genba/client/direct_entitlements.rb
119
122
  - lib/genba/client/keys.rb
120
123
  - lib/genba/client/prices.rb
121
124
  - lib/genba/client/products.rb
125
+ - lib/genba/client/reports.rb
122
126
  - lib/genba/client/restrictions.rb
123
127
  - lib/genba/key_black_list_request.rb
124
128
  - lib/genba/key_report_request.rb
129
+ - lib/genba/util.rb
125
130
  - lib/genba/version.rb
126
131
  homepage: https://api.genbagames.com/doc/
127
132
  licenses:
@@ -144,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
149
  version: '0'
145
150
  requirements: []
146
151
  rubyforge_project:
147
- rubygems_version: 2.6.14
152
+ rubygems_version: 2.7.7
148
153
  signing_key:
149
154
  specification_version: 4
150
155
  summary: genba api for ruby version