nintendo_eshop 0.1.0.alpha2 → 0.1.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +7 -5
- data/Gemfile.lock +1 -1
- data/README.md +18 -1
- data/lib/nintendo_eshop/api_client.rb +21 -0
- data/lib/nintendo_eshop/api_request.rb +6 -15
- data/lib/nintendo_eshop/version.rb +1 -1
- data/lib/nintendo_eshop.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e94ec5b299a5682fbc2cbb5cd3657515dd88ddd20b6b1102da17bb9386d8149
|
4
|
+
data.tar.gz: ee16d11185eac66b1cf8c7ae802f6f971e41154bd83f14b10ed307c67938e9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e87038f95f781ac0d4dabf85d57ba78d2e2570d4e7f39a7db8bf6f09e8531900ae0ff0c511ae09250b3fa26f4e2d8a6bc70bb969bed176d301c827ed15bbd97
|
7
|
+
data.tar.gz: 21747be84dda661be38463d61c8f0780fd2ac29dcdb405ce70b9ca966ec8a083555862864ba615f9bb4fb99cd7d4c9f64c804a6eee406bdca8d285cbc6d640c7
|
data/.rspec_status
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/
|
4
|
-
./spec/nintendo_eshop/game_spec.rb[1:1:
|
5
|
-
./spec/
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------------------ | ------ | --------------- |
|
3
|
+
./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.11786 seconds |
|
4
|
+
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00419 seconds |
|
5
|
+
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00606 seconds |
|
6
|
+
./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.00398 seconds |
|
7
|
+
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00083 seconds |
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -62,6 +62,16 @@ game.title # "Sonic Forces"
|
|
62
62
|
game.url # "/games/detail/sonic-forces-switch"
|
63
63
|
```
|
64
64
|
|
65
|
+
## Errors
|
66
|
+
|
67
|
+
Error handling is still a work in progress
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
game = NintendoEshop::Game.retrieve("invalid id")
|
71
|
+
|
72
|
+
# => NintendoEshop::InvalidRequestError
|
73
|
+
```
|
74
|
+
|
65
75
|
## Development
|
66
76
|
|
67
77
|
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.
|
@@ -80,7 +90,14 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
80
90
|
|
81
91
|
CircleCi is used to push releases to rubygems.org
|
82
92
|
|
83
|
-
To release
|
93
|
+
To release
|
94
|
+
|
95
|
+
* Edit the version.rb file
|
96
|
+
* `bundle`
|
97
|
+
* Commit that to your master branch
|
98
|
+
* Create and push a git tag with the same name as your version
|
99
|
+
|
100
|
+
Example
|
84
101
|
|
85
102
|
```
|
86
103
|
git tag -a 0.1.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module NintendoEshop
|
2
|
+
class APIClient
|
3
|
+
class << self
|
4
|
+
def post(uri, json: {})
|
5
|
+
http = setup_http(uri)
|
6
|
+
req = Net::HTTP::Post.new(uri)
|
7
|
+
req.add_field "Accept", "application/json"
|
8
|
+
req.add_field "Content-Type", "application/json"
|
9
|
+
req.body = JSON.dump(json)
|
10
|
+
http.request(req)
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_http(uri)
|
14
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
http.use_ssl = true
|
16
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
17
|
+
http
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -7,26 +7,17 @@ module NintendoEshop
|
|
7
7
|
def request(method, to_json: {})
|
8
8
|
case method
|
9
9
|
when :post
|
10
|
-
post(
|
10
|
+
post(json: to_json)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def post(
|
14
|
+
def post(json: {})
|
15
15
|
uri = URI("#{NintendoEshop.base_url}#{self.class::RESOURCE_PATH}?#{url_params}")
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
16
|
+
response = NintendoEshop.client.post(uri, json: json)
|
17
|
+
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
18
|
+
raise InvalidRequestError, "ID not found" if parsed_response.dig(:nbHits).zero?
|
24
19
|
|
25
|
-
|
26
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
-
http.use_ssl = true
|
28
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
29
|
-
http
|
20
|
+
parsed_response
|
30
21
|
end
|
31
22
|
|
32
23
|
def url_params
|
data/lib/nintendo_eshop.rb
CHANGED
@@ -4,6 +4,7 @@ rescue StandardError; end # rubocop:disable Lint/HandleExceptions
|
|
4
4
|
require "json"
|
5
5
|
require "net/http"
|
6
6
|
|
7
|
+
require_relative "nintendo_eshop/api_client"
|
7
8
|
require_relative "nintendo_eshop/api_request"
|
8
9
|
require_relative "nintendo_eshop/game"
|
9
10
|
require_relative "nintendo_eshop/version"
|
@@ -13,7 +14,14 @@ module NintendoEshop
|
|
13
14
|
attr_accessor :api_key
|
14
15
|
attr_accessor :app_id
|
15
16
|
attr_accessor :base_url
|
17
|
+
|
18
|
+
attr_writer :client
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= NintendoEshop::APIClient
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
class Error < StandardError; end
|
26
|
+
class InvalidRequestError < Error; end
|
19
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nintendo_eshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Peyton
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- bin/console
|
190
190
|
- bin/setup
|
191
191
|
- lib/nintendo_eshop.rb
|
192
|
+
- lib/nintendo_eshop/api_client.rb
|
192
193
|
- lib/nintendo_eshop/api_request.rb
|
193
194
|
- lib/nintendo_eshop/game.rb
|
194
195
|
- lib/nintendo_eshop/version.rb
|