Class: PlayStationNetwork::U::User

Inherits:
Object
  • Object
show all
Defined in:
lib/playstationnetwork/u/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(membership, avatar, username, about, country, region, total, platinum, gold, silver, bronze, total_possible, points_base, points, points_next, level, projected_level, progress, projected_progress, total_games, completed_games, completion_percentage, world_rank, region_rank, hardcore_rank) ⇒ User

Returns a new instance of User.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/playstationnetwork/u/user.rb', line 12

def initialize(
    membership, avatar, username, about, country, region,
    total, platinum, gold, silver, bronze, total_possible,
    points_base, points, points_next,
    level, projected_level, progress, projected_progress,
    total_games, completed_games, completion_percentage, world_rank, region_rank, hardcore_rank
  )

  # Build the Profile Hash
  #
  psn_profile = Hash.new
  psn_profile[:membership] = membership.to_i
  psn_profile[:avatar]     = avatar
  psn_profile[:username]   = username
  psn_profile[:about]      = about
  psn_profile[:location]   = Hash.new
  psn_profile[:location][:country] = country
  psn_profile[:location][:region]  = region

  # Build the Trophies hash
  #
  psn_profile_trophies = Hash.new
  psn_profile_trophies[:total]          = total.to_i
  psn_profile_trophies[:platinum]       = platinum.to_i
  psn_profile_trophies[:gold]           = gold.to_i
  psn_profile_trophies[:silver]         = silver.to_i
  psn_profile_trophies[:bronze]         = bronze.to_i
  psn_profile_trophies[:total_possible] = total_possible.to_i

  # Build the Points hash
  #
  psn_profile_points = Hash.new
  psn_profile_points[:base]   = points_base.to_i
  psn_profile_points[:actual] = points.to_i
  psn_profile_points[:next]   = points_next.to_i

  # Build the Level hash
  #
  psn_profile_level = Hash.new
  psn_profile_level[:level]              = level.to_i
  psn_profile_level[:projected_level]    = projected_level.to_i
  psn_profile_level[:progress]           = progress.to_f
  psn_profile_level[:projected_progress] = projected_progress.to_f

  # Build the Points hash
  #
  psn_profile_stats = Hash.new
  psn_profile_stats[:games]                 = total_games.to_i
  psn_profile_stats[:completed_games]       = completed_games.to_i
  psn_profile_stats[:completion_percentage] = completion_percentage.to_f
  psn_profile_stats[:rank]                  = Hash.new
  psn_profile_stats[:rank][:world_rank]     = world_rank.to_i
  psn_profile_stats[:rank][:region_rank]    = region_rank.to_i
  psn_profile_stats[:rank][:hardcore_rank]  = hardcore_rank.to_i

  self.profile  = psn_profile
  self.trophies = psn_profile_trophies
  self.level    = psn_profile_level
  self.points   = psn_profile_points
  self.stats    = psn_profile_stats

end

Instance Attribute Details

#aboutObject

Returns the value of attribute about.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def about
  @about
end

#avatarObject

Returns the value of attribute avatar.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def avatar
  @avatar
end

#bronzeObject

Returns the value of attribute bronze.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def bronze
  @bronze
end

#completed_gamesObject

Returns the value of attribute completed_games.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def completed_games
  @completed_games
end

#completion_percentageObject

Returns the value of attribute completion_percentage.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def completion_percentage
  @completion_percentage
end

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def country
  @country
end

#goldObject

Returns the value of attribute gold.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def gold
  @gold
end

#hardcore_rankObject

Returns the value of attribute hardcore_rank.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def hardcore_rank
  @hardcore_rank
end

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def level
  @level
end

#membershipObject

Returns the value of attribute membership.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def membership
  @membership
end

#platinumObject

Returns the value of attribute platinum.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def platinum
  @platinum
end

#pointsObject

Returns the value of attribute points.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def points
  @points
end

#points_baseObject

Returns the value of attribute points_base.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def points_base
  @points_base
end

#points_nextObject

Returns the value of attribute points_next.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def points_next
  @points_next
end

#profileObject

Returns the value of attribute profile.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def profile
  @profile
end

#progressObject

Returns the value of attribute progress.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def progress
  @progress
end

#projected_levelObject

Returns the value of attribute projected_level.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def projected_level
  @projected_level
end

#projected_progressObject

Returns the value of attribute projected_progress.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def projected_progress
  @projected_progress
end

#regionObject

Returns the value of attribute region.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def region
  @region
end

#region_rankObject

Returns the value of attribute region_rank.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def region_rank
  @region_rank
end

#silverObject

Returns the value of attribute silver.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def silver
  @silver
end

#statsObject

Returns the value of attribute stats.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def stats
  @stats
end

#totalObject

Returns the value of attribute total.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def total
  @total
end

#total_gamesObject

Returns the value of attribute total_games.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def total_games
  @total_games
end

#total_possibleObject

Returns the value of attribute total_possible.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def total_possible
  @total_possible
end

#trophiesObject

Returns the value of attribute trophies.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def trophies
  @trophies
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def username
  @username
end

#world_rankObject

Returns the value of attribute world_rank.



5
6
7
# File 'lib/playstationnetwork/u/user.rb', line 5

def world_rank
  @world_rank
end

Class Method Details

.profile(psn_user_id) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/playstationnetwork/u/user.rb', line 75

def self.profile(psn_user_id)
  options  = PlayStationNetwork::API.config.merge({ user_id: psn_user_id })
  response = PlayStationNetwork::API.post('/psnGetUser', body: options)

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

    self.new(
      parsed['psnplus'],
      parsed['avatar'],
      parsed['psn_id'],
      parsed['about_me'],
      parsed['country'],
      parsed['region'],

      parsed['total'],
      parsed['platinum'],
      parsed['gold'],
      parsed['silver'],
      parsed['bronze'],
      parsed['total_possible_trophies'],

      parsed['base'],
      parsed['points'],
      parsed['next'],

      parsed['level'],
      parsed['projected_level'],
      parsed['progress'],
      parsed['projected_progress'],

      parsed['total_games'],
      parsed['games_complete'],
      parsed['completion_percentage'],
      parsed['worldrank'],
      parsed['regionrank'],
      parsed['hardcore_rank']

    )
  else
    raise response.response
  end
end