Class: PlayStationNetwork::G::Games

Inherits:
Object
  • Object
show all
Defined in:
lib/playstationnetwork/g/games.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success, total_games, games) ⇒ Games

Returns a new instance of Games.



11
12
13
14
15
# File 'lib/playstationnetwork/g/games.rb', line 11

def initialize(success, total_games, games)
  self.success     = success
  self.total_games = total_games
  self.games       = games
end

Instance Attribute Details

#gamesObject

Returns the value of attribute games.



9
10
11
# File 'lib/playstationnetwork/g/games.rb', line 9

def games
  @games
end

#successObject

Returns the value of attribute success.



9
10
11
# File 'lib/playstationnetwork/g/games.rb', line 9

def success
  @success
end

#total_gamesObject

Returns the value of attribute total_games.



9
10
11
# File 'lib/playstationnetwork/g/games.rb', line 9

def total_games
  @total_games
end

Class Method Details

.all(psn_platform = 'all') ⇒ Object

Available platform options

> all returns all PlayStation Network games

> psp2 returns all PSP games

> ps3 returns all PS3 games

> ps4 returns all PS4 games



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/playstationnetwork/g/games.rb', line 24

def self.all(psn_platform = 'all')
  options  = PlayStationNetwork::API.config.merge({ platform: psn_platform })
  response = PlayStationNetwork::API.post('/psnListGames', body: options)

  sanitized_response = response.gsub('<?xml version=\"1.0\"?>', '').gsub('<\/', '</').tr('"', '')
  parsed_response    = Hash.from_xml(sanitized_response)

  if response.success?
    new(
      (parsed_response['psn_api']['success'].to_i == 1 ? true : false),
      parsed_response['psn_api']['game'].size,
      parsed_response['psn_api']['game']
    )
  else
    raise response.response
  end
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/playstationnetwork/g/games.rb', line 42

def self.popular
  response = PlayStationNetwork::API.post('/psnPopularThisWeek')

  sanitized_response = response.gsub('<?xml version=\"1.0\"?>', '').gsub('<\/', '</').tr('"', '')
  parsed_response    = Hash.from_xml(sanitized_response)

  if response.success?
    new(
      (parsed_response['psn_api']['success'].to_i == 1 ? true : false),
      parsed_response['psn_api']['game'].size,
      parsed_response['psn_api']['game']
    )
  else
    raise response.response
  end
end