genba 0.1.12 → 0.2.0

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: 3e0eb327252630e8364197fc6364be7c107aba4dde3d9d447ef7e99a0ebebe6a
4
- data.tar.gz: b2b338539902fd1ed45f6e79077c999282cd21c76b6e99c33d1c16783500da4f
3
+ metadata.gz: 793387fb5c72045ad8ead98d5ee9b49e7aa249b82bab44544053714bd1e175f0
4
+ data.tar.gz: 6bfc0526bbd8de64c1bb0b852f3d8053526837b80183d4e66967918cc9e253db
5
5
  SHA512:
6
- metadata.gz: 6db62be86e2459c27a52a47d2ba489efaa44e4d731ff5940e9b28e48d233f7744f5d4061deddbc6b18c63d46fc647a621bc0a57cc427b58af5e2547c2915698e
7
- data.tar.gz: a91bc06963b45a3e44d3fedd23bb2bfd0d319d77b96b30bbbff8edbc92fb9d20dbbb6b03cf99e3356efe0f53c36efbac8ae60a4f8150d9160bea3402b31bde92
6
+ metadata.gz: 39ea2725c23c6a6fe92300b6f127c96e86f257e89ef04736e41d297d4446cb709f952dc549618f583af56cc74109884488bd77f0e340ffd70ab99f438935b8c0
7
+ data.tar.gz: 397670a04d99f73bd1948bfa4f65cf5313d636e74e8f0466779ed394b24967e9b743f900f126e331529e4d799cf8f1388dd244c937d060db34c10f1e98688bf6
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- genba (0.1.12)
4
+ genba (0.2.0)
5
+ dry-validation (~> 0.11.0)
6
+ jwt (~> 1.5)
5
7
  oj (~> 3.5)
6
8
  rest-client (~> 2.0)
7
- ruby-mcrypt (= 0.2.0)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -20,17 +21,46 @@ GEM
20
21
  public_suffix (>= 2.0.2, < 4.0)
21
22
  byebug (10.0.2)
22
23
  coderay (1.1.2)
23
- concurrent-ruby (1.0.5)
24
+ concurrent-ruby (1.1.5)
24
25
  crack (0.4.3)
25
26
  safe_yaml (~> 1.0.0)
26
27
  diff-lcs (1.3)
27
- domain_name (0.5.20180417)
28
+ domain_name (0.5.20190701)
28
29
  unf (>= 0.0.5, < 1.0.0)
30
+ dry-configurable (0.7.0)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-container (0.6.0)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-configurable (~> 0.1, >= 0.1.3)
35
+ dry-core (0.4.8)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-equalizer (0.2.2)
38
+ dry-logic (0.4.2)
39
+ dry-container (~> 0.2, >= 0.2.6)
40
+ dry-core (~> 0.2)
41
+ dry-equalizer (~> 0.2)
42
+ dry-types (0.12.3)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-configurable (~> 0.1)
45
+ dry-container (~> 0.3)
46
+ dry-core (~> 0.2, >= 0.2.1)
47
+ dry-equalizer (~> 0.2)
48
+ dry-logic (~> 0.4, >= 0.4.2)
49
+ inflecto (~> 0.0.0, >= 0.0.2)
50
+ dry-validation (0.11.2)
51
+ concurrent-ruby (~> 1.0)
52
+ dry-configurable (~> 0.1, >= 0.1.3)
53
+ dry-core (~> 0.2, >= 0.2.1)
54
+ dry-equalizer (~> 0.2)
55
+ dry-logic (~> 0.4.2)
56
+ dry-types (~> 0.12.0)
29
57
  hashdiff (0.3.7)
30
58
  http-cookie (1.0.3)
31
59
  domain_name (~> 0.5)
32
60
  i18n (1.0.1)
33
61
  concurrent-ruby (~> 1.0)
62
+ inflecto (0.0.2)
63
+ jwt (1.5.6)
34
64
  method_source (0.9.0)
35
65
  mime-types (3.2.2)
36
66
  mime-types-data (~> 3.2015)
@@ -63,7 +93,6 @@ GEM
63
93
  diff-lcs (>= 1.2.0, < 2.0)
64
94
  rspec-support (~> 3.7.0)
65
95
  rspec-support (3.7.1)
66
- ruby-mcrypt (0.2.0)
67
96
  safe_yaml (1.0.4)
68
97
  thread_safe (0.3.6)
69
98
  tzinfo (1.2.5)
data/README.md CHANGED
@@ -4,234 +4,43 @@
4
4
  [![CircleCI](https://circleci.com/gh/iscreen/genba-ruby.svg?style=svg)](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 V3](https://sandbox.genbadigital.io/doc) from applications written in the Ruby language.
8
+ * [Genba Digital](https://genbadigital.com/)
9
+ * [Genba API V2](https://api.genbagames.com/doc/)
10
+ * [Genba API V3 Sandbox](https://sandbox.genbadigital.io/doc/)
11
+ * [Genba API V3 Production](https://unknown.genbadigital.io/doc)
8
12
 
9
13
  ## Basic Usage
10
14
 
11
15
  ```ruby
12
- require 'genba'
16
+ require 'genba-ruby'
13
17
 
14
- genba_client = Genba.client(
15
- username: 'api_genba_user',
16
- app_id: '00000000-0000-0000-0000-000000000000',
17
- api_key: '00000000000000000000000000000000',
18
- customer_account_id: '00000000-0000-0000-0000-000000000000'
19
- )
20
- ```
21
-
22
- ## Products
23
- [Genba Products API](https://api.genbagames.com/doc/#api-Product)
24
-
25
- ### Product - Changes
26
-
27
- Return a list of products which have changed since a given date, including basic or advanced metadata.
28
-
29
- ```ruby
30
- payload = {
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
54
- }
55
-
56
- response = genba_client.products.get_products(payload)
57
- ```
58
-
59
- Return a list of product objects with countryISO
60
-
61
- ```ruby
62
- payload = {
63
- country_iso: 'US',
64
- include_meta: false
65
- }
66
-
67
- response = genba_client.products.get_products(payload)
68
- ```
69
-
70
- Retrieve an existing product
71
-
72
- ```ruby
73
- payload = {
74
- sku_id: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
75
- include_meta: true
76
- }
77
-
78
- product = genba_client.products.get_products(payload)
18
+ GENBA = Genba.client(
19
+ resource: 'resource-0000-0000-0000-000000000000',
20
+ account_id: 'account0-0000-0000-0000-000000000000',
21
+ cert: 'your.domain.crt',
22
+ key: 'your.domain.key',
23
+ sandbox: true # default: false
24
+ )
79
25
  ```
80
26
 
81
- ### Product - Removed
82
-
83
- Return a list of products which have been removed since a given date.
84
-
85
- ```ruby
86
- payload = {
87
- from_date: DateTime.now - 1,
88
- country_iso: 'US',
89
- include_meta: false
90
- }
27
+ ## Ping
28
+ [Genba Ping API](https://sandbox.genbadigital.io/doc/#/Ping)
91
29
 
92
- response = genba_client.products.get_removed(payload)
93
- ```
30
+ ## Products
31
+ [Genba Products API](https://sandbox.genbadigital.io/doc/#/Products)
94
32
 
95
33
  ## Prices
96
- [Genba Prices API](https://api.genbagames.com/doc/#api-Prices)
97
-
98
- Get latest prices for all of your available products. It is recommended that you call this daily to get accurate pricing.
99
-
100
- ```ruby
101
- response = genba_client.prices.get_prices
102
- ```
103
-
104
- ## Restrictions
105
- [Genba Restrictions API](https://api.genbagames.com/doc/#api-Restrictions)
106
-
107
- ### Restrictions - Get
108
-
109
- Returns a list of product sku restrictions, whitelist - can only sold in countries, blacklist - cannot be sold in countries.
110
-
111
- Returns a list of product sku restrictions by countryISO
34
+ [Genba Prices API](https://sandbox.genbadigital.io/doc/#/Prices)
112
35
 
113
- ```ruby
114
- payload = {
115
- country_iso: 'US'
116
- }
117
-
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)
132
- response[:productRestriction]
133
- ```
134
-
135
- ## Keys
136
- [Genba Keys API](https://api.genbagames.com/doc/#api-Keys)
137
-
138
- ### Keys - Get Test Keys
139
-
140
- Request Product Test Keys for a SKU
141
-
142
- ```ruby
143
- response = genba_client.keys.get_test_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577')
144
-
145
- response[:status]
146
- response[:keys]
147
- ```
148
-
149
- Request Product Keys for a SKU
150
-
151
- ```ruby
152
-
153
- response = genba_client.keys.get_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577', 1, customerAccountId)
154
-
155
- response[:status]
156
- response[:keys]
157
- ```
36
+ ## Promotions
37
+ [Genba Promotions API](https://sandbox.genbadigital.io/doc/#/Promotions)
158
38
 
159
- ### Keys - Report Usage
39
+ ## Reservations
40
+ [Genba Reservations API](https://sandbox.genbadigital.io/doc/#/Reservations)
160
41
 
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
- ```
42
+ ## Orders
43
+ [Genba Orders API](https://sandbox.genbadigital.io/doc/#/Orders)
201
44
 
202
45
  ## 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
- ```
46
+ [Genba DirectEntitlement API](https://sandbox.genbadigital.io/doc/#/DirectEntitlement)
@@ -32,7 +32,8 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_runtime_dependency 'oj', '~> 3.5'
34
34
  spec.add_runtime_dependency 'rest-client', '~> 2.0'
35
- spec.add_runtime_dependency 'ruby-mcrypt', '0.2.0'
35
+ spec.add_runtime_dependency 'jwt', '~> 1.5'
36
+ spec.add_runtime_dependency 'dry-validation', '~> 0.11.0'
36
37
 
37
38
  spec.add_development_dependency 'bundler', '~> 1.16'
38
39
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,21 +1,29 @@
1
1
  require 'base64'
2
2
  require 'digest'
3
- require 'mcrypt'
3
+ require 'jwt'
4
4
  require 'rest-client'
5
5
  require 'logger'
6
6
  require 'oj'
7
7
  require 'active_model'
8
+ require 'dry-validation'
8
9
 
9
10
  require 'genba/version'
10
- require 'genba/key_black_list_request'
11
- require 'genba/key_report_request'
11
+ require 'genba/reservation_request'
12
+ require 'genba/order_request'
13
+ require 'genba/action_request'
14
+ require 'genba/activation_request'
15
+ require 'genba/redemption_request'
16
+
12
17
  require 'genba/util'
13
- require 'genba/client/direct_entitlements'
14
- require 'genba/client/keys'
15
- require 'genba/client/prices'
18
+ require 'genba/client/ping'
16
19
  require 'genba/client/products'
17
- require 'genba/client/reports'
18
- require 'genba/client/restrictions'
20
+ require 'genba/client/prices'
21
+ require 'genba/client/promotions'
22
+ require 'genba/client/reservations'
23
+ require 'genba/client/orders'
24
+ require 'genba/client/direct_entitlement'
25
+ require 'genba/client/direct_entitlements/activations'
26
+ require 'genba/client/direct_entitlements/redemptions'
19
27
  require 'genba/client'
20
28
 
21
29
  # Genba API module
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class ActionRequest
5
+ def initialize
6
+ @schema = Dry::Validation.Schema do
7
+ required(:Action).filled(:str?)
8
+ optional(:Reason).filled(:str?)
9
+ end
10
+ end
11
+
12
+ def call(data)
13
+ @schema.call(data)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class ActivationRequest
5
+ def initialize
6
+ @schema = Dry::Validation.Schema do
7
+ required(:ClientTransactionID).filled(:str?)
8
+ optional(:EtailerID).filled(:str?)
9
+ required(:Activation).schema do
10
+ required(:Sku).filled(:str?)
11
+ required(:CountryCode).filled(:str?)
12
+ optional(:ConsumerIP).maybe(:str?)
13
+ optional(:BuyingPrice).schema do
14
+ required(:Amount).filled(:float?)
15
+ required(:CurrencyCode).filled(:str?)
16
+ end
17
+ required(:SellingPrice).schema do
18
+ required(:NetAmount).filled(:float?)
19
+ required(:GrossAmount).filled(:float?)
20
+ required(:CurrencyCode).filled(:str?)
21
+ end
22
+ optional(:EtailerID).filled(:str?)
23
+ end
24
+ optional(:Redemption).schema do
25
+ required(:EndUserID).filled(:str?)
26
+ required(:EndUserTicket).filled(:str?)
27
+ end
28
+ end
29
+ end
30
+
31
+ def call(data)
32
+ @schema.call(data)
33
+ end
34
+ end
35
+ end
@@ -6,7 +6,8 @@ module Genba
6
6
  attr_accessor :customer_account_id,
7
7
  :open_timeout, :read_timeout, :max_retry, :retry_delay
8
8
 
9
- API_URL = 'https://api.genbagames.com/api'.freeze
9
+ SANDBOX_API_URL = 'https://sandbox.genbadigital.io/api/v3-0'.freeze
10
+ PRODUCTION_API_URL = 'https://api.genbadigital.io/api/v3-0'.freeze
10
11
 
11
12
  @expires_on = nil
12
13
  @id_token = nil
@@ -18,11 +19,16 @@ module Genba
18
19
  # * +config+ - Genba API credential attribute
19
20
  #
20
21
  # ==== Options
21
- def initialize(app_id:, username:, api_key:, customer_account_id:, options: {})
22
- @app_id = app_id.strip
23
- @username = username.strip
24
- @api_key = api_key.strip
25
- @customer_account_id = customer_account_id.strip
22
+ def initialize(resource:, account_id:, cert:, key:, sandbox: false, options: {})
23
+ @api_url = sandbox ? SANDBOX_API_URL : PRODUCTION_API_URL
24
+ @resource = resource
25
+ @account_id = account_id
26
+ @cert = cert
27
+ @key = key
28
+ @tenant = 'aad.genbadigital.io'
29
+ @authority_url = "https://login.microsoftonline.com/#{@tenant}"
30
+ @client_id = "https://aad-snd.genbadigital.io/#{@account_id}"
31
+
26
32
  @open_timeout = options[:open_timeout] || 15
27
33
  @read_timeout = options[:read_timeout] || 60
28
34
  @max_retry = options[:max_retry] || 0
@@ -31,22 +37,42 @@ module Genba
31
37
 
32
38
  def generate_token
33
39
  unless token_valid?
34
- body = { appId: @app_id, signature: genba_signature }
40
+ certificate = OpenSSL::X509::Certificate.new File.open(@cert)
41
+ x5t = Base64.encode64 OpenSSL::Digest::SHA1.new(certificate.to_der).digest
42
+ payload = {
43
+ exp: (Time.now + 60*60*24).to_i,
44
+ aud: "#{@authority_url}/oauth2/token",
45
+ iss: @client_id,
46
+ sub: @client_id,
47
+ }
48
+ rsa_private = OpenSSL::PKey::RSA.new File.open(@key)
49
+ token = JWT.encode payload, rsa_private, 'RS256', { x5t: x5t }
50
+
51
+ body = {
52
+ resource: @resource,
53
+ client_id: @client_id,
54
+ grant_type: 'client_credentials',
55
+ scope: 'https://graph.microsoft.com/.default',
56
+ client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
57
+ client_assertion: token,
58
+ tenant: @tenant
59
+ }
60
+
35
61
  response = RestClient.post(
36
- "#{API_URL}/token",
62
+ "#{@authority_url}/oauth2/token",
37
63
  body,
38
64
  headers: { accept: 'application/json', 'Content-Type': 'application/json' }
39
65
  )
40
66
  parsed_response = decode_json(response.body)
41
- @id_token = parsed_response['token']
42
- @expires_on = Time.parse(parsed_response['expiration'])
67
+ @id_token = parsed_response['access_token']
68
+ @expires_on = Time.at(parsed_response['expires_on'].to_i)
43
69
  end
44
70
  raw_token
45
71
  end
46
72
 
47
73
  def rest_get_with_token(path, query_params = {}, headers = {}, options = {})
48
74
  genba_headers = token.merge(headers)
49
- api_url = "#{API_URL}#{path}"
75
+ api_url = "#{@api_url}#{path}"
50
76
  api_url += "?#{query_params.to_query}" unless query_params.empty?
51
77
  response = execute_request(method: :get, url: api_url,
52
78
  headers: genba_headers, options: options)
@@ -55,14 +81,14 @@ module Genba
55
81
 
56
82
  def rest_put_with_token(path, body = {}, headers = {}, options = {})
57
83
  genba_headers = token.merge(headers)
58
- response = execute_request(method: :put, url: "#{API_URL}#{path}",
84
+ response = execute_request(method: :put, url: "#{@api_url}#{path}",
59
85
  payload: encode_json(body), headers: genba_headers, options: options)
60
86
  from_rest_client_response(response)
61
87
  end
62
88
 
63
89
  def rest_post_with_token(path, body = {}, headers = {}, options = {})
64
90
  genba_headers = token.merge(headers)
65
- response = execute_request(method: :post, url: "#{API_URL}#{path}",
91
+ response = execute_request(method: :post, url: "#{@api_url}#{path}",
66
92
  payload: encode_json(body), headers: genba_headers, options: options)
67
93
  from_rest_client_response(response)
68
94
  end
@@ -93,7 +119,13 @@ module Genba
93
119
  num_try = 0
94
120
  begin
95
121
  response = RestClient::Request.execute(request_opts)
96
- rescue StandardError => e
122
+ rescue RestClient::Exception, SocketError, Errno::ECONNREFUSED, NoMethodError => e
123
+ if e.class.parent == RestClient && valid_json?(e.http_body)
124
+ Genba::Util.log_error "#{e.class} => #{e.message}\n#{e.http_body}"
125
+ raise e
126
+ # response = OpenStruct.new(code: e.http_code, body: e.http_body, headers: {})
127
+ # return response
128
+ end
97
129
  Genba::Util.log_error "#{e.class} => #{e.message}"
98
130
 
99
131
  num_try += 1
@@ -109,6 +141,17 @@ module Genba
109
141
  response
110
142
  end
111
143
 
144
+ def valid_json?(json)
145
+ JSON.parse(json)
146
+ return true
147
+ rescue JSON::ParserError => e
148
+ return false
149
+ end
150
+
151
+ def ping
152
+ Ping.new(self)
153
+ end
154
+
112
155
  def products
113
156
  Products.new(self)
114
157
  end
@@ -117,20 +160,20 @@ module Genba
117
160
  Prices.new(self)
118
161
  end
119
162
 
120
- def restrictions
121
- Restrictions.new(self)
163
+ def promotions
164
+ Promotions.new(self)
122
165
  end
123
166
 
124
- def keys
125
- Keys.new(self)
167
+ def reservations
168
+ Reservations.new(self)
126
169
  end
127
170
 
128
- def direct_entitlements
129
- DirectEntitlements.new(self)
171
+ def orders
172
+ Orders.new(self)
130
173
  end
131
174
 
132
- def reports
133
- Reports.new(self)
175
+ def direct_entitlement
176
+ DirectEntitlement.new(self)
134
177
  end
135
178
 
136
179
  private
@@ -143,22 +186,10 @@ module Genba
143
186
  Oj.load(json)
144
187
  end
145
188
 
146
- def genba_signature
147
- cipher = Mcrypt.new(
148
- :rijndael_256,
149
- :cbc,
150
- Digest::SHA256.digest(@username),
151
- Digest::SHA256.digest(@app_id)
152
- )
153
- encrypted = cipher.encrypt(@api_key)
154
- Base64.strict_encode64(encrypted)
155
- end
156
-
157
189
  def raw_token
158
190
  if token_valid?
159
191
  {
160
- token: @id_token,
161
- appId: @app_id,
192
+ Authorization: "Bearer #{@id_token}",
162
193
  accept: 'application/json',
163
194
  'Content-Type': 'application/json'
164
195
  }
@@ -177,8 +208,7 @@ module Genba
177
208
  end
178
209
 
179
210
  def from_rest_client_response(response)
180
- if response.code < 200 &&
181
- response.code >= 400
211
+ if response.code < 200
182
212
  Genba::Util.log_error "Invalid response object from API: #{response.body}" \
183
213
  "(HTTP response code was #{response.code})"
184
214
  raise "Invalid response object from API: #{response.body}" \
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ # DirectEntitlements client
6
+ class DirectEntitlement
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def activations
12
+ DirectEntitlement::Activations.new(@client)
13
+ end
14
+
15
+ def redemptions
16
+ DirectEntitlement::Redemptions.new(@client)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class DirectEntitlement
6
+ # DirectEntitlement Activations client
7
+ class Activations
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # Perform a direct entitlement activation
13
+ def perform(activation_request, headers: {}, options: {})
14
+ errors = Genba::ActivationRequest.new.call(activation_request).messages
15
+ raise errors.inspect unless errors.empty?
16
+
17
+ @client.rest_post_with_token('/directentitlement/activations', activation_request, headers, options)
18
+ end
19
+
20
+ # Retrieve a direct entitlement activation
21
+ def get(activation_id, headers: {})
22
+ @client.rest_get_with_token("/directentitlement/activations/#{activation_id}", {}, headers)
23
+ end
24
+
25
+ # Perform an action on an activation
26
+ def perform_action(activation_id, action_request, headers: {}, options: {})
27
+ errors = Genba::ActionRequest.new.call(action_request).messages
28
+ raise errors.inspect unless errors.empty?
29
+
30
+ @client.rest_post_with_token("/directentitlement/activations/#{activation_id}", action_request, headers)
31
+ end
32
+
33
+ # Retrieve a direct entitlement activation by its Client Transaction ID
34
+ def get_by_ctid(ctid, headers: {})
35
+ @client.rest_get_with_token("/directentitlement/activations/ctid/#{ctid}", {}, headers)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class DirectEntitlement
6
+ # DirectEntitlement Redemptions client
7
+ class Redemptions
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # Perform a direct entitlement redemption
13
+ def perform(redemption_request, headers: {}, options: {})
14
+ errors = Genba::RedemptionRequest.new.call(redemption_request).messages
15
+ raise errors.inspect unless errors.empty?
16
+
17
+ @client.rest_post_with_token('/directentitlement/redemptions', redemption_request, headers, options)
18
+ end
19
+
20
+ # Retrieve a direct entitlement redemption
21
+ def get(redemption_id, headers: {})
22
+ @client.rest_get_with_token("/directentitlement/redemptions/#{redemption_id}", {}, headers)
23
+ end
24
+
25
+ # Perform an action on an redemption
26
+ def perform_action(redemption_id, action_request, headers: {}, options: {})
27
+ errors = Genba::ActionRequest.new.call(action_request).messages
28
+ raise errors.inspect unless errors.empty?
29
+
30
+ @client.rest_post_with_token("/directentitlement/redemptions/#{redemption_id}", action_request, headers)
31
+ end
32
+
33
+ # Retrieve a direct entitlement redemption by its Client Transaction ID
34
+ def get_by_ctid(ctid, headers: {})
35
+ @client.rest_get_with_token("/directentitlement/redemptions/ctid/#{ctid}", {}, headers)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class Orders
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Order a product key
11
+ def perform(order_request, headers: {}, options: {})
12
+ errors = Genba::OrderRequest.new.call(order_request).messages
13
+ raise errors.inspect unless errors.empty?
14
+
15
+ @client.rest_post_with_token('/orders', order_request, headers, options)
16
+ end
17
+
18
+ # Retrieve an order
19
+ def get(order_id, headers: {})
20
+ @client.rest_get_with_token("/orders/#{order_id}", {}, headers)
21
+ end
22
+
23
+ # Perform an action on a product, like ‘Return’
24
+ def perform_action(order_id, action_request, headers: {}, options: {})
25
+ errors = Genba::ActionRequest.new.call(action_request).messages
26
+ raise errors.inspect unless errors.empty?
27
+
28
+ @client.rest_post_with_token("/orders/#{order_id}", action_request, headers)
29
+ end
30
+
31
+ # Retrieve and order based on your Client transaction ID
32
+ def get_by_ctid(ctid, headers: {})
33
+ @client.rest_get_with_token("/orders/ctid/#{ctid}", {}, headers)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class Ping
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Test connection to the API
11
+ def perform
12
+ @client.rest_get_with_token('/ping', {}, {})
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,16 +2,17 @@
2
2
 
3
3
  module Genba
4
4
  class Client
5
- # Prices client
6
5
  class Prices
7
6
  def initialize(client)
8
7
  @client = client
9
8
  end
10
9
 
11
- def get_prices(params = {}, headers = {})
12
- payload = params.merge(
13
- customerAccountId: @client.customer_account_id
14
- )
10
+ # Gets a collection of prices
11
+ def list(continuation_token: nil, params: {}, headers: {})
12
+ payload = {
13
+ continuationtoken: continuation_token
14
+ }.select { |_, v| !v.nil? }.merge(params)
15
+
15
16
  @client.rest_get_with_token('/prices', payload, headers)
16
17
  end
17
18
  end
@@ -2,38 +2,30 @@
2
2
 
3
3
  module Genba
4
4
  class Client
5
- # Products client
6
5
  class Products
7
6
  def initialize(client)
8
7
  @client = client
9
8
  end
10
9
 
11
- def get_products(sku_id: nil, country_iso: nil, include_meta: false, headers: {})
10
+ # Return information about a product
11
+ def get(sku_id, headers: {})
12
12
  payload = {
13
- skuId: sku_id,
14
- countryISO: country_iso,
15
- includeMeta: include_meta
16
13
  }.select { |_, v| !v.nil? }
17
14
 
18
- @client.rest_get_with_token('/product', payload, headers)
15
+ @client.rest_get_with_token("/products/#{sku_id}", payload, headers)
19
16
  end
20
17
 
21
- def get_changes(from_date: nil, country_iso: nil, include_meta: false, params: {}, headers: {})
22
- payload = params.merge(
23
- countryISO: country_iso,
24
- includeMeta: include_meta
25
- ).select { |_, v| !v.nil? }
26
- payload[:fromDate] = from_date.strftime('%FT%T') if from_date
27
- @client.rest_get_with_token('/product/changes', payload, headers)
28
- end
18
+ # Gets a collection of available products
19
+ def list(country_code: nil, include_meta: nil, from_date: nil, deleted: nil, continuation_token: nil, headers: {})
20
+ payload = {
21
+ countryCode: country_code,
22
+ includeMeta: include_meta,
23
+ fromDate: from_date,
24
+ deleted: deleted,
25
+ continuationtoken: continuation_token
26
+ }.select { |_, v| !v.nil? }
29
27
 
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)
28
+ @client.rest_get_with_token('/products', payload, headers)
37
29
  end
38
30
  end
39
31
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class Promotions
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Gets a collection of available promotions
11
+ def list(from_date: nil, to_date: nil, continuation_token: nil, headers: {})
12
+ payload = {
13
+ fromDate: from_date,
14
+ toDate: to_date,
15
+ continuationtoken: continuation_token
16
+ }.select { |_, v| !v.nil? }
17
+
18
+ @client.rest_get_with_token('/promotions', payload, headers)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class Client
5
+ class Reservations
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Place a reservation for a product
11
+ def perform(reservation_request, headers: {}, options: {})
12
+ errors = Genba::ReservationRequest.new.call(reservation_request).messages
13
+ raise errors.inspect unless errors.empty?
14
+
15
+ @client.rest_post_with_token('/reservations', reservation_request, headers, options)
16
+ end
17
+
18
+ # Retrieve a reservation
19
+ def get(reservation_id, headers: {})
20
+ payload = {
21
+ }.select { |_, v| !v.nil? }
22
+
23
+ @client.rest_get_with_token("/reservations/#{reservation_id}", payload, headers)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class OrderRequest
5
+ def initialize
6
+ @schema = Dry::Validation.Schema do
7
+ required(:ClientTransactionID).filled(:str?)
8
+ optional(:Properties).schema do
9
+ required(:Sku).filled(:str?)
10
+ optional(:BuyingPrice).schema do
11
+ required(:Amount).filled(:float?)
12
+ required(:CurrencyCode).filled(:str?)
13
+ end
14
+ required(:SellingPrice).schema do
15
+ required(:NetAmount).filled(:float?)
16
+ required(:GrossAmount).filled(:float?)
17
+ required(:CurrencyCode).filled(:str?)
18
+ end
19
+ optional(:ConsumerIP).maybe(:str?)
20
+ required(:CountryCode).filled(:str?)
21
+ optional(:EtailerID).filled(:str?)
22
+ end
23
+ optional(:ReservationID).filled(:str?)
24
+ end
25
+ end
26
+
27
+ def call(data)
28
+ @schema.call(data)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class RedemptionRequest
5
+ def initialize
6
+ @schema = Dry::Validation.Schema do
7
+ required(:ClientTransactionID).filled(:str?)
8
+ optional(:EtailerID).filled(:str?)
9
+ required(:ActivationID).filled(:str?)
10
+ required(:Redemption).schema do
11
+ required(:EndUserID).filled(:str?)
12
+ required(:EndUserTicket).filled(:str?)
13
+ end
14
+ end
15
+ end
16
+
17
+ def call(data)
18
+ @schema.call(data)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genba
4
+ class ReservationRequest
5
+ def initialize
6
+ @schema = Dry::Validation.Schema do
7
+ required(:ClientTransactionID).filled(:str?)
8
+ required(:Properties).schema do
9
+ required(:Sku).filled(:str?)
10
+ optional(:BuyingPrice).schema do
11
+ required(:Amount).filled(:float?)
12
+ required(:CurrencyCode).filled(:str?)
13
+ end
14
+ required(:SellingPrice).schema do
15
+ required(:NetAmount).filled(:float?)
16
+ required(:GrossAmount).filled(:float?)
17
+ required(:CurrencyCode).filled(:str?)
18
+ end
19
+ optional(:ConsumerIP).maybe(:str?)
20
+ required(:CountryCode).filled(:str?)
21
+ optional(:EtailerID).filled(:str?)
22
+ end
23
+ end
24
+ end
25
+
26
+ def call(data)
27
+ @schema.call(data)
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Genba
2
- VERSION = '0.1.12'.freeze
2
+ VERSION = '0.2.0'.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.12
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -39,19 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-mcrypt
42
+ name: jwt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: '1.5'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-validation
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.2.0
68
+ version: 0.11.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -116,17 +130,25 @@ files:
116
130
  - circle.yml
117
131
  - genba.gemspec
118
132
  - lib/genba.rb
133
+ - lib/genba/action_request.rb
134
+ - lib/genba/activation_request.rb
119
135
  - lib/genba/client.rb
120
- - lib/genba/client/direct_entitlements.rb
121
- - lib/genba/client/keys.rb
136
+ - lib/genba/client/direct_entitlement.rb
137
+ - lib/genba/client/direct_entitlements/activations.rb
138
+ - lib/genba/client/direct_entitlements/redemptions.rb
139
+ - lib/genba/client/orders.rb
140
+ - lib/genba/client/ping.rb
122
141
  - lib/genba/client/prices.rb
123
142
  - lib/genba/client/products.rb
124
- - lib/genba/client/reports.rb
125
- - lib/genba/client/restrictions.rb
126
- - lib/genba/key_black_list_request.rb
143
+ - lib/genba/client/promotions.rb
144
+ - lib/genba/client/reservations.rb
127
145
  - lib/genba/key_report_request.rb
146
+ - lib/genba/order_request.rb
147
+ - lib/genba/redemption_request.rb
148
+ - lib/genba/reservation_request.rb
128
149
  - lib/genba/util.rb
129
150
  - lib/genba/version.rb
151
+ - tmp/.gitkeep
130
152
  homepage: https://api.genbagames.com/doc/
131
153
  licenses:
132
154
  - MIT
@@ -147,7 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
169
  - !ruby/object:Gem::Version
148
170
  version: '0'
149
171
  requirements: []
150
- rubygems_version: 3.0.6
172
+ rubyforge_project:
173
+ rubygems_version: 2.7.8
151
174
  signing_key:
152
175
  specification_version: 4
153
176
  summary: genba api for ruby version
@@ -1,60 +0,0 @@
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
- e_tailer_subsidiary: nil,
24
- headers: {},
25
- options: {}
26
- )
27
- params = {
28
- skuId: sku_id,
29
- customerAccountId: @client.customer_account_id,
30
- countryISO: country_iso,
31
- endUserIpAddress: end_user_ip_address,
32
- endUserId: end_user_id,
33
- endUserTicket: end_user_ticket,
34
- ETailerBuyingPrice: e_tailer_buying_price,
35
- ETailerBuyingPriceCurrencyCode: e_tailer_buying_price_currency_code,
36
- ETailerSellingPriceNet: e_tailer_selling_price_net,
37
- ETailerSellingPriceGross: e_tailer_selling_price_gross,
38
- ETailerSellingPriceCurrencyCode: e_tailer_selling_price_currency_code,
39
- EtailerSubsidiary: e_tailer_subsidiary
40
- }.select { |_, v| !v.nil? }
41
- params[:saleDate] = sale_date.strftime('%FT%T') if sale_date
42
- Genba::Util.log_debug "DirectEntitlements activate payload: #{params.inspect}"
43
- @client.rest_get_with_token('/directentitlement/activate', params, headers, options)
44
- end
45
-
46
- # Use this method to redeem keys already sold for a Direct Entitlement SKU and link them to the
47
- # end-user's account. You will not be charged at the point of calling this method.
48
- def redeem(sku_id:, key_id:, end_user_id:, end_user_ticket:, headers: {}, options: {})
49
- params = {
50
- customerAccountId: @client.customer_account_id,
51
- skuId: sku_id,
52
- keyId: key_id,
53
- endUserId: end_user_id,
54
- endUserTicket: end_user_ticket
55
- }
56
- @client.rest_get_with_token('/directentitlement/redeem', params, headers, options)
57
- end
58
- end
59
- end
60
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Genba
4
- class Client
5
- # Keys client
6
- class Keys
7
- def initialize(client)
8
- @client = client
9
- end
10
-
11
- def get_test_keys(sku_id, headers = {})
12
- params = {
13
- skuId: sku_id
14
- }
15
- @client.rest_get_with_token('/testKeys', params, headers)
16
- end
17
-
18
- def get_keys(sku_id, quantity = 1, params = {}, headers = {}, options: {})
19
- payload = params.merge(
20
- skuId: sku_id,
21
- quantity: quantity,
22
- customerAccountId: @client.customer_account_id
23
- )
24
- @client.rest_get_with_token('/keys', payload, headers, options)
25
- end
26
-
27
- def get_key_code_status(key_code, params = {}, headers = {}, options: {})
28
- payload = params.merge(
29
- keyCode: key_code
30
- )
31
- @client.rest_get_with_token('/keys', payload, headers, options)
32
- end
33
-
34
- def get_key_status(key_id, params = {}, headers = {}, options: {})
35
- @client.rest_get_with_token("/keys/#{key_id}", params, headers, options)
36
- end
37
-
38
- def get_report_usage(keys = nil, headers = {}, options: {})
39
- raise 'ReportUsage keys should be array' unless keys.is_a?(Array)
40
- raise 'ReportUseag keys should be a KeyReportRequest class' unless key_report_request?(keys)
41
- payload = keys.map(&:to_genba_json_payload)
42
- Genba::Util.log_debug "get_report_usage payload: #{payload.inspect}"
43
- @client.rest_post_with_token('/keyReport', payload, headers, options)
44
- end
45
-
46
- def black_list(keys = nil, headers = {}, options: {})
47
- raise 'Blacklist keys should be array' unless keys.is_a?(Array)
48
- raise 'Blacklist keys should be a KeyBlackListRequest class' unless key_black_list_request?(keys)
49
-
50
- keys.each do |k|
51
- raise k.errors.full_messages.to_s unless k.valid?
52
- end
53
-
54
- payload = keys.map(&:to_genba_json_payload)
55
- @client.rest_post_with_token('/blackListKeys', payload, headers, options)
56
- end
57
-
58
- private
59
-
60
- def key_report_request?(keys)
61
- (keys.map { |k| k.is_a?(KeyReportRequest) } & [false]).empty?
62
- end
63
-
64
- def key_black_list_request?(keys)
65
- (keys.map { |k| k.is_a?(KeyBlackListRequest) } & [false]).empty?
66
- end
67
- end
68
- end
69
- end
@@ -1,19 +0,0 @@
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
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Genba
4
- class Client
5
- # Restrictions client
6
- class Restrictions
7
- def initialize(client)
8
- @client = client
9
- end
10
-
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)
18
- end
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # keyBlackListRequest
4
- class KeyBlackListRequest
5
- include ActiveModel::Validations
6
- attr_accessor :key_id, :reason_text
7
-
8
- validates :key_id, presence: true, allow_blank: false
9
- validates :reason_text, presence: true, allow_blank: false
10
-
11
- def initialize(key_id, reason_text)
12
- @key_id = key_id
13
- @reason_text = reason_text
14
- end
15
-
16
- def to_genba_json_payload
17
- {
18
- keyId: @key_id,
19
- reasonText: @reason_text
20
- }.select { |_, v| !v.nil? }
21
- end
22
- end