nintendo_eshop 0.1.1 → 0.2.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: b67c846439c788d7c5658ad903b43689023be5e7aaeb247c016070d3c5f8d371
4
- data.tar.gz: b05f285d40a426690191c7cfe9b3c0739ffeb2b22c0635dfed62fd10e74868f3
3
+ metadata.gz: 0d874bca76474ca9bc0faafb383b2b516f732cf9cd76ebf0685ac63ed5da5b06
4
+ data.tar.gz: a2beeed00c829013a7c8427ace76c88079a36c9df84d31e87ebdb5ff34566a10
5
5
  SHA512:
6
- metadata.gz: 2a6e281b6714960900c5e316c108efe37c94aea905aaaeedeb4d2da1f3771d613440e02480418f0bc9c2492e3aeecb2712c199f71c2bd2af3eaee305572f3205
7
- data.tar.gz: 350d90b61533e3fa1648597d75b0eaaf074f1077774754a6a6ec8a76610dd5630da12dc50a3735673e45405c4136b0fce8c3c210611feff7e403ce91d9a267e8
6
+ metadata.gz: ec4eee7216a52d4232762570de13e73a804c2870afbe2d29ed557c549d25338ba78f658208eeecc65d1c8498f3a05eeef634b68b6ba32485be75238d2ef50911
7
+ data.tar.gz: e3f0f5b3d293aa387050abbdb5fef4f890c78eecf25fcbb1ae7c3d386db2fcc198db4f3d805bb2e45c4d8b740aa29e762689b889c08b15e3a829e1a0d4307e76
@@ -1,11 +1,11 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------------------------ | ------ | --------------- |
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 |
3
+ ./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.13332 seconds |
4
+ ./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00681 seconds |
5
+ ./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00613 seconds |
6
+ ./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.0054 seconds |
7
+ ./spec/nintendo_eshop/game_spec.rb[1:1:4] | passed | 0.00744 seconds |
8
+ ./spec/nintendo_eshop/game_spec.rb[1:1:5] | passed | 0.00035 seconds |
9
+ ./spec/nintendo_eshop/games_list_spec.rb[1:1] | passed | 0.00204 seconds |
10
+ ./spec/nintendo_eshop/games_list_spec.rb[1:2:1] | passed | 0.00552 seconds |
11
+ ./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.0042 seconds |
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nintendo_eshop (0.1.1)
4
+ nintendo_eshop (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -34,20 +34,28 @@ Use the provided `base_url`, `api_key` and `app_id`. These are provided as confi
34
34
  NintendoEshop.base_url = "https://u3b6gr4ua3-dsn.algolia.net"
35
35
  NintendoEshop.api_key = "9a20c93440cf63cf1a7008d75f7438bf"
36
36
  NintendoEshop.app_id = "U3B6GR4UA3"
37
+ ```
37
38
 
38
39
  ### Retrieve a game by ID (nsuid)
39
40
 
41
+ ```ruby
40
42
  game = NintendoEshop::Game.retrieve_by(id: "70010000001130")
41
43
 
42
- game.art # "/content/dam/noa/en_US/games/switch/s/super-mario-odyssey-switch/Switch_SuperMarioOdyssey_box.png"
44
+ game.art # "https://www.nintendo.com/content/dam/noa/en_US/games/switch/s/su..."
45
+ game.categories # [ "Action", "Platformer" ]
43
46
  game.current_price # 59.99
47
+ game.description # "Use amazing new abilities\u2014like the power to capture..."
48
+ game.esrb # "Everyone 10+"
44
49
  game.id # "70010000001130"
45
50
  game.msrp # 59.99
46
- game.object_id # 3ce3fb54-5f95-3a24-9101-7faa694c4b6f
51
+ game.object_id # "3ce3fb54-5f95-3a24-9101-7faa694c4b6f"
47
52
  game.platform # "Nintendo Switch"
53
+ game.release_date # #<Date: 2017-10-26 ...>
54
+ game.release_date_pretty # "Oct 26, 2017"
55
+ game.sale_percent # nil
48
56
  game.sale_price # nil
49
- game.title # Super Mario Odyssey"
50
- game.url # "/games/detail/super-mario-odyssey-switch"
57
+ game.title # "Super Mario Odyssey"
58
+ game.url # "https://www.nintendo.com/games/detail/super-mario-odyssey-switch">
51
59
  ```
52
60
 
53
61
  Or a game on sale
@@ -55,30 +63,27 @@ Or a game on sale
55
63
  ```ruby
56
64
  game = NintendoEshop::Game.retrieve_by(id: "70010000001539")
57
65
 
58
- game.art # "/content/dam/noa/en_US/games/switch/s/sonic-forces-switch/Switch_SonicForces_box.png"
59
- game.current_price # 14.99
66
+ game.art # "https://www.nintendo.com/content/dam/.../Switch_SonicForces_box.png"
67
+ game.categories # [ "Action" ]
68
+ game.current_price # 9.99
69
+ game.description # "From the team that brought you Sonic Colors and Generati..."
70
+ game.esrb # "Everyone 10+"
60
71
  game.id # "70010000001539"
61
- game.msrp # 29.99
62
- game.object_id # 26322c64-9268-3a24-822e-5e10f9e5cfc9
72
+ game.msrp # 19.99
73
+ game.object_id # "26322c64-9268-3a24-822e-5e10f9e5cfc9"
63
74
  game.platform # "Nintendo Switch"
64
- game.sale_price # 14.99
75
+ game.release_date # #<Date: 2017-11-07 ...>
76
+ game.release_date_pretty # "Nov 07, 2017"
77
+ game.sale_percent # 50%
78
+ game.sale_price # 9.99
65
79
  game.title # "Sonic Forces"
66
- game.url # "/games/detail/sonic-forces-switch"
80
+ game.url # "https://www.nintendo.com/games/detail/sonic-forces-switch">
67
81
  ```
68
82
 
69
83
  Or by object_id
70
84
 
71
85
  ```ruby
72
86
  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
87
  ```
83
88
 
84
89
  ### Search by Title
@@ -1,6 +1,7 @@
1
1
  begin
2
2
  require "pry"
3
3
  rescue Exception; end # rubocop:disable Lint/HandleExceptions, Lint/RescueException
4
+ require "date"
4
5
  require "json"
5
6
  require "net/http"
6
7
 
@@ -1,10 +1,14 @@
1
1
  module NintendoEshop
2
2
  class Game < APIRequest
3
3
  attr_accessor :art
4
+ attr_accessor :categories
5
+ attr_accessor :description
6
+ attr_accessor :esrb
4
7
  attr_accessor :id
5
8
  attr_accessor :msrp
6
9
  attr_accessor :object_id
7
10
  attr_accessor :platform
11
+ attr_accessor :release_date
8
12
  attr_accessor :sale_price
9
13
  attr_accessor :title
10
14
  attr_accessor :url
@@ -32,6 +36,14 @@ module NintendoEshop
32
36
  sale_price || msrp
33
37
  end
34
38
 
39
+ def release_date_pretty
40
+ release_date.strftime("%b %d, %Y")
41
+ end
42
+
43
+ def sale_percent
44
+ ((1 - (sale_price / msrp)).round(2) * 100).to_i.to_s + "%" if sale_price
45
+ end
46
+
35
47
  class << self
36
48
  def retrieve_by(id_type = {})
37
49
  validate_argument(id_type)
@@ -72,7 +84,7 @@ module NintendoEshop
72
84
  {
73
85
  "indexName": "noa_aem_game_en_us",
74
86
  "objectID": object_id.to_s,
75
- "attributesToRetrieve": "url,objectID,title,nsuid,salePrice,msrp,boxArt,platform"
87
+ "attributesToRetrieve": "boxArt,categories,description,esrb,msrp,nsuid,objectID,platform,releaseDateMask,salePrice,title,url" # rubocop:disable Metrics/LineLength
76
88
  }
77
89
  ]
78
90
  }
@@ -86,15 +98,19 @@ module NintendoEshop
86
98
  end
87
99
  end
88
100
 
89
- def refresh_object(result)
90
- self.art = result.dig(:boxArt)
101
+ def refresh_object(result) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
102
+ self.art = "https://www.nintendo.com#{result.dig(:boxArt)}"
103
+ self.categories = result.dig(:categories)
104
+ self.description = result.dig(:description).tr("\n", " ").squeeze
105
+ self.esrb = result.dig(:esrb)
91
106
  self.id = result.dig(:nsuid)
92
107
  self.msrp = result.dig(:msrp)
93
108
  self.object_id = result.dig(:objectID)
94
109
  self.platform = result.dig(:platform)
110
+ self.release_date = Date.parse(result.dig(:releaseDateMask))
95
111
  self.sale_price = result.dig(:salePrice)
96
112
  self.title = result.dig(:title)
97
- self.url = result.dig(:url)
113
+ self.url = "https://www.nintendo.com#{result.dig(:url)}"
98
114
  end
99
115
  end
100
116
  end
@@ -42,16 +42,10 @@ module NintendoEshop
42
42
  "/1/indexes/noa_aem_game_en_us/query".freeze
43
43
  end
44
44
 
45
- def refresh_list_objects(objects) # rubocop:disable Metrics/MethodLength
45
+ def refresh_list_objects(objects)
46
46
  objects.map do |object|
47
47
  game = Game.new(id: object.dig(:nsuid))
48
- game.art = object.dig(:boxArt)
49
- game.msrp = object.dig(:msrp)
50
- game.object_id = object.dig(:objectID)
51
- game.platform = object.dig(:platform)
52
- game.sale_price = object.dig(:salePrice)
53
- game.title = object.dig(:title)
54
- game.url = object.dig(:url)
48
+ game.send(:refresh_object, object)
55
49
  game
56
50
  end
57
51
  end
@@ -1,3 +1,3 @@
1
1
  module NintendoEshop
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
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.1
4
+ version: 0.2.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-07-05 00:00:00.000000000 Z
11
+ date: 2019-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler