Class: NintendoEshop::Game
- Inherits:
-
APIRequest
- Object
- APIRequest
- NintendoEshop::Game
- Defined in:
- lib/nintendo_eshop/game.rb
Instance Attribute Summary collapse
-
#art ⇒ Object
Returns the value of attribute art.
-
#id ⇒ Object
Returns the value of attribute id.
-
#msrp ⇒ Object
Returns the value of attribute msrp.
-
#object_id ⇒ Object
Returns the value of attribute object_id.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#sale_price ⇒ Object
Returns the value of attribute sale_price.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #current_price ⇒ Object
-
#initialize(id: nil, object_id: nil) ⇒ Game
constructor
A new instance of Game.
- #refresh ⇒ Object
Constructor Details
#initialize(id: nil, object_id: nil) ⇒ Game
Returns a new instance of Game.
12 13 14 15 |
# File 'lib/nintendo_eshop/game.rb', line 12 def initialize(id: nil, object_id: nil) self.id = id self.object_id = object_id end |
Instance Attribute Details
#art ⇒ Object
Returns the value of attribute art.
3 4 5 |
# File 'lib/nintendo_eshop/game.rb', line 3 def art @art end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/nintendo_eshop/game.rb', line 4 def id @id end |
#msrp ⇒ Object
Returns the value of attribute msrp.
5 6 7 |
# File 'lib/nintendo_eshop/game.rb', line 5 def msrp @msrp end |
#object_id ⇒ Object
Returns the value of attribute object_id.
6 7 8 |
# File 'lib/nintendo_eshop/game.rb', line 6 def object_id @object_id end |
#platform ⇒ Object
Returns the value of attribute platform.
7 8 9 |
# File 'lib/nintendo_eshop/game.rb', line 7 def platform @platform end |
#sale_price ⇒ Object
Returns the value of attribute sale_price.
8 9 10 |
# File 'lib/nintendo_eshop/game.rb', line 8 def sale_price @sale_price end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/nintendo_eshop/game.rb', line 9 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/nintendo_eshop/game.rb', line 10 def url @url end |
Class Method Details
.retrieve_by(id_type = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/nintendo_eshop/game.rb', line 36 def retrieve_by(id_type = {}) validate_argument(id_type) instance = new(id_type) instance.refresh end |
Instance Method Details
#current_price ⇒ Object
31 32 33 |
# File 'lib/nintendo_eshop/game.rb', line 31 def current_price sale_price || msrp end |
#refresh ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nintendo_eshop/game.rb', line 17 def refresh response = request(:post, to_json: body) result = if response.dig(:hits)&.any? response.dig(:hits, 0) elsif response.dig(:results)&.any? response.dig(:results, 0) else raise InvalidRequestError, "ID not found" end refresh_object(result) self end |