Class: GameLockerAPI::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/gamelocker_api/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, index = nil) ⇒ Match

Returns a new instance of Match.



6
7
8
9
10
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
56
57
58
59
60
# File 'lib/gamelocker_api/match.rb', line 6

def initialize(data, index = nil)
  if index
    self.uuid = data['data'][index]['id']
    self.shard_id = data['data'][index]['attributes']['shardId']
    self.created_at = data['data'][index]['attributes']['createdAt']
    self.duration = data['data'][index]['attributes']['duration']
    self.gamemode = data['data'][index]['attributes']['gameMode']
    self.end_game_reason = data['data'][index]['attributes']['stats']['endGameReason']
  else
    self.uuid = data['data']['id']
    self.shard_id = data['data']['attributes']['shardId']
    self.created_at = data['data']['attributes']['createdAt']
    self.duration = data['data']['attributes']['duration']
    self.gamemode = data['data']['attributes']['gameMode']
    self.end_game_reason = data['data']['attributes']['stats']['endGameReason']
  end
  self.telemetry_url = nil
  self.rosters = []
  self.red_team = []
  self.blue_team= []
  self.players = []
  self.participants = []

  if index
    data['included'].each do |wanted|
      self.telemetry_url = wanted['attributes']['URL'] if wanted['type'] == "asset" && data['data'][index]['relationships']['assets']['data'].first['id'] == wanted['id']
      thing = nil
      if wanted['id'] == data['data'][index]['relationships']['rosters']['data'][0]['id']
        thing = data['data'][index]['relationships']['rosters']['data'][0]['id']
        self.rosters << compose_roster(data, thing, self)
      elsif wanted['id'] == data['data'][index]['relationships']['rosters']['data'][1]['id']
        thing = data['data'][index]['relationships']['rosters']['data'][1]['id']
        self.rosters << compose_roster(data, thing, self)
      else
        next
      end
    end
  else
    data['included'].each do |wanted|
      self.telemetry_url = wanted['attributes']['URL'] if wanted['type'] == "asset" && data['data']['relationships']['assets']['data'].first['id'] == wanted['id']
      thing = nil
      if wanted['id'] == data['data']['relationships']['rosters']['data'][0]['id']
        thing = data['data']['relationships']['rosters']['data'][0]['id']
        self.rosters << compose_roster(data, thing, self)
      elsif wanted['id'] == data['data']['relationships']['rosters']['data'][1]['id']
        thing = data['data']['relationships']['rosters']['data'][1]['id']
        self.rosters << compose_roster(data, thing, self)
      else
        next
      end
    end
  end

  return self
end

Instance Attribute Details

#blue_teamObject

Returns the value of attribute blue_team.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def blue_team
  @blue_team
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/gamelocker_api/match.rb', line 4

def created_at
  @created_at
end

#durationObject

Returns the value of attribute duration.



4
5
6
# File 'lib/gamelocker_api/match.rb', line 4

def duration
  @duration
end

#end_game_reasonObject

Returns the value of attribute end_game_reason.



4
5
6
# File 'lib/gamelocker_api/match.rb', line 4

def end_game_reason
  @end_game_reason
end

#gamemodeObject

Returns the value of attribute gamemode.



4
5
6
# File 'lib/gamelocker_api/match.rb', line 4

def gamemode
  @gamemode
end

#participantsObject

Returns the value of attribute participants.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def participants
  @participants
end

#playersObject

Returns the value of attribute players.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def players
  @players
end

#red_teamObject

Returns the value of attribute red_team.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def red_team
  @red_team
end

#rostersObject

Returns the value of attribute rosters.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def rosters
  @rosters
end

#shard_idObject

Returns the value of attribute shard_id.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def shard_id
  @shard_id
end

#telemetry_urlObject

Returns the value of attribute telemetry_url.



4
5
6
# File 'lib/gamelocker_api/match.rb', line 4

def telemetry_url
  @telemetry_url
end

#uuidObject

Returns the value of attribute uuid.



3
4
5
# File 'lib/gamelocker_api/match.rb', line 3

def uuid
  @uuid
end

Instance Method Details

#compose_roster(data, roster, temp_match) ⇒ Object



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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gamelocker_api/match.rb', line 62

def compose_roster(data, roster, temp_match)
  temp_roster = Roster.new
  temp_roster.uuid = roster
  temp_roster.participants = []
  data['included'].each do |local_roster|
    next unless local_roster['type'] == "roster"
    if local_roster['id'] == roster
      temp_roster.aces_earned = local_roster['attributes']['stats']['acesEarned']
      temp_roster.gold        = local_roster['attributes']['stats']['gold']
      temp_roster.hero_kills  = local_roster['attributes']['stats']['heroKills']
      temp_roster.kraken_captures  = local_roster['attributes']['stats']['krakenCaptures']
      temp_roster.side  = local_roster['attributes']['stats']['side']
      temp_roster.turret_kills  = local_roster['attributes']['stats']['turretKills']
      temp_roster.turrets_remaining  = local_roster['attributes']['stats']['turretsRemaining']

      local_roster['relationships']['participants']['data'].each do |pat|
        data['included'].each do |local_participant|
          next unless local_participant['id'] == pat['id']
          temp_participant = Participant.new
          temp_participant.uuid = local_participant['id']
          temp_participant.assists = local_participant['attributes']['stats']['assists']
          temp_participant.crystal_mine_captures = local_participant['attributes']['stats']['crystalMineCaptures']
          temp_participant.deaths = local_participant['attributes']['stats']['deaths']
          temp_participant.farm = local_participant['attributes']['stats']['farm']
          temp_participant.first_afk_time = local_participant['attributes']['stats']['firstAfkTime']
          temp_participant.gold = local_participant['attributes']['stats']['gold']
          temp_participant.gold_mine_captures = local_participant['attributes']['stats']['goldMineCaptures']
          temp_participant.item_grants = local_participant['attributes']['stats']['itemGrants']
          temp_participant.item_sells = local_participant['attributes']['stats']['itemSells']
          temp_participant.item_uses = local_participant['attributes']['stats']['itemUses']
          temp_participant.items = local_participant['attributes']['stats']['items']
          temp_participant.jungle_kills = local_participant['attributes']['stats']['jungleKills']
          temp_participant.karma_level = local_participant['attributes']['stats']['karmaLevel']
          temp_participant.kills = local_participant['attributes']['stats']['kills']
          temp_participant.kraken_captures = local_participant['attributes']['stats']['krakenCaptures']
          temp_participant.level = local_participant['attributes']['stats']['level']
          temp_participant.minion_kills = local_participant['attributes']['stats']['minionKills']
          temp_participant.non_jungle_minion_kills = local_participant['attributes']['stats']['nonJungleMinionKills']
          temp_participant.skill_tier = local_participant['attributes']['stats']['skillTier']
          temp_participant.skin_key = local_participant['attributes']['stats']['skinKey']
          temp_participant.turret_captures = local_participant['attributes']['stats']['turretCaptures']
          temp_participant.went_afk = local_participant['attributes']['stats']['wentAfk']
          temp_participant.winner = local_participant['attributes']['stats']['winner']
          temp_participant.actor = local_participant['attributes']['actor']

          temp_player = nil
          data['included'].each do |local_player|
            next unless local_player['id'] == local_participant['relationships']['player']['data']['id']
            temp_player = Player.new(local_player)
          end
          temp_participant.player = temp_player
          temp_match.players.push(temp_player)

          temp_match.participants.push(temp_participant)
          temp_roster.participants.push(temp_participant)
        end
      end
    end
  end

  if temp_roster.side.include?("red")
    temp_match.red_team.push(temp_roster)
  elsif temp_roster.side.include?("blue")
    temp_match.blue_team.push(temp_roster)
  end
  return temp_roster
end