Class: NintendoEshop::Game

Inherits:
APIRequest show all
Defined in:
lib/nintendo_eshop/game.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#artObject

Returns the value of attribute art.



3
4
5
# File 'lib/nintendo_eshop/game.rb', line 3

def art
  @art
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/nintendo_eshop/game.rb', line 4

def id
  @id
end

#msrpObject

Returns the value of attribute msrp.



5
6
7
# File 'lib/nintendo_eshop/game.rb', line 5

def msrp
  @msrp
end

#object_idObject

Returns the value of attribute object_id.



6
7
8
# File 'lib/nintendo_eshop/game.rb', line 6

def object_id
  @object_id
end

#platformObject

Returns the value of attribute platform.



7
8
9
# File 'lib/nintendo_eshop/game.rb', line 7

def platform
  @platform
end

#sale_priceObject

Returns the value of attribute sale_price.



8
9
10
# File 'lib/nintendo_eshop/game.rb', line 8

def sale_price
  @sale_price
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/nintendo_eshop/game.rb', line 9

def title
  @title
end

#urlObject

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_priceObject



31
32
33
# File 'lib/nintendo_eshop/game.rb', line 31

def current_price
  sale_price || msrp
end

#refreshObject



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