genba-ruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +21 -0
- data/README.md +112 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +3 -0
- data/genba-ruby.gemspec +40 -0
- data/lib/genba/client/keys.rb +27 -0
- data/lib/genba/client/prices.rb +19 -0
- data/lib/genba/client/products.rb +24 -0
- data/lib/genba/client/restrictions.rb +16 -0
- data/lib/genba/client.rb +130 -0
- data/lib/genba/version.rb +3 -0
- data/lib/genba.rb +19 -0
- metadata +149 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4ffd8d18495a1fee30099a9648b8ca924e248851
|
|
4
|
+
data.tar.gz: e95032398e8f2cee3448816b82264f42176d8b58
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6f2d58be28a3f0590bc9b471249979674d4ff3f46cc4ac34e949f46fe8f8592897b7a0d1663999fe4b402c94db1d6bf58c33cf9fb1d456a2d907909bc581d5fa
|
|
7
|
+
data.tar.gz: 66d1a71cb9d926357e3828e54ab72cd23b20c435114db4565e9c4da5704572e5cbc4b9f620be95f49b2e493d92cce7dc4263d7ab240963a8445fbf123da3c098
|
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,21 @@
|
|
|
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
|
+
group :development do
|
|
9
|
+
gem 'rake'
|
|
10
|
+
gem 'webmock'
|
|
11
|
+
|
|
12
|
+
platforms :mri do
|
|
13
|
+
# to avoid problems, bring Byebug in on just versions of Ruby under which
|
|
14
|
+
# it's known to work well
|
|
15
|
+
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new("2.0.0")
|
|
16
|
+
gem 'byebug'
|
|
17
|
+
gem 'pry'
|
|
18
|
+
gem 'pry-byebug'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
genba-ruby (0.1.0)
|
|
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
|
+
addressable (2.5.2)
|
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
14
|
+
byebug (10.0.2)
|
|
15
|
+
coderay (1.1.2)
|
|
16
|
+
crack (0.4.3)
|
|
17
|
+
safe_yaml (~> 1.0.0)
|
|
18
|
+
diff-lcs (1.3)
|
|
19
|
+
domain_name (0.5.20180417)
|
|
20
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
21
|
+
hashdiff (0.3.7)
|
|
22
|
+
http-cookie (1.0.3)
|
|
23
|
+
domain_name (~> 0.5)
|
|
24
|
+
method_source (0.9.0)
|
|
25
|
+
mime-types (3.1)
|
|
26
|
+
mime-types-data (~> 3.2015)
|
|
27
|
+
mime-types-data (3.2016.0521)
|
|
28
|
+
netrc (0.11.0)
|
|
29
|
+
oj (2.18.5)
|
|
30
|
+
pry (0.11.3)
|
|
31
|
+
coderay (~> 1.1.0)
|
|
32
|
+
method_source (~> 0.9.0)
|
|
33
|
+
pry-byebug (3.6.0)
|
|
34
|
+
byebug (~> 10.0)
|
|
35
|
+
pry (~> 0.10)
|
|
36
|
+
public_suffix (3.0.2)
|
|
37
|
+
rake (10.5.0)
|
|
38
|
+
rest-client (2.0.2)
|
|
39
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
40
|
+
mime-types (>= 1.16, < 4.0)
|
|
41
|
+
netrc (~> 0.8)
|
|
42
|
+
rspec (3.7.0)
|
|
43
|
+
rspec-core (~> 3.7.0)
|
|
44
|
+
rspec-expectations (~> 3.7.0)
|
|
45
|
+
rspec-mocks (~> 3.7.0)
|
|
46
|
+
rspec-core (3.7.1)
|
|
47
|
+
rspec-support (~> 3.7.0)
|
|
48
|
+
rspec-expectations (3.7.0)
|
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
50
|
+
rspec-support (~> 3.7.0)
|
|
51
|
+
rspec-mocks (3.7.0)
|
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
+
rspec-support (~> 3.7.0)
|
|
54
|
+
rspec-support (3.7.1)
|
|
55
|
+
ruby-mcrypt (0.2.0)
|
|
56
|
+
safe_yaml (1.0.4)
|
|
57
|
+
unf (0.1.4)
|
|
58
|
+
unf_ext
|
|
59
|
+
unf_ext (0.0.7.5)
|
|
60
|
+
webmock (3.4.1)
|
|
61
|
+
addressable (>= 2.3.6)
|
|
62
|
+
crack (>= 0.3.2)
|
|
63
|
+
hashdiff
|
|
64
|
+
|
|
65
|
+
PLATFORMS
|
|
66
|
+
ruby
|
|
67
|
+
|
|
68
|
+
DEPENDENCIES
|
|
69
|
+
bundler (~> 1.16)
|
|
70
|
+
byebug
|
|
71
|
+
genba-ruby!
|
|
72
|
+
pry
|
|
73
|
+
pry-byebug
|
|
74
|
+
rake
|
|
75
|
+
rspec (~> 3.0)
|
|
76
|
+
webmock
|
|
77
|
+
|
|
78
|
+
BUNDLED WITH
|
|
79
|
+
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,112 @@
|
|
|
1
|
+
# Genba Ruby
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/iscreen/genba-ruby)
|
|
4
|
+
[](https://badge.fury.io/rb/genba-ruby)
|
|
5
|
+
|
|
6
|
+
The Genba Library provides convenient access to the [Genba API](https://api.genbagames.com/doc/) from applications written in the Ruby language.
|
|
7
|
+
|
|
8
|
+
## Basic Usage
|
|
9
|
+
|
|
10
|
+
require 'genba'
|
|
11
|
+
|
|
12
|
+
genba_client = Genba.client(
|
|
13
|
+
username: 'api_genba_user',
|
|
14
|
+
app_id: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
|
|
15
|
+
api_key: 'e6a69096fb94d91971ccc69b1770b9f3'
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
## Products
|
|
19
|
+
[Genba Products API](https://api.genbagames.com/doc/#api-Product)
|
|
20
|
+
|
|
21
|
+
Call products.get_products to get all products.
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
payload = {
|
|
25
|
+
countryISO: 'US',
|
|
26
|
+
includeMeta: false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
response = genba_client.products.get_products(payload)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Retrieve an existing product
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
payload = {
|
|
36
|
+
skuId: '79cf9bb2-e7f5-448f-b996-c52e4b2bb351',
|
|
37
|
+
countryISO: 'US',
|
|
38
|
+
includeMeta: false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
product = genba_client.products.get_products(payload)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Return a list of products which have changed since a given date, including basic or advanced metadata.
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
payload = {
|
|
48
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
|
49
|
+
countryISO: 'US',
|
|
50
|
+
includeMeta: false
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
response = genba_client.products.get_changes(payload)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Return a list of products which have been removed since a given date.
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
payload = {
|
|
60
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
|
61
|
+
countryISO: 'US',
|
|
62
|
+
includeMeta: false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
response = genba_client.products.get_removed(payload)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Prices
|
|
69
|
+
[Genba Prices API](https://api.genbagames.com/doc/#api-Prices)
|
|
70
|
+
|
|
71
|
+
Get latest prices for all of your available products. It is recommended that you call this daily to get accurate pricing.
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
response = genba_client.prices.get_prices
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Restrictions
|
|
78
|
+
[Genba Restrictions API](https://api.genbagames.com/doc/#api-Restrictions)
|
|
79
|
+
|
|
80
|
+
Returns a list of product sku restrictions, whitelist - can only sold in countries, blacklist - cannot be sold in countries.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
payload = {
|
|
84
|
+
productId: '84d90a06-f458-4ed8-8f3d-91aa84cc6577',
|
|
85
|
+
fromDate: 1.days.ago.strftime('%FT%T'),
|
|
86
|
+
countryISO: 'US'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
response = genba_client.restrictions.get_restrictions
|
|
90
|
+
response[:productRestriction]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Keys
|
|
94
|
+
[Genba Keys API](https://api.genbagames.com/doc/#api-Keys)
|
|
95
|
+
|
|
96
|
+
Request Product Test Keys for a SKU
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
response = genba_client.keys.get_test_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577')
|
|
100
|
+
|
|
101
|
+
response[:status]
|
|
102
|
+
response[:keys]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Request Product Keys for a SKU
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
response = genba_client.keys.get_keys('84d90a06-f458-4ed8-8f3d-91aa84cc6577', 1)
|
|
109
|
+
|
|
110
|
+
response[:status]
|
|
111
|
+
response[:keys]
|
|
112
|
+
```
|
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-ruby.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-ruby'
|
|
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 'rest-client', '~> 2.0'
|
|
34
|
+
spec.add_runtime_dependency 'oj', '~> 2.18'
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
end
|
|
26
|
+
end
|
|
27
|
+
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,24 @@
|
|
|
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(params = {}, headers = {})
|
|
16
|
+
@client.rest_get_with_token('/product/changes', params, headers)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_removed(params = {}, headers = {})
|
|
20
|
+
@client.rest_get_with_token('/product/removed', params, headers)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
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
|
data/lib/genba/client.rb
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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) if response.code == 200
|
|
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
|
+
|
|
50
|
+
decode_json(response.body) if response.code == 200
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def rest_post_with_token(path, body = {}, headers = {})
|
|
54
|
+
genba_headers = token.merge(headers)
|
|
55
|
+
response = RestClient.post("#{API_URL}#{path}", encode_json(body), genba_headers)
|
|
56
|
+
decode_json(response.body) if response.code == 201
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def products
|
|
60
|
+
Products.new(self)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def prices
|
|
64
|
+
Prices.new(self)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def restrictions
|
|
68
|
+
Restrictions.new(self)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def keys
|
|
72
|
+
Keys.new(self)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def encode_json(data)
|
|
78
|
+
Oj.dump(data, mode: :compat)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def decode_json(json)
|
|
82
|
+
Oj.load(json)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def genba_signature
|
|
86
|
+
cipher = Mcrypt.new(
|
|
87
|
+
:rijndael_256,
|
|
88
|
+
:cbc,
|
|
89
|
+
Digest::SHA256.digest(@username),
|
|
90
|
+
Digest::SHA256.digest(@app_id)
|
|
91
|
+
)
|
|
92
|
+
encrypted = cipher.encrypt(@api_key)
|
|
93
|
+
Base64.strict_encode64(encrypted)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def raw_token
|
|
97
|
+
if token_valid?
|
|
98
|
+
{
|
|
99
|
+
token: @id_token,
|
|
100
|
+
appId: @app_id,
|
|
101
|
+
accept: 'application/json'
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
{}
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def token
|
|
109
|
+
generate_token unless token_valid?
|
|
110
|
+
raw_token
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def token_valid?
|
|
114
|
+
@id_token && @expires_on > Time.now
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def from_rest_client_response(response)
|
|
118
|
+
if response.code < 200 &&
|
|
119
|
+
response.code >= 400
|
|
120
|
+
raise "Invalid response object from API: #{response.body}" \
|
|
121
|
+
"(HTTP response code was #{response.code})"
|
|
122
|
+
end
|
|
123
|
+
# default decode by json
|
|
124
|
+
return decode_json(response.body) unless response.headers[:content_type]
|
|
125
|
+
if (response.headers[:content_type] =~ %r{application\/json}) > 0
|
|
126
|
+
decode_json(response.body)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
data/lib/genba.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'mcrypt'
|
|
4
|
+
require 'rest-client'
|
|
5
|
+
require 'oj'
|
|
6
|
+
|
|
7
|
+
require 'genba/version'
|
|
8
|
+
require 'genba/client/keys'
|
|
9
|
+
require 'genba/client/prices'
|
|
10
|
+
require 'genba/client/products'
|
|
11
|
+
require 'genba/client/restrictions'
|
|
12
|
+
require 'genba/client'
|
|
13
|
+
|
|
14
|
+
# Genba API module
|
|
15
|
+
module Genba
|
|
16
|
+
def self.client(credentials = {})
|
|
17
|
+
Client.new(credentials)
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: genba-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dean Lin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rest-client
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: oj
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.18'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.18'
|
|
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-ruby.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/version.rb
|
|
124
|
+
homepage: https://api.genbagames.com/doc/
|
|
125
|
+
licenses:
|
|
126
|
+
- MIT
|
|
127
|
+
metadata:
|
|
128
|
+
allowed_push_host: https://rubygems.org
|
|
129
|
+
post_install_message:
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
require_paths:
|
|
132
|
+
- lib
|
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
requirements: []
|
|
144
|
+
rubyforge_project:
|
|
145
|
+
rubygems_version: 2.6.14
|
|
146
|
+
signing_key:
|
|
147
|
+
specification_version: 4
|
|
148
|
+
summary: genba api for ruby version
|
|
149
|
+
test_files: []
|