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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16722724063cfd735832cc6a1e058bbeb6023b87c6856421c7f20887eee90db
4
- data.tar.gz: 6877920b5fd9c9a4dc4fbedeb12e6284212becb77c616631754eaedb306a64f4
3
+ metadata.gz: 9e94ec5b299a5682fbc2cbb5cd3657515dd88ddd20b6b1102da17bb9386d8149
4
+ data.tar.gz: ee16d11185eac66b1cf8c7ae802f6f971e41154bd83f14b10ed307c67938e9b8
5
5
  SHA512:
6
- metadata.gz: fc2c84062048e4a562cc0809e805175c2cff2ba134ad1d213522859c849d694c9764bf41e3af74d1ac2796d3ed92562df96e0a278624ceceb101944c5b799431
7
- data.tar.gz: cf726caaac49676c462818ea3f7b8facb51ae3e1968ccd27230ea546d1a3d4b469a4bb969f1a74838c846c6b9148ea62a0e70a48f44c25fcef7a08d794ef599e
6
+ metadata.gz: 1e87038f95f781ac0d4dabf85d57ba78d2e2570d4e7f39a7db8bf6f09e8531900ae0ff0c511ae09250b3fa26f4e2d8a6bc70bb969bed176d301c827ed15bbd97
7
+ data.tar.gz: 21747be84dda661be38463d61c8f0780fd2ac29dcdb405ce70b9ca966ec8a083555862864ba615f9bb4fb99cd7d4c9f64c804a6eee406bdca8d285cbc6d640c7
data/.rspec_status CHANGED
@@ -1,5 +1,7 @@
1
- example_id | status | run_time |
2
- ----------------------------------------- | ------ | --------------- |
3
- ./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00568 seconds |
4
- ./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.0112 seconds |
5
- ./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00086 seconds |
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nintendo_eshop (0.1.0.alpha2)
4
+ nintendo_eshop (0.1.0.alpha3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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, 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:
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(to_json: to_json)
10
+ post(json: to_json)
11
11
  end
12
12
  end
13
13
 
14
- def post(to_json: {})
14
+ def post(json: {})
15
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
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
- 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
20
+ parsed_response
30
21
  end
31
22
 
32
23
  def url_params
@@ -1,3 +1,3 @@
1
1
  module NintendoEshop
2
- VERSION = "0.1.0.alpha2".freeze
2
+ VERSION = "0.1.0.alpha3".freeze
3
3
  end
@@ -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.alpha2
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