Class: PlayStationNetwork::G::Game

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(psn_id, psn_hash, psn_type, psn_slug, name, cover, platforms, updated, checked, artworks, videos, total, platinum, gold, silver, bronze, points, points_platinum, average_percentage, owners, completers, completers_platinum, trophies_earned, played_this_week) ⇒ Game

Returns a new instance of Game.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/playstationnetwork/g/game.rb', line 11

def initialize(
    psn_id, psn_hash, psn_type, psn_slug, name, cover, platforms,
    updated, checked,
    artworks, videos,
    total, platinum, gold, silver, bronze,
    points, points_platinum, average_percentage, owners, completers, completers_platinum, trophies_earned, played_this_week
  )

  game_updates = Hash.new
  game_updates[:last_updated] = updated
  game_updates[:last_checked] = checked

  game_media = Hash.new
  game_media[:artworks] = artworks
  game_media[:videos]   = videos

  game_trophies = Hash.new
  game_trophies[:total]    = total
  game_trophies[:platinum] = platinum
  game_trophies[:gold]     = gold
  game_trophies[:silver]   = silver
  game_trophies[:bronze]   = bronze

  game_stats = Hash.new
  game_stats[:points]              = points
  game_stats[:points_platinum]     = points_platinum
  game_stats[:average_percentage]  = "#{average_percentage}%"
  game_stats[:owners]              = owners
  game_stats[:completers]          = completers
  game_stats[:completers_platinum] = completers_platinum
  game_stats[:trophies_earned]     = trophies_earned
  game_stats[:played_this_week]    = played_this_week

  self.psn_id    = psn_id
  self.psn_hash  = psn_hash
  self.psn_type  = psn_type
  self.psn_slug  = psn_slug
  self.name      = name
  self.cover     = cover
  self.platforms = platforms.split(',')
  self.media     = game_media
  self.updates   = game_updates
  self.trophies  = game_trophies
  self.stats     = game_stats
end

Instance Attribute Details

#average_percentageObject

Returns the value of attribute average_percentage.



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

def average_percentage
  @average_percentage
end

#bronzeObject

Returns the value of attribute bronze.



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

def bronze
  @bronze
end

#checkedObject

Returns the value of attribute checked.



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

def checked
  @checked
end

#completersObject

Returns the value of attribute completers.



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

def completers
  @completers
end

#completers_platinumObject

Returns the value of attribute completers_platinum.



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

def completers_platinum
  @completers_platinum
end

#coverObject

Returns the value of attribute cover.



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

def cover
  @cover
end

#goldObject

Returns the value of attribute gold.



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

def gold
  @gold
end

#mediaObject

Returns the value of attribute media.



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

def media
  @media
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#ownersObject

Returns the value of attribute owners.



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

def owners
  @owners
end

#platformsObject

Returns the value of attribute platforms.



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

def platforms
  @platforms
end

#platinumObject

Returns the value of attribute platinum.



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

def platinum
  @platinum
end

#played_this_weekObject

Returns the value of attribute played_this_week.



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

def played_this_week
  @played_this_week
end

#pointsObject

Returns the value of attribute points.



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

def points
  @points
end

#points_platinumObject

Returns the value of attribute points_platinum.



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

def points_platinum
  @points_platinum
end

#psn_hashObject

Returns the value of attribute psn_hash.



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

def psn_hash
  @psn_hash
end

#psn_idObject

Returns the value of attribute psn_id.



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

def psn_id
  @psn_id
end

#psn_slugObject

Returns the value of attribute psn_slug.



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

def psn_slug
  @psn_slug
end

#psn_typeObject

Returns the value of attribute psn_type.



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

def psn_type
  @psn_type
end

#silverObject

Returns the value of attribute silver.



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

def silver
  @silver
end

#statsObject

Returns the value of attribute stats.



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

def stats
  @stats
end

#totalObject

Returns the value of attribute total.



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

def total
  @total
end

#trophiesObject

Returns the value of attribute trophies.



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

def trophies
  @trophies
end

#trophies_earnedObject

Returns the value of attribute trophies_earned.



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

def trophies_earned
  @trophies_earned
end

#updatedObject

Returns the value of attribute updated.



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

def updated
  @updated
end

#updatesObject

Returns the value of attribute updates.



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

def updates
  @updates
end

Class Method Details

.find(psn_game_id) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/playstationnetwork/g/game.rb', line 57

def self.find(psn_game_id)
  options  = PlayStationNetwork::API.config.merge({ npcommid: psn_game_id })
  response = PlayStationNetwork::API.post('/psnGetGame', body: options)

  if response.success?
    parsed = JSON.parse(response)

    new(
      parsed['npcommid'],
      parsed['game_hash'],
      parsed['content_Type'],
      parsed['unique_url'],
      parsed['title'],
      parsed['image'],
      parsed['pf'],
      parsed['updated'].to_i,
      parsed['meta_check'].to_i,
      parsed['screenshots'],
      parsed['videos'],
      parsed['total'].to_i,
      parsed['platinum'].to_i,
      parsed['gold'].to_i,
      parsed['silver'].to_i,
      parsed['bronze'].to_i,
      parsed['total_points'].to_i,
      parsed['total_points_plat'].to_i,
      parsed['average_perc'].to_f,
      parsed['owners'].to_i,
      parsed['completers'].to_i,
      parsed['platters'].to_i,
      parsed['trophies_earned'].to_i,
      parsed['played_this_week'].to_i
    )
  else
    raise response.response
  end
end