nintendo_eshop 0.1.0.alpha4 → 0.1.0

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: e399f05fe13f9ec613499cf69bc067ea100af0f9ceb26019cb49f5cd87c04e2b
4
- data.tar.gz: a8c433708538c30cec7bb587b37a3491ebeee696ad3bc15f1186dc6534061145
3
+ metadata.gz: 0b5aad1fc3ec9ae00b695d50e092876aeb6db8b5d4c19603ea905ba49fd3e88e
4
+ data.tar.gz: b5c26c915e8e5cc703c32152dd06b7e56378c964d77cec0ac12ff326ffe9caed
5
5
  SHA512:
6
- metadata.gz: 421f83bf9d48a559a730102479b4a55e780dcd41ac42bfed343f7684a14e23d5aa332dcdfd4b568048510cf996a8f49accf5ae76b4de68915be481467af52890
7
- data.tar.gz: 9cd06480f21d667383580dc57493e4ecf44ac1ac13dff64f92730007e7e41fa3046c9b2323497ecdc94768e93dc337916af310b6fc947706fa85e2ffa727fd67
6
+ metadata.gz: 7e1a501720baec7391a1e32f0343d3b5379d1e8355acf46b7d89f30276c993f336cfe4a8a2b99e4a4e9c0f4953351d83fa0ea75592035649c95e50b02603dacd
7
+ data.tar.gz: aeb1fd14ec3b5d370336949a19827c4cb23b4af9c33d29be17e893144e48e13db51ce5095e09469289e0b384c8edac854615493b23b8ea68a8abe2e419ba9f35
data/.codeclimate.yml CHANGED
@@ -1,11 +1,7 @@
1
1
  version: "2"
2
- # prepare:
3
- # fetch:
4
- # - url: "https://raw.githubusercontent.com/RamseyInHouse/ramsey-cop/master/default.yml"
5
- # path: "alternate-rubocop-path.yml"
6
2
  plugins:
7
3
  rubocop:
8
4
  enabled: true
9
- channel: "rubocop-0-67"
5
+ channel: "rubocop-0-71"
10
6
  config:
11
- file: "alternate-rubocop-path.yml"
7
+ file: ".rubocop.yml"
data/.rspec_status CHANGED
@@ -1,9 +1,11 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------------------------ | ------ | --------------- |
3
- ./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.14289 seconds |
4
- ./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00375 seconds |
5
- ./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00616 seconds |
6
- ./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.00564 seconds |
7
- ./spec/nintendo_eshop/games_list_spec.rb[1:1] | passed | 0.00254 seconds |
8
- ./spec/nintendo_eshop/games_list_spec.rb[1:2:1] | passed | 0.00393 seconds |
9
- ./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00331 seconds |
3
+ ./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.12552 seconds |
4
+ ./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.0032 seconds |
5
+ ./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00406 seconds |
6
+ ./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.0034 seconds |
7
+ ./spec/nintendo_eshop/game_spec.rb[1:1:4] | passed | 0.00478 seconds |
8
+ ./spec/nintendo_eshop/game_spec.rb[1:1:5] | passed | 0.00013 seconds |
9
+ ./spec/nintendo_eshop/games_list_spec.rb[1:1] | passed | 0.00227 seconds |
10
+ ./spec/nintendo_eshop/games_list_spec.rb[1:2:1] | passed | 0.00325 seconds |
11
+ ./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00127 seconds |
data/.rubocop.yml CHANGED
@@ -1,6 +1,90 @@
1
- inherit_gem:
2
- ramsey_cop:
3
- - default.yml
1
+ require: rubocop-performance
4
2
 
5
3
  AllCops:
6
- TargetRubyVersion: 2.4
4
+ Exclude:
5
+ - db/schema.rb
6
+ - vendor/**/*
7
+ TargetRubyVersion: 2.4.6
8
+
9
+ Documentation:
10
+ Enabled: false
11
+
12
+ Layout/AccessModifierIndentation:
13
+ EnforcedStyle: outdent
14
+
15
+ Metrics/AbcSize:
16
+ Exclude:
17
+ - spec/**/*
18
+ - test/**/*
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - config/initializers/*
23
+ - config/routes.rb
24
+ - Gemfile
25
+ - spec/**/*
26
+ - test/**/*
27
+ - "*.gemspec"
28
+ - "**/*.rake"
29
+
30
+ Metrics/BlockNesting:
31
+ Exclude:
32
+ - spec/**/*
33
+ - test/**/*
34
+
35
+ Metrics/CyclomaticComplexity:
36
+ Exclude:
37
+ - spec/**/*
38
+ - test/**/*
39
+
40
+ Metrics/LineLength:
41
+ Max: 120
42
+ Exclude:
43
+ - config/routes.rb
44
+ - config/routes/*
45
+ - db/migrate/*
46
+
47
+ Metrics/MethodLength:
48
+ Exclude:
49
+ - db/migrate/*
50
+ - spec/**/*
51
+ - test/**/*
52
+
53
+ Metrics/ModuleLength:
54
+ Exclude:
55
+ - spec/**/*
56
+ - test/**/*
57
+
58
+ Style/Alias:
59
+ EnforcedStyle: prefer_alias_method
60
+
61
+ Style/AndOr:
62
+ EnforcedStyle: conditionals
63
+
64
+ Style/DateTime:
65
+ Enabled: false
66
+
67
+ Style/FrozenStringLiteralComment:
68
+ Enabled: false
69
+
70
+ Style/Lambda:
71
+ Enabled: false
72
+
73
+ Style/NumericLiterals:
74
+ Enabled: false
75
+
76
+ Style/PercentLiteralDelimiters:
77
+ PreferredDelimiters:
78
+ '%i': ()
79
+ '%I': ()
80
+ '%q': ()
81
+ '%Q': ()
82
+ '%r': '{}'
83
+ '%s': ()
84
+ '%w': ()
85
+ '%W': ()
86
+ '%x': ()
87
+
88
+ Style/StringLiterals:
89
+ EnforcedStyle: double_quotes
90
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nintendo_eshop (0.1.0.alpha4)
4
+ nintendo_eshop (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -36,9 +36,6 @@ GEM
36
36
  public_suffix (3.1.0)
37
37
  rainbow (3.0.0)
38
38
  rake (12.3.2)
39
- ramsey_cop (0.14.0)
40
- rubocop (~> 0.62)
41
- rubocop-performance
42
39
  reverse_markdown (1.1.0)
43
40
  nokogiri
44
41
  rspec (3.8.0)
@@ -69,12 +66,12 @@ GEM
69
66
  rake (>= 0.8.1)
70
67
  ruby-progressbar (1.10.1)
71
68
  safe_yaml (1.0.5)
72
- simplecov (0.16.1)
69
+ simplecov (0.17.0)
73
70
  docile (~> 1.1)
74
71
  json (>= 1.8, < 3)
75
72
  simplecov-html (~> 0.10.0)
76
73
  simplecov-html (0.10.2)
77
- solargraph (0.33.2)
74
+ solargraph (0.34.2)
78
75
  backport (~> 1.1)
79
76
  bundler (>= 1.17.2)
80
77
  htmlentities (~> 4.3, >= 4.3.4)
@@ -93,7 +90,7 @@ GEM
93
90
  addressable (>= 2.3.6)
94
91
  crack (>= 0.3.2)
95
92
  hashdiff (>= 0.4.0, < 2.0.0)
96
- yard (0.9.19)
93
+ yard (0.9.20)
97
94
 
98
95
  PLATFORMS
99
96
  ruby
@@ -104,9 +101,10 @@ DEPENDENCIES
104
101
  nintendo_eshop!
105
102
  pry
106
103
  rake (~> 12.3)
107
- ramsey_cop
108
104
  rspec (~> 3.0)
109
105
  rspec_junit_formatter
106
+ rubocop (~> 0.71.0)
107
+ rubocop-performance
110
108
  ruby-debug-ide
111
109
  simplecov
112
110
  solargraph
data/README.md CHANGED
@@ -35,14 +35,15 @@ NintendoEshop.base_url = "https://u3b6gr4ua3-dsn.algolia.net"
35
35
  NintendoEshop.api_key = "9a20c93440cf63cf1a7008d75f7438bf"
36
36
  NintendoEshop.app_id = "U3B6GR4UA3"
37
37
 
38
- ### Retrieve a game by ID
38
+ ### Retrieve a game by ID (nsuid)
39
39
 
40
- game = NintendoEshop::Game.retrieve("70010000001130")
40
+ game = NintendoEshop::Game.retrieve_by(id: "70010000001130")
41
41
 
42
42
  game.art # "/content/dam/noa/en_US/games/switch/s/super-mario-odyssey-switch/Switch_SuperMarioOdyssey_box.png"
43
43
  game.current_price # 59.99
44
44
  game.id # "70010000001130"
45
45
  game.msrp # 59.99
46
+ game.object_id # 3ce3fb54-5f95-3a24-9101-7faa694c4b6f
46
47
  game.platform # "Nintendo Switch"
47
48
  game.sale_price # nil
48
49
  game.title # Super Mario Odyssey"
@@ -52,18 +53,34 @@ game.url # "/games/detail/super-mario-odyssey-switch"
52
53
  Or a game on sale
53
54
 
54
55
  ```ruby
55
- game = NintendoEshop::Game.retrieve("70010000001539")
56
+ game = NintendoEshop::Game.retrieve_by(id: "70010000001539")
56
57
 
57
58
  game.art # "/content/dam/noa/en_US/games/switch/s/sonic-forces-switch/Switch_SonicForces_box.png"
58
59
  game.current_price # 14.99
59
60
  game.id # "70010000001539"
60
61
  game.msrp # 29.99
62
+ game.object_id # 26322c64-9268-3a24-822e-5e10f9e5cfc9
61
63
  game.platform # "Nintendo Switch"
62
64
  game.sale_price # 14.99
63
65
  game.title # "Sonic Forces"
64
66
  game.url # "/games/detail/sonic-forces-switch"
65
67
  ```
66
68
 
69
+ Or by object_id
70
+
71
+ ```ruby
72
+ game = NintendoEshop::Game.retrieve_by(object_id: "26851cb3-4f10-333a-8d7c-f9cae4a9bc03")
73
+
74
+ game.id # "70010000001023"
75
+ game.object_id # "26851cb3-4f10-333a-8d7c-f9cae4a9bc03"
76
+ game.art # "/content/dam/noa/en_US/games/switch/b/bridge-constructor-portal-switch/Switch_BridgeConstructorPortal_box_eShop.png"
77
+ game.msrp # 14.99
78
+ game.platform # "Nintendo Switch"
79
+ game.sale_price # 7.49
80
+ game.title # "Bridge Constructor Portal"
81
+ game.url # "/games/detail/bridge-constructor-portal-switch"
82
+ ```
83
+
67
84
  ### Search by Title
68
85
 
69
86
  ```ruby
@@ -77,7 +94,7 @@ games.first.title # "Super Mario Odyssey: Starter"
77
94
  Error handling is still a work in progress
78
95
 
79
96
  ```ruby
80
- game = NintendoEshop::Game.retrieve("invalid id")
97
+ game = NintendoEshop::Game.retrieve_by(id: "invalid id")
81
98
 
82
99
  # => NintendoEshop::InvalidRequestError
83
100
  ```
@@ -24,5 +24,6 @@ module NintendoEshop
24
24
  end
25
25
 
26
26
  class Error < StandardError; end
27
+ class InvalidArgumentError < Error; end
27
28
  class InvalidRequestError < Error; end
28
29
  end
@@ -12,10 +12,9 @@ module NintendoEshop
12
12
  end
13
13
 
14
14
  def post(json: {})
15
- uri = URI("#{NintendoEshop.base_url}#{self.class::RESOURCE_PATH}?#{url_params}")
15
+ uri = URI("#{NintendoEshop.base_url}#{resource_path}?#{url_params}")
16
16
  response = NintendoEshop.client.post(uri, json: json)
17
17
  parsed_response = JSON.parse(response.body, symbolize_names: true)
18
- raise InvalidRequestError, "ID not found" if parsed_response.dig(:nbHits).zero?
19
18
 
20
19
  parsed_response
21
20
  end
@@ -3,20 +3,27 @@ module NintendoEshop
3
3
  attr_accessor :art
4
4
  attr_accessor :id
5
5
  attr_accessor :msrp
6
+ attr_accessor :object_id
6
7
  attr_accessor :platform
7
8
  attr_accessor :sale_price
8
9
  attr_accessor :title
9
10
  attr_accessor :url
10
11
 
11
- RESOURCE_PATH = "/1/indexes/noa_aem_game_en_us/query".freeze
12
-
13
- def initialize(id)
12
+ def initialize(id: nil, object_id: nil)
14
13
  self.id = id
14
+ self.object_id = object_id
15
15
  end
16
16
 
17
17
  def refresh
18
18
  response = request(:post, to_json: body)
19
- result = response.dig(:hits, 0)
19
+ result = if response.dig(:hits)&.any?
20
+ response.dig(:hits, 0)
21
+ elsif response.dig(:results)&.any?
22
+ response.dig(:results, 0)
23
+ else
24
+ raise InvalidRequestError, "ID not found"
25
+ end
26
+
20
27
  refresh_object(result)
21
28
  self
22
29
  end
@@ -25,14 +32,32 @@ module NintendoEshop
25
32
  sale_price || msrp
26
33
  end
27
34
 
28
- def self.retrieve(id)
29
- instance = new(id)
30
- instance.refresh
35
+ class << self
36
+ def retrieve_by(id_type = {})
37
+ validate_argument(id_type)
38
+ instance = new(id_type)
39
+ instance.refresh
40
+ end
41
+
42
+ private
43
+
44
+ def validate_argument(argument)
45
+ valid_args = argument.keys == [:id] || argument.keys == [:object_id]
46
+ raise InvalidArgumentError, "Only id: and object_id: have been implemented" unless valid_args
47
+ end
31
48
  end
32
49
 
33
50
  private
34
51
 
35
52
  def body
53
+ if id
54
+ query_body
55
+ elsif object_id
56
+ object_body
57
+ end
58
+ end
59
+
60
+ def query_body
36
61
  {
37
62
  "query": id.to_s,
38
63
  "restrictSearchableAttributes": [
@@ -41,10 +66,31 @@ module NintendoEshop
41
66
  }
42
67
  end
43
68
 
69
+ def object_body
70
+ {
71
+ "requests": [
72
+ {
73
+ "indexName": "noa_aem_game_en_us",
74
+ "objectID": object_id.to_s,
75
+ "attributesToRetrieve": "url,objectID,title,nsuid,salePrice,msrp,boxArt,platform"
76
+ }
77
+ ]
78
+ }
79
+ end
80
+
81
+ def resource_path
82
+ if id
83
+ "/1/indexes/noa_aem_game_en_us/query".freeze
84
+ elsif object_id
85
+ "/1/indexes/*/objects".freeze
86
+ end
87
+ end
88
+
44
89
  def refresh_object(result)
45
90
  self.art = result.dig(:boxArt)
46
91
  self.id = result.dig(:nsuid)
47
92
  self.msrp = result.dig(:msrp)
93
+ self.object_id = result.dig(:objectID)
48
94
  self.platform = result.dig(:platform)
49
95
  self.sale_price = result.dig(:salePrice)
50
96
  self.title = result.dig(:title)
@@ -5,8 +5,6 @@ module NintendoEshop
5
5
  attr_accessor :title
6
6
  attr_accessor :games
7
7
 
8
- RESOURCE_PATH = "/1/indexes/noa_aem_game_en_us/query".freeze
9
-
10
8
  def initialize(title)
11
9
  self.title = title
12
10
  end
@@ -40,11 +38,16 @@ module NintendoEshop
40
38
  }
41
39
  end
42
40
 
43
- def refresh_list_objects(objects)
41
+ def resource_path
42
+ "/1/indexes/noa_aem_game_en_us/query".freeze
43
+ end
44
+
45
+ def refresh_list_objects(objects) # rubocop:disable Metrics/MethodLength
44
46
  objects.map do |object|
45
- game = Game.new(object.dig(:nsuid))
47
+ game = Game.new(id: object.dig(:nsuid))
46
48
  game.art = object.dig(:boxArt)
47
49
  game.msrp = object.dig(:msrp)
50
+ game.object_id = object.dig(:objectID)
48
51
  game.platform = object.dig(:platform)
49
52
  game.sale_price = object.dig(:salePrice)
50
53
  game.title = object.dig(:title)
@@ -1,3 +1,3 @@
1
1
  module NintendoEshop
2
- VERSION = "0.1.0.alpha4".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -35,9 +35,10 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "debase"
36
36
  spec.add_development_dependency "pry"
37
37
  spec.add_development_dependency "rake", "~> 12.3"
38
- spec.add_development_dependency "ramsey_cop"
39
38
  spec.add_development_dependency "rspec", "~> 3.0"
40
39
  spec.add_development_dependency "rspec_junit_formatter"
40
+ spec.add_development_dependency "rubocop", "~> 0.71.0"
41
+ spec.add_development_dependency "rubocop-performance"
41
42
  spec.add_development_dependency "ruby-debug-ide"
42
43
  spec.add_development_dependency "simplecov"
43
44
  spec.add_development_dependency "solargraph"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nintendo_eshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Peyton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-25 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '12.3'
69
69
  - !ruby/object:Gem::Dependency
70
- name: ramsey_cop
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -81,21 +95,21 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rspec
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '3.0'
103
+ version: 0.71.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '3.0'
110
+ version: 0.71.0
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec_junit_formatter
112
+ name: rubocop-performance
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -188,7 +202,6 @@ files:
188
202
  - LICENSE
189
203
  - README.md
190
204
  - Rakefile
191
- - alternate-rubocop-path.yml
192
205
  - bin/console
193
206
  - bin/setup
194
207
  - lib/nintendo_eshop.rb
@@ -216,9 +229,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
229
  version: 2.4.6
217
230
  required_rubygems_version: !ruby/object:Gem::Requirement
218
231
  requirements:
219
- - - ">"
232
+ - - ">="
220
233
  - !ruby/object:Gem::Version
221
- version: 1.3.1
234
+ version: '0'
222
235
  requirements: []
223
236
  rubygems_version: 3.0.3
224
237
  signing_key:
@@ -1,90 +0,0 @@
1
- require: rubocop-performance
2
-
3
- AllCops:
4
- Exclude:
5
- - db/schema.rb
6
- - vendor/**/*
7
- TargetRubyVersion: 2.4.6
8
-
9
- Documentation:
10
- Enabled: false
11
-
12
- Layout/AccessModifierIndentation:
13
- EnforcedStyle: outdent
14
-
15
- Metrics/AbcSize:
16
- Exclude:
17
- - spec/**/*
18
- - test/**/*
19
-
20
- Metrics/BlockLength:
21
- Exclude:
22
- - config/initializers/*
23
- - config/routes.rb
24
- - Gemfile
25
- - spec/**/*
26
- - test/**/*
27
- - "*.gemspec"
28
- - "**/*.rake"
29
-
30
- Metrics/BlockNesting:
31
- Exclude:
32
- - spec/**/*
33
- - test/**/*
34
-
35
- Metrics/CyclomaticComplexity:
36
- Exclude:
37
- - spec/**/*
38
- - test/**/*
39
-
40
- Metrics/LineLength:
41
- Max: 120
42
- Exclude:
43
- - config/routes.rb
44
- - config/routes/*
45
- - db/migrate/*
46
-
47
- Metrics/MethodLength:
48
- Exclude:
49
- - db/migrate/*
50
- - spec/**/*
51
- - test/**/*
52
-
53
- Metrics/ModuleLength:
54
- Exclude:
55
- - spec/**/*
56
- - test/**/*
57
-
58
- Style/Alias:
59
- EnforcedStyle: prefer_alias_method
60
-
61
- Style/AndOr:
62
- EnforcedStyle: conditionals
63
-
64
- Style/DateTime:
65
- Enabled: false
66
-
67
- Style/FrozenStringLiteralComment:
68
- Enabled: false
69
-
70
- Style/Lambda:
71
- Enabled: false
72
-
73
- Style/NumericLiterals:
74
- Enabled: false
75
-
76
- Style/PercentLiteralDelimiters:
77
- PreferredDelimiters:
78
- '%i': ()
79
- '%I': ()
80
- '%q': ()
81
- '%Q': ()
82
- '%r': '{}'
83
- '%s': ()
84
- '%w': ()
85
- '%W': ()
86
- '%x': ()
87
-
88
- Style/StringLiterals:
89
- EnforcedStyle: double_quotes
90
- Enabled: true