genba 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +94 -0
- data/LICENSE.txt +21 -0
- data/README.md +113 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +10 -0
- data/genba.gemspec +40 -0
- data/lib/genba.rb +25 -0
- data/lib/genba/client.rb +129 -0
- data/lib/genba/client/keys.rb +70 -0
- data/lib/genba/client/prices.rb +19 -0
- data/lib/genba/client/products.rb +27 -0
- data/lib/genba/client/restrictions.rb +16 -0
- data/lib/genba/key_black_list_request.rb +22 -0
- data/lib/genba/key_report_request.rb +31 -0
- data/lib/genba/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adcd7e46a8308fc3301011cfe7c4f8c468160331
|
4
|
+
data.tar.gz: 3250e4acf387e044976b8cca83438e6ae835d275
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e9c0a137a30dfc44243357cb7d8cf63f878d611b073daa27491623af4bb676e1046a85ab227b47231c820e2dd02cd9e5f6d172d445c97b499ea29f78110a4e1
|
7
|
+
data.tar.gz: c3b077d7cff7111851172050bd156cd32ba63ace2e01019e596ddcdf98088d09e794e1bd99dd14d63157a4b6cefc4d9e2722770cc01083340f7cfe244b121c4c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dean.lin@iscreen.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in genba-ruby.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'activemodel', require: 'active_model'
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem 'rake'
|
12
|
+
gem 'webmock'
|
13
|
+
|
14
|
+
platforms :mri do
|
15
|
+
# to avoid problems, bring Byebug in on just versions of Ruby under which
|
16
|
+
# it's known to work well
|
17
|
+
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
|
18
|
+
gem 'byebug'
|
19
|
+
gem 'pry'
|
20
|
+
gem 'pry-byebug'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
genba (0.1.6)
|
5
|
+
oj (~> 2.18)
|
6
|
+
rest-client (~> 2.0)
|
7
|
+
ruby-mcrypt (= 0.2.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (5.2.0)
|
13
|
+
activesupport (= 5.2.0)
|
14
|
+
activesupport (5.2.0)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
addressable (2.5.2)
|
20
|
+
public_suffix (>= 2.0.2, < 4.0)
|
21
|
+
byebug (10.0.2)
|
22
|
+
coderay (1.1.2)
|
23
|
+
concurrent-ruby (1.0.5)
|
24
|
+
crack (0.4.3)
|
25
|
+
safe_yaml (~> 1.0.0)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
domain_name (0.5.20180417)
|
28
|
+
unf (>= 0.0.5, < 1.0.0)
|
29
|
+
hashdiff (0.3.7)
|
30
|
+
http-cookie (1.0.3)
|
31
|
+
domain_name (~> 0.5)
|
32
|
+
i18n (1.0.1)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
method_source (0.9.0)
|
35
|
+
mime-types (3.1)
|
36
|
+
mime-types-data (~> 3.2015)
|
37
|
+
mime-types-data (3.2016.0521)
|
38
|
+
minitest (5.11.3)
|
39
|
+
netrc (0.11.0)
|
40
|
+
oj (2.18.5)
|
41
|
+
pry (0.11.3)
|
42
|
+
coderay (~> 1.1.0)
|
43
|
+
method_source (~> 0.9.0)
|
44
|
+
pry-byebug (3.6.0)
|
45
|
+
byebug (~> 10.0)
|
46
|
+
pry (~> 0.10)
|
47
|
+
public_suffix (3.0.2)
|
48
|
+
rake (10.5.0)
|
49
|
+
rest-client (2.0.2)
|
50
|
+
http-cookie (>= 1.0.2, < 2.0)
|
51
|
+
mime-types (>= 1.16, < 4.0)
|
52
|
+
netrc (~> 0.8)
|
53
|
+
rspec (3.7.0)
|
54
|
+
rspec-core (~> 3.7.0)
|
55
|
+
rspec-expectations (~> 3.7.0)
|
56
|
+
rspec-mocks (~> 3.7.0)
|
57
|
+
rspec-core (3.7.1)
|
58
|
+
rspec-support (~> 3.7.0)
|
59
|
+
rspec-expectations (3.7.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.7.0)
|
62
|
+
rspec-mocks (3.7.0)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.7.0)
|
65
|
+
rspec-support (3.7.1)
|
66
|
+
ruby-mcrypt (0.2.0)
|
67
|
+
safe_yaml (1.0.4)
|
68
|
+
thread_safe (0.3.6)
|
69
|
+
tzinfo (1.2.5)
|
70
|
+
thread_safe (~> 0.1)
|
71
|
+
unf (0.1.4)
|
72
|
+
unf_ext
|
73
|
+
unf_ext (0.0.7.5)
|
74
|
+
webmock (3.4.1)
|
75
|
+
addressable (>= 2.3.6)
|
76
|
+
crack (>= 0.3.2)
|
77
|
+
hashdiff
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
activemodel
|
84
|
+
bundler (~> 1.16)
|
85
|
+
byebug
|
86
|
+
genba!
|
87
|
+
pry
|
88
|
+
pry-byebug
|
89
|
+
rake
|
90
|
+
rspec (~> 3.0)
|
91
|
+
webmock
|
92
|
+
|
93
|
+
BUNDLED WITH
|
94
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dean Lin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Genba Ruby
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/iscreen/genba-ruby.svg)](https://travis-ci.org/iscreen/genba-ruby)
|
4
|
+
[![CircleCI](https://circleci.com/gh/iscreen/genba-ruby.svg?style=shield)](https://circleci.com/gh/iscreen/genba-ruby)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/genba-ruby.svg)](https://badge.fury.io/rb/genba-ruby)
|
6
|
+
|
7
|
+
The Genba Library provides convenient access to the [Genba API](https://api.genbagames.com/doc/) from applications written in the Ruby language.
|
8
|
+
|
9
|
+
## Basic Usage
|
10
|
+
|
11
|
+
require 'genba'
|
12
|
+
|
13
|
+
genba_client = Genba.client(
|
14
|
+
username: 'api_genba_user',
|
15
|
+
app_id: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
|
16
|
+
api_key: 'e6a69096fb94d91971ccc69b1770b9f3'
|
17
|
+
)
|
18
|
+
|
19
|
+
## Products
|
20
|
+
[Genba Products API](https://api.genbagames.com/doc/#api-Product)
|
21
|
+
|
22
|
+
Call products.get_products to get all products.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
payload = {
|
26
|
+
countryISO: 'US',
|
27
|
+
includeMeta: false
|
28
|
+
}
|
29
|
+
|
30
|
+
response = genba_client.products.get_products(payload)
|
31
|
+
```
|
32
|
+
|
33
|
+
Retrieve an existing product
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
payload = {
|
37
|
+
skuId: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
|
38
|
+
countryISO: 'US',
|
39
|
+
includeMeta: false
|
40
|
+
}
|
41
|
+
|
42
|
+
product = genba_client.products.get_products(payload)
|
43
|
+
```
|
44
|
+
|
45
|
+
Return a list of products which have changed since a given date, including basic or advanced metadata.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
payload = {
|
49
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
50
|
+
countryISO: 'US',
|
51
|
+
includeMeta: false
|
52
|
+
}
|
53
|
+
|
54
|
+
response = genba_client.products.get_changes(payload)
|
55
|
+
```
|
56
|
+
|
57
|
+
Return a list of products which have been removed since a given date.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
payload = {
|
61
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
62
|
+
countryISO: 'US',
|
63
|
+
includeMeta: false
|
64
|
+
}
|
65
|
+
|
66
|
+
response = genba_client.products.get_removed(payload)
|
67
|
+
```
|
68
|
+
|
69
|
+
## Prices
|
70
|
+
[Genba Prices API](https://api.genbagames.com/doc/#api-Prices)
|
71
|
+
|
72
|
+
Get latest prices for all of your available products. It is recommended that you call this daily to get accurate pricing.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
response = genba_client.prices.get_prices
|
76
|
+
```
|
77
|
+
|
78
|
+
## Restrictions
|
79
|
+
[Genba Restrictions API](https://api.genbagames.com/doc/#api-Restrictions)
|
80
|
+
|
81
|
+
Returns a list of product sku restrictions, whitelist - can only sold in countries, blacklist - cannot be sold in countries.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
payload = {
|
85
|
+
productId: '84d90a06-f458-4ed8-8f3d-91aa84cc6577',
|
86
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
87
|
+
countryISO: 'US'
|
88
|
+
}
|
89
|
+
|
90
|
+
response = genba_client.restrictions.get_restrictions
|
91
|
+
response[:productRestriction]
|
92
|
+
```
|
93
|
+
|
94
|
+
## Keys
|
95
|
+
[Genba Keys API](https://api.genbagames.com/doc/#api-Keys)
|
96
|
+
|
97
|
+
Request Product Test Keys for a SKU
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
response = genba_client.keys.get_test_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577')
|
101
|
+
|
102
|
+
response[:status]
|
103
|
+
response[:keys]
|
104
|
+
```
|
105
|
+
|
106
|
+
Request Product Keys for a SKU
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
response = genba_client.keys.get_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577', 1)
|
110
|
+
|
111
|
+
response[:status]
|
112
|
+
response[:keys]
|
113
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "genba/ruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/circle.yml
ADDED
data/genba.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'genba/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'genba'
|
8
|
+
spec.version = Genba::VERSION
|
9
|
+
spec.authors = ['Dean Lin']
|
10
|
+
spec.email = ['dean.lin@iscreen.com']
|
11
|
+
|
12
|
+
spec.summary = %q{genba api for ruby version}
|
13
|
+
spec.description = %q{genba api for ruby version}
|
14
|
+
spec.homepage = 'https://api.genbagames.com/doc/'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'oj', '~> 2.18'
|
34
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.0'
|
35
|
+
spec.add_runtime_dependency 'ruby-mcrypt', '0.2.0'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
end
|
data/lib/genba.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest'
|
3
|
+
require 'mcrypt'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'oj'
|
6
|
+
require 'active_model'
|
7
|
+
|
8
|
+
# Engine (for rails)
|
9
|
+
require 'genba/engine' if defined?(Rails)
|
10
|
+
|
11
|
+
require 'genba/version'
|
12
|
+
require 'genba/key_black_list_request'
|
13
|
+
require 'genba/key_report_request'
|
14
|
+
require 'genba/client/keys'
|
15
|
+
require 'genba/client/prices'
|
16
|
+
require 'genba/client/products'
|
17
|
+
require 'genba/client/restrictions'
|
18
|
+
require 'genba/client'
|
19
|
+
|
20
|
+
# Genba API module
|
21
|
+
module Genba
|
22
|
+
def self.client(credentials = {})
|
23
|
+
Client.new(credentials)
|
24
|
+
end
|
25
|
+
end
|
data/lib/genba/client.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genba
|
4
|
+
# Genba API Client
|
5
|
+
class Client
|
6
|
+
API_URL = 'https://api.genbagames.com/api'.freeze
|
7
|
+
|
8
|
+
@expires_on = nil
|
9
|
+
@id_token = nil
|
10
|
+
|
11
|
+
# Desribe the behaviour of the method
|
12
|
+
#
|
13
|
+
# ==== Attributes
|
14
|
+
#
|
15
|
+
# * +config+ - Genba API credential attribute
|
16
|
+
#
|
17
|
+
# ==== Options
|
18
|
+
def initialize(config = {})
|
19
|
+
@app_id = config[:app_id]
|
20
|
+
@username = config[:username]
|
21
|
+
@api_key = config[:api_key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_token
|
25
|
+
unless token_valid?
|
26
|
+
body = { appId: @app_id, signature: genba_signature }
|
27
|
+
response = RestClient.post(
|
28
|
+
"#{API_URL}/token",
|
29
|
+
body,
|
30
|
+
headers: { accept: 'application/json' }
|
31
|
+
)
|
32
|
+
parsed_response = decode_json(response.body)
|
33
|
+
@id_token = parsed_response['token']
|
34
|
+
@expires_on = Time.parse(parsed_response['expiration'])
|
35
|
+
end
|
36
|
+
raw_token
|
37
|
+
end
|
38
|
+
|
39
|
+
def rest_get_with_token(path, query_params = {}, headers = {})
|
40
|
+
genba_headers = token.merge(headers)
|
41
|
+
headers[:params] = query_params unless query_params.empty?
|
42
|
+
response = RestClient.get("#{API_URL}#{path}", genba_headers)
|
43
|
+
from_rest_client_response(response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def rest_put_with_token(path, body = {}, headers = {})
|
47
|
+
genba_headers = token.merge(headers)
|
48
|
+
response = RestClient.put("#{API_URL}#{path}", encode_json(body), genba_headers)
|
49
|
+
from_rest_client_response(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def rest_post_with_token(path, body = {}, headers = {})
|
53
|
+
genba_headers = token.merge(headers)
|
54
|
+
response = RestClient.post("#{API_URL}#{path}", encode_json(body), genba_headers)
|
55
|
+
from_rest_client_response(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
def products
|
59
|
+
Products.new(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def prices
|
63
|
+
Prices.new(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def restrictions
|
67
|
+
Restrictions.new(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
def keys
|
71
|
+
Keys.new(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def encode_json(data)
|
77
|
+
Oj.dump(data, mode: :compat)
|
78
|
+
end
|
79
|
+
|
80
|
+
def decode_json(json)
|
81
|
+
Oj.load(json)
|
82
|
+
end
|
83
|
+
|
84
|
+
def genba_signature
|
85
|
+
cipher = Mcrypt.new(
|
86
|
+
:rijndael_256,
|
87
|
+
:cbc,
|
88
|
+
Digest::SHA256.digest(@username),
|
89
|
+
Digest::SHA256.digest(@app_id)
|
90
|
+
)
|
91
|
+
encrypted = cipher.encrypt(@api_key)
|
92
|
+
Base64.strict_encode64(encrypted)
|
93
|
+
end
|
94
|
+
|
95
|
+
def raw_token
|
96
|
+
if token_valid?
|
97
|
+
{
|
98
|
+
token: @id_token,
|
99
|
+
appId: @app_id,
|
100
|
+
accept: 'application/json'
|
101
|
+
}
|
102
|
+
else
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def token
|
108
|
+
generate_token unless token_valid?
|
109
|
+
raw_token
|
110
|
+
end
|
111
|
+
|
112
|
+
def token_valid?
|
113
|
+
@id_token && @expires_on > Time.now
|
114
|
+
end
|
115
|
+
|
116
|
+
def from_rest_client_response(response)
|
117
|
+
if response.code < 200 &&
|
118
|
+
response.code >= 400
|
119
|
+
raise "Invalid response object from API: #{response.body}" \
|
120
|
+
"(HTTP response code was #{response.code})"
|
121
|
+
end
|
122
|
+
# default decode by json
|
123
|
+
return decode_json(response.body) unless response.headers[:content_type]
|
124
|
+
if (response.headers[:content_type] =~ %r{application\/json}) > 0
|
125
|
+
decode_json(response.body)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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 = {})
|
19
|
+
payload = params.merge(
|
20
|
+
skuId: sku_id,
|
21
|
+
quantity: quantity
|
22
|
+
)
|
23
|
+
@client.rest_get_with_token('/keys', payload, headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_key_code_status(key_code, params = {}, headers = {})
|
27
|
+
payload = params.merge(
|
28
|
+
keyCode: key_code
|
29
|
+
)
|
30
|
+
@client.rest_get_with_token('/keys', payload, headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
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)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_report_usage(keys = nil, headers = {})
|
41
|
+
raise 'ReportUsage keys should be array' unless keys.is_a?(Array)
|
42
|
+
raise 'ReportUseag keys should be a KeyReportRequest class' unless key_report_request?(keys)
|
43
|
+
payload = keys.map(&:to_genba_json_payload)
|
44
|
+
@client.rest_post_with_token('/keyReport', payload, headers)
|
45
|
+
end
|
46
|
+
|
47
|
+
def black_list(keys = nil, headers = {})
|
48
|
+
raise 'Blacklist keys should be array' unless keys.is_a?(Array)
|
49
|
+
raise 'Blacklist keys should be a KeyBlackListRequest class' unless key_black_list_request?(keys)
|
50
|
+
|
51
|
+
keys.each do |k|
|
52
|
+
raise k.errors.full_messages.to_s unless k.valid?
|
53
|
+
end
|
54
|
+
|
55
|
+
payload = keys.map(&:to_genba_json_payload)
|
56
|
+
@client.rest_post_with_token('/blackListKeys', payload, headers)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def key_report_request?(keys)
|
62
|
+
(keys.map { |k| k.is_a?(KeyReportRequest) } & [false]).empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
def key_black_list_request?(keys)
|
66
|
+
(keys.map { |k| k.is_a?(KeyBlackListRequest) } & [false]).empty?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genba
|
4
|
+
class Client
|
5
|
+
# Prices client
|
6
|
+
class Prices
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
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)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genba
|
4
|
+
class Client
|
5
|
+
# Products client
|
6
|
+
class Products
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_products(params = {}, headers = {})
|
12
|
+
@client.rest_get_with_token('/product', params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_changes(from_date, params = {}, headers = {})
|
16
|
+
payload = params.merge(
|
17
|
+
fromDate: from_date
|
18
|
+
)
|
19
|
+
@client.rest_get_with_token('/product/changes', payload, headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_removed(params = {}, headers = {})
|
23
|
+
@client.rest_get_with_token('/product/removed', params, headers)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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(params = {}, headers = {})
|
12
|
+
@client.rest_get_with_token('/restrictions', params, headers)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# KeyReportRequest
|
4
|
+
class KeyReportRequest
|
5
|
+
attr_accessor :key, :key_id, :country_iso, :sale_date, :user_ip_address,
|
6
|
+
:e_tailer_buying_price, :e_tailer_buying_price_currency_code,
|
7
|
+
:e_tailer_selling_price_net, :e_tailer_selling_price_gross,
|
8
|
+
:e_tailer_selling_price_currency_code
|
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]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_genba_json_payload
|
18
|
+
{
|
19
|
+
key: @key,
|
20
|
+
keyId: @key_id,
|
21
|
+
countryISO: @country_iso,
|
22
|
+
saleDate: @sale_date,
|
23
|
+
userIpAddress: @user_ip_address,
|
24
|
+
ETailerBuyingPrice: @e_tailer_buying_price,
|
25
|
+
ETailerBuyingPriceCurrencyCode: @e_tailer_buying_price_currency_code,
|
26
|
+
ETailerSellingPriceNet: @e_tailer_selling_price_net,
|
27
|
+
ETailerSellingPriceGross: @e_tailer_selling_price_gross,
|
28
|
+
ETailerSellingPriceCurrencyCode: @e_tailer_selling_price_currency_code
|
29
|
+
}.select { |_, v| !v.nil? }
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: genba
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Lin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-mcrypt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: genba api for ruby version
|
98
|
+
email:
|
99
|
+
- dean.lin@iscreen.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- circle.yml
|
116
|
+
- genba.gemspec
|
117
|
+
- lib/genba.rb
|
118
|
+
- lib/genba/client.rb
|
119
|
+
- lib/genba/client/keys.rb
|
120
|
+
- lib/genba/client/prices.rb
|
121
|
+
- lib/genba/client/products.rb
|
122
|
+
- lib/genba/client/restrictions.rb
|
123
|
+
- lib/genba/key_black_list_request.rb
|
124
|
+
- lib/genba/key_report_request.rb
|
125
|
+
- lib/genba/version.rb
|
126
|
+
homepage: https://api.genbagames.com/doc/
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata:
|
130
|
+
allowed_push_host: https://rubygems.org
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.6.14
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: genba api for ruby version
|
151
|
+
test_files: []
|