nintendo_eshop 0.1.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +86 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.devcontainer/Dockerfile +11 -0
- data/.devcontainer/devcontainer.json +30 -0
- data/.gitattributes +2 -0
- data/.gitignore +50 -0
- data/.rspec +1 -0
- data/.rspec_status +5 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +108 -0
- data/LICENSE +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nintendo_eshop/api_request.rb +36 -0
- data/lib/nintendo_eshop/game.rb +59 -0
- data/lib/nintendo_eshop/version.rb +3 -0
- data/lib/nintendo_eshop.rb +19 -0
- data/nintendo_eshop.gemspec +34 -0
- data/test_results +1 -0
- data/test_results_xml +9 -0
- metadata +206 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 61dd76f0dea8e749bcdc061fabf0665e4c3d732543a965369cd0f164f1433561
|
4
|
+
data.tar.gz: 762525c29b7db3d53acbd23f2e9e43b5bbeea2450ff43069c06e014be12dfe65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d44317428360508973e8dada8664351533bded7c86b80978b383481105bdd3069b4a8c778e8fab289ef2d848f42dcf34e0db3c1d9773d465bcf951f5d38f7eca
|
7
|
+
data.tar.gz: 9f9b84276ae3351203f508f6b7844bfbb201f3f29f7e6d5de9ec31e5a14e4c0f846296d5bdf7d768b3f4fc9f76266d4e71b52566990244f8f6724396c1f39e66
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.4.6
|
11
|
+
|
12
|
+
# Specify service dependencies here if necessary
|
13
|
+
# CircleCI maintains a library of pre-built images
|
14
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
15
|
+
# - image: circleci/postgres:9.4
|
16
|
+
|
17
|
+
working_directory: ~/repo
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- checkout
|
21
|
+
|
22
|
+
# Download and cache dependencies
|
23
|
+
- restore_cache:
|
24
|
+
keys:
|
25
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
26
|
+
# fallback to using the latest cache if no exact match is found
|
27
|
+
- v1-dependencies-
|
28
|
+
|
29
|
+
- run:
|
30
|
+
name: install dependencies
|
31
|
+
command: |
|
32
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
33
|
+
|
34
|
+
- save_cache:
|
35
|
+
paths:
|
36
|
+
- ./vendor/bundle
|
37
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
38
|
+
|
39
|
+
# run tests!
|
40
|
+
- run:
|
41
|
+
name: run tests
|
42
|
+
command: |
|
43
|
+
mkdir /tmp/test-results
|
44
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
45
|
+
circleci tests split --split-by=timings)"
|
46
|
+
|
47
|
+
bundle exec rspec \
|
48
|
+
--format RspecJunitFormatter \
|
49
|
+
--out /tmp/test-results/rspec.xml \
|
50
|
+
$TEST_FILES
|
51
|
+
|
52
|
+
# collect reports
|
53
|
+
- store_test_results:
|
54
|
+
path: /tmp/test-results
|
55
|
+
- store_artifacts:
|
56
|
+
path: /tmp/test-results
|
57
|
+
destination: test-results
|
58
|
+
deploy:
|
59
|
+
docker:
|
60
|
+
- image: circleci/ruby:2.4.6
|
61
|
+
|
62
|
+
working_directory: ~/repo
|
63
|
+
|
64
|
+
steps:
|
65
|
+
- checkout
|
66
|
+
- run:
|
67
|
+
name: Setup Rubygems
|
68
|
+
command: bash .circleci/setup-rubygems.sh
|
69
|
+
|
70
|
+
- run:
|
71
|
+
name: Publish to Rubygems
|
72
|
+
command: |
|
73
|
+
gem build nintendo_eshop.gemspec
|
74
|
+
gem push "nintendo_eshop-$(git describe --tags).gem"
|
75
|
+
|
76
|
+
workflows:
|
77
|
+
version: 2
|
78
|
+
test-deploy:
|
79
|
+
jobs:
|
80
|
+
- build
|
81
|
+
- deploy:
|
82
|
+
filters:
|
83
|
+
tags:
|
84
|
+
only: /.*/
|
85
|
+
branches:
|
86
|
+
ignore: /.*/
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:2.4
|
2
|
+
RUN apt-get update && apt-get -y install git procps
|
3
|
+
RUN apt-get autoremove -y \
|
4
|
+
&& apt-get clean -y \
|
5
|
+
&& rm -rf /var/lib/apt/lists/*
|
6
|
+
COPY lib/nintendo_eshop/version.rb ./lib/nintendo_eshop/
|
7
|
+
COPY Gemfile* ./
|
8
|
+
COPY nintendo_eshop.gemspec ./
|
9
|
+
RUN bundle
|
10
|
+
RUN bundle exec yard gems
|
11
|
+
ENV SHELL /bin/bash
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"name": "Nintendo eShop",
|
3
|
+
"dockerFile": "Dockerfile",
|
4
|
+
"context": "..",
|
5
|
+
"settings": {
|
6
|
+
"[json]": {
|
7
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
8
|
+
},
|
9
|
+
"[ruby]": {
|
10
|
+
"editor.formatOnSave": true
|
11
|
+
},
|
12
|
+
"ruby.format": "rubocop",
|
13
|
+
"editor.formatOnSaveTimeout": 2500,
|
14
|
+
"ruby.codeCompletion": false,
|
15
|
+
"ruby.intellisense": "rubyLocate",
|
16
|
+
"ruby.lint": {
|
17
|
+
"rubocop": true
|
18
|
+
},
|
19
|
+
"ruby.useBundler": true,
|
20
|
+
"solargraph.useBundler": true
|
21
|
+
},
|
22
|
+
"extensions": [
|
23
|
+
"castwide.solargraph",
|
24
|
+
"eamodio.gitlens",
|
25
|
+
"esbenp.prettier-vscode",
|
26
|
+
"kaiwood.endwise",
|
27
|
+
"noku.rails-run-spec-vscode",
|
28
|
+
"rebornix.Ruby"
|
29
|
+
],
|
30
|
+
}
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rspec_status
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00598 seconds |
|
4
|
+
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00382 seconds |
|
5
|
+
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00038 seconds |
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nintendo_eshop (0.1.0.alpha1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.6.0)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
ast (2.4.0)
|
12
|
+
backport (1.1.1)
|
13
|
+
coderay (1.1.2)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
debase (0.2.2)
|
17
|
+
debase-ruby_core_source (>= 0.10.2)
|
18
|
+
debase-ruby_core_source (0.10.5)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
hashdiff (0.4.0)
|
21
|
+
htmlentities (4.3.4)
|
22
|
+
jaro_winkler (1.5.3)
|
23
|
+
kramdown (1.17.0)
|
24
|
+
method_source (0.9.2)
|
25
|
+
mini_portile2 (2.4.0)
|
26
|
+
nokogiri (1.10.3)
|
27
|
+
mini_portile2 (~> 2.4.0)
|
28
|
+
parallel (1.17.0)
|
29
|
+
parser (2.6.3.0)
|
30
|
+
ast (~> 2.4.0)
|
31
|
+
pry (0.12.2)
|
32
|
+
coderay (~> 1.1.0)
|
33
|
+
method_source (~> 0.9.0)
|
34
|
+
public_suffix (3.1.0)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (10.5.0)
|
37
|
+
ramsey_cop (0.14.0)
|
38
|
+
rubocop (~> 0.62)
|
39
|
+
rubocop-performance
|
40
|
+
reverse_markdown (1.1.0)
|
41
|
+
nokogiri
|
42
|
+
rspec (3.8.0)
|
43
|
+
rspec-core (~> 3.8.0)
|
44
|
+
rspec-expectations (~> 3.8.0)
|
45
|
+
rspec-mocks (~> 3.8.0)
|
46
|
+
rspec-core (3.8.1)
|
47
|
+
rspec-support (~> 3.8.0)
|
48
|
+
rspec-expectations (3.8.4)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.8.0)
|
51
|
+
rspec-mocks (3.8.1)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.8.0)
|
54
|
+
rspec-support (3.8.2)
|
55
|
+
rspec_junit_formatter (0.4.1)
|
56
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
57
|
+
rubocop (0.71.0)
|
58
|
+
jaro_winkler (~> 1.5.1)
|
59
|
+
parallel (~> 1.10)
|
60
|
+
parser (>= 2.6)
|
61
|
+
rainbow (>= 2.2.2, < 4.0)
|
62
|
+
ruby-progressbar (~> 1.7)
|
63
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
64
|
+
rubocop-performance (1.4.0)
|
65
|
+
rubocop (>= 0.71.0)
|
66
|
+
ruby-debug-ide (0.7.0)
|
67
|
+
rake (>= 0.8.1)
|
68
|
+
ruby-progressbar (1.10.1)
|
69
|
+
safe_yaml (1.0.5)
|
70
|
+
solargraph (0.33.2)
|
71
|
+
backport (~> 1.1)
|
72
|
+
bundler (>= 1.17.2)
|
73
|
+
htmlentities (~> 4.3, >= 4.3.4)
|
74
|
+
jaro_winkler (~> 1.5)
|
75
|
+
kramdown (~> 1.16)
|
76
|
+
parser (~> 2.3)
|
77
|
+
reverse_markdown (~> 1.0, >= 1.0.5)
|
78
|
+
rubocop (~> 0.52)
|
79
|
+
thor (~> 0.19, >= 0.19.4)
|
80
|
+
tilt (~> 2.0)
|
81
|
+
yard (~> 0.9)
|
82
|
+
thor (0.20.3)
|
83
|
+
tilt (2.0.9)
|
84
|
+
unicode-display_width (1.6.0)
|
85
|
+
webmock (3.6.0)
|
86
|
+
addressable (>= 2.3.6)
|
87
|
+
crack (>= 0.3.2)
|
88
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
89
|
+
yard (0.9.19)
|
90
|
+
|
91
|
+
PLATFORMS
|
92
|
+
ruby
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
bundler (~> 1.17)
|
96
|
+
debase
|
97
|
+
nintendo_eshop!
|
98
|
+
pry
|
99
|
+
rake (~> 10.0)
|
100
|
+
ramsey_cop
|
101
|
+
rspec (~> 3.0)
|
102
|
+
rspec_junit_formatter
|
103
|
+
ruby-debug-ide
|
104
|
+
solargraph
|
105
|
+
webmock
|
106
|
+
|
107
|
+
BUNDLED WITH
|
108
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Rick Peyton
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Nintendo eShop
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/rickpeyton/nintendo_eshop.svg?style=svg)](https://circleci.com/gh/rickpeyton/nintendo_eshop)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/5e41e08d88dbecfcf318/maintainability)](https://codeclimate.com/github/rickpeyton/nintendo_eshop/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/5e41e08d88dbecfcf318/test_coverage)](https://codeclimate.com/github/rickpeyton/nintendo_eshop/test_coverage)
|
6
|
+
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&identifier=193173552)](https://dependabot.com)
|
7
|
+
|
8
|
+
## Description
|
9
|
+
|
10
|
+
When I want to check the price of a game on the Nintendo eShop I want to search Nintendo's API by external key so that I am confident I am getting the correct price.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'nintendo_eshop'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install nintendo_eshop
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Use the provided `base_url`, `api_key` and `app_id`. These are provided as configuration in case the values change. The README will be updated to reflect the new values so that you do not have to update the library.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
NintendoEshop.base_url = "https://u3b6gr4ua3-dsn.algolia.net"
|
34
|
+
NintendoEshop.api_key = "9a20c93440cf63cf1a7008d75f7438bf"
|
35
|
+
NintendoEshop.app_id = "U3B6GR4UA3"
|
36
|
+
|
37
|
+
game = NintendoEshop::Game.retrieve("3ce3fb54-5f95-3a24-9101-7faa694c4b6f")
|
38
|
+
|
39
|
+
game.art # "/content/dam/noa/en_US/games/switch/s/super-mario-odyssey-switch/Switch_SuperMarioOdyssey_box.png"
|
40
|
+
game.current_price # 59.99
|
41
|
+
game.external_key # "3ce3fb54-5f95-3a24-9101-7faa694c4b6f"
|
42
|
+
game.id # "70010000001130"
|
43
|
+
game.msrp # 59.99
|
44
|
+
game.platform # "Nintendo Switch"
|
45
|
+
game.sale_price # nil
|
46
|
+
game.title # Super Mario Odyssey"
|
47
|
+
game.url # "/games/detail/super-mario-odyssey-switch"
|
48
|
+
```
|
49
|
+
|
50
|
+
Or a game on sale
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
game = NintendoEshop::Game.retrieve("26322c64-9268-3a24-822e-5e10f9e5cfc9")
|
54
|
+
|
55
|
+
game.art # "/content/dam/noa/en_US/games/switch/s/sonic-forces-switch/Switch_SonicForces_box.png"
|
56
|
+
game.current_price # 14.99
|
57
|
+
game.external_key # "26322c64-9268-3a24-822e-5e10f9e5cfc9
|
58
|
+
game.id # "70010000001539"
|
59
|
+
game.msrp # 29.99
|
60
|
+
game.platform # "Nintendo Switch"
|
61
|
+
game.sale_price # 14.99
|
62
|
+
game.title # "Sonic Forces"
|
63
|
+
game.url # "/games/detail/sonic-forces-switch"
|
64
|
+
```
|
65
|
+
|
66
|
+
## Development
|
67
|
+
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
69
|
+
|
70
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rickpeyton/nintendo_eshop.
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
79
|
+
|
80
|
+
## Releases
|
81
|
+
|
82
|
+
CircleCi is used to push releases to rubygems.org
|
83
|
+
|
84
|
+
To release, edit the version.rb file to the version you want to publish, commit that to your master branch, then create and push a git tag with the same name as your version:
|
85
|
+
|
86
|
+
```
|
87
|
+
git tag -a 0.1.0
|
88
|
+
git push origin 0.1.0
|
89
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nintendo_eshop"
|
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
@@ -0,0 +1,36 @@
|
|
1
|
+
module NintendoEshop
|
2
|
+
class APIRequest
|
3
|
+
class << self; end
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def request(method, to_json: {})
|
8
|
+
case method
|
9
|
+
when :post
|
10
|
+
post(to_json: to_json)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(to_json: {})
|
15
|
+
uri = URI("#{NintendoEshop.base_url}#{self.class::RESOURCE_PATH}?#{url_params}")
|
16
|
+
http = setup_http(uri)
|
17
|
+
req = Net::HTTP::Post.new(uri)
|
18
|
+
req.add_field "Accept", "application/json"
|
19
|
+
req.add_field "Content-Type", "application/json"
|
20
|
+
req.body = JSON.dump(to_json)
|
21
|
+
res = http.request(req)
|
22
|
+
JSON.parse(res.body, symbolize_names: true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_http(uri)
|
26
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
+
http.use_ssl = true
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
29
|
+
http
|
30
|
+
end
|
31
|
+
|
32
|
+
def url_params
|
33
|
+
"x-algolia-api-key=#{NintendoEshop.api_key}&x-algolia-application-id=#{NintendoEshop.app_id}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module NintendoEshop
|
2
|
+
class Game < APIRequest
|
3
|
+
attr_accessor :art
|
4
|
+
attr_accessor :external_key
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :msrp
|
7
|
+
attr_accessor :platform
|
8
|
+
attr_accessor :sale_price
|
9
|
+
attr_accessor :title
|
10
|
+
attr_accessor :url
|
11
|
+
|
12
|
+
RESOURCE_PATH = "/1/indexes/*/objects".freeze
|
13
|
+
|
14
|
+
def initialize(external_key)
|
15
|
+
self.external_key = external_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def refresh
|
19
|
+
response = request(:post, to_json: body)
|
20
|
+
result = response.dig(:results, 0)
|
21
|
+
refresh_object(result)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_price
|
26
|
+
sale_price || msrp
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.retrieve(external_key)
|
30
|
+
instance = new(external_key)
|
31
|
+
instance.refresh
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def body
|
37
|
+
{
|
38
|
+
"requests" => [
|
39
|
+
{
|
40
|
+
"attributesToRetrieve" => "url,objectID,title,nsuid,salePrice,msrp,boxArt,platform",
|
41
|
+
"objectID" => external_key.to_s,
|
42
|
+
"indexName" => "noa_aem_game_en_us"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def refresh_object(result)
|
49
|
+
self.art = result.dig(:boxArt)
|
50
|
+
self.external_key = result.dig(:objectID)
|
51
|
+
self.id = result.dig(:nsuid)
|
52
|
+
self.msrp = result.dig(:msrp)
|
53
|
+
self.platform = result.dig(:platform)
|
54
|
+
self.sale_price = result.dig(:salePrice)
|
55
|
+
self.title = result.dig(:title)
|
56
|
+
self.url = result.dig(:url)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require "pry"
|
3
|
+
rescue StandardError; end # rubocop:disable Lint/HandleExceptions
|
4
|
+
require "json"
|
5
|
+
require "net/http"
|
6
|
+
|
7
|
+
require_relative "nintendo_eshop/api_request"
|
8
|
+
require_relative "nintendo_eshop/game"
|
9
|
+
require_relative "nintendo_eshop/version"
|
10
|
+
|
11
|
+
module NintendoEshop
|
12
|
+
class << self
|
13
|
+
attr_accessor :api_key
|
14
|
+
attr_accessor :app_id
|
15
|
+
attr_accessor :base_url
|
16
|
+
end
|
17
|
+
|
18
|
+
class Error < StandardError; end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "nintendo_eshop/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "nintendo_eshop"
|
7
|
+
spec.version = NintendoEshop::VERSION
|
8
|
+
spec.authors = ["Rick Peyton"]
|
9
|
+
spec.email = ["peytorb@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Retrieve game prices from the Nintendo eShop"
|
12
|
+
spec.homepage = "https://github.com/rickpeyton/nintendo_eshop"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
25
|
+
spec.add_development_dependency "debase"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "ramsey_cop"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "rspec_junit_formatter"
|
31
|
+
spec.add_development_dependency "ruby-debug-ide"
|
32
|
+
spec.add_development_dependency "solargraph"
|
33
|
+
spec.add_development_dependency "webmock"
|
34
|
+
end
|
data/test_results
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":"3.8.1","examples":[{"id":"./spec/nintendo_eshop/game_spec.rb[1:1:1]","description":"retrieves a sale game from the Nintendo eShop API","full_description":"NintendoEshop::Game.retrieve retrieves a sale game from the Nintendo eShop API","status":"passed","file_path":"./spec/nintendo_eshop/game_spec.rb","line_number":3,"run_time":0.005747114,"pending_message":null},{"id":"./spec/nintendo_eshop/game_spec.rb[1:1:2]","description":"retrieves a non-sale game from the Nintendo eShop API","full_description":"NintendoEshop::Game.retrieve retrieves a non-sale game from the Nintendo eShop API","status":"passed","file_path":"./spec/nintendo_eshop/game_spec.rb","line_number":20,"run_time":0.00602694,"pending_message":null},{"id":"./spec/nintendo_eshop_spec.rb[1:1]","description":"has a version number","full_description":"NintendoEshop has a version number","status":"passed","file_path":"./spec/nintendo_eshop_spec.rb","line_number":2,"run_time":0.000361282,"pending_message":null}],"summary":{"duration":0.013353587,"example_count":3,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"3 examples, 0 failures"}
|
data/test_results_xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<testsuite name="rspec" tests="3" skipped="0" failures="0" errors="0" time="0.012374" timestamp="2019-06-22T04:13:21+00:00" hostname="07feaddbd13b">
|
3
|
+
<properties>
|
4
|
+
<property name="seed" value="64681"/>
|
5
|
+
</properties>
|
6
|
+
<testcase classname="spec.nintendo_eshop.game_spec" name="NintendoEshop::Game.retrieve retrieves a sale game from the Nintendo eShop API" file="./spec/nintendo_eshop/game_spec.rb" time="0.005981"></testcase>
|
7
|
+
<testcase classname="spec.nintendo_eshop.game_spec" name="NintendoEshop::Game.retrieve retrieves a non-sale game from the Nintendo eShop API" file="./spec/nintendo_eshop/game_spec.rb" time="0.003820"></testcase>
|
8
|
+
<testcase classname="spec.nintendo_eshop_spec" name="NintendoEshop has a version number" file="./spec/nintendo_eshop_spec.rb" time="0.000376"></testcase>
|
9
|
+
</testsuite>
|
metadata
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nintendo_eshop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Peyton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debase
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ramsey_cop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec_junit_formatter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ruby-debug-ide
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: solargraph
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- peytorb@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".circleci/config.yml"
|
161
|
+
- ".circleci/setup-rubygems.sh"
|
162
|
+
- ".devcontainer/Dockerfile"
|
163
|
+
- ".devcontainer/devcontainer.json"
|
164
|
+
- ".gitattributes"
|
165
|
+
- ".gitignore"
|
166
|
+
- ".rspec"
|
167
|
+
- ".rspec_status"
|
168
|
+
- ".rubocop.yml"
|
169
|
+
- Gemfile
|
170
|
+
- Gemfile.lock
|
171
|
+
- LICENSE
|
172
|
+
- README.md
|
173
|
+
- Rakefile
|
174
|
+
- bin/console
|
175
|
+
- bin/setup
|
176
|
+
- lib/nintendo_eshop.rb
|
177
|
+
- lib/nintendo_eshop/api_request.rb
|
178
|
+
- lib/nintendo_eshop/game.rb
|
179
|
+
- lib/nintendo_eshop/version.rb
|
180
|
+
- nintendo_eshop.gemspec
|
181
|
+
- test_results
|
182
|
+
- test_results_xml
|
183
|
+
homepage: https://github.com/rickpeyton/nintendo_eshop
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
metadata: {}
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
require_paths:
|
190
|
+
- lib
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">"
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: 1.3.1
|
201
|
+
requirements: []
|
202
|
+
rubygems_version: 3.0.3
|
203
|
+
signing_key:
|
204
|
+
specification_version: 4
|
205
|
+
summary: Retrieve game prices from the Nintendo eShop
|
206
|
+
test_files: []
|