Class: GameLockerAPI::AbstractParser

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

Class Method Summary collapse

Class Method Details

.compose_roster(data, roster, temp_match) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/gamelocker_api/abstract_parser.rb', line 130

def self.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 = Player.new
          data['included'].each do |local_player|
            next unless local_player['id'] == local_participant['relationships']['player']['data']['id']
            temp_player.uuid = local_player['id']
            temp_player.level = local_player['attributes']['stats']['level']
            temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
            temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
            temp_player.played = local_player['attributes']['stats']['played']
            temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
            temp_player.win_streak = local_player['attributes']['stats']['winStreak']
            temp_player.wins = local_player['attributes']['stats']['wins']
            temp_player.xp = local_player['attributes']['stats']['xp']
            temp_player.name = local_player['attributes']['name']
            temp_player.created_at = local_player['attributes']['createdAt']
          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

.guess(end_point, data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gamelocker_api/abstract_parser.rb', line 3

def self.guess(end_point, data)
  if end_point == "matches"
    match(data)
  elsif end_point.start_with?("matches/")
    match(data, true)

  elsif end_point == "players"
    player(data)
  elsif end_point.start_with?("players/")
    player(data, true)

  else
    raise "(0_-)\nCouldn't guess what parser to use, sorry.\nEndpoint was: #{end_point}"
  end
end

.match(data, solo = false) ⇒ Object

Might only work with MATCHES… []



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
74
75
76
77
78
79
# File 'lib/gamelocker_api/abstract_parser.rb', line 20

def self.match(data, solo = false)
  _matches = []
  temp_match = nil
  unless solo
    data['data'].each do |match|
      temp_match = Match.new
      _matches.push(temp_match)
      temp_match.uuid = match['id']
      temp_match.shard_id = match['attributes']['shardId']
      temp_match.created_at = match['attributes']['createdAt']
      temp_match.duration = match['attributes']['duration']
      temp_match.gamemode = match['attributes']['gameMode']
      temp_match.end_game_reason = match['attributes']['stats']['endGameReason']
      temp_match.rosters = []
      temp_match.red_team = []
      temp_match.blue_team= []
      temp_match.players = []
      temp_match.participants = []
      data['included'].each do |wanted|
        thing = nil
        if wanted['id'] == match['relationships']['rosters']['data'][0]['id']
          thing = match['relationships']['rosters']['data'][0]['id']
          temp_match.rosters << compose_roster(data, thing, temp_match)
        elsif wanted['id'] == match['relationships']['rosters']['data'][1]['id']
          thing = match['relationships']['rosters']['data'][1]['id']
          temp_match.rosters << compose_roster(data, thing, temp_match)
        else
          next
        end
      end
    end
  else
    temp_match = Match.new
    match = data['data']
    temp_match.uuid = match['id']
    temp_match.shard_id = match['attributes']['shardId']
    temp_match.created_at = match['attributes']['createdAt']
    temp_match.duration = match['attributes']['duration']
    temp_match.gamemode = match['attributes']['gameMode']
    temp_match.end_game_reason = match['attributes']['stats']['endGameReason']
    temp_match.rosters = []
    temp_match.red_team = []
    temp_match.blue_team= []
    temp_match.players = []
    temp_match.participants = []
    data['included'].each do |wanted|
      thing = nil
      if wanted['id'] == match['relationships']['rosters']['data'][0]['id']
        thing = match['relationships']['rosters']['data'][0]['id']
        temp_match.rosters << compose_roster(data, thing, temp_match)
      elsif wanted['id'] == match['relationships']['rosters']['data'][1]['id']
        thing = match['relationships']['rosters']['data'][1]['id']
        temp_match.rosters << compose_roster(data, thing, temp_match)
      else
        next
      end
    end
  end
  solo ? temp_match : _matches
end

.participant(roster) ⇒ Object

Expects a roster uuid



126
127
# File 'lib/gamelocker_api/abstract_parser.rb', line 126

def self.participant(roster)
end

.player(data, solo = false) ⇒ Object



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
# File 'lib/gamelocker_api/abstract_parser.rb', line 81

def self.player(data, solo = false)
  temp_players = []
  temp_player  = nil
  unless solo
    data['data'].each do |local_player|
      temp_player  = Player.new

      temp_player.uuid = local_player['id']
      temp_player.level = local_player['attributes']['stats']['level']
      temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
      temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
      temp_player.played = local_player['attributes']['stats']['played']
      temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
      temp_player.win_streak = local_player['attributes']['stats']['winStreak']
      temp_player.wins = local_player['attributes']['stats']['wins']
      temp_player.xp = local_player['attributes']['stats']['xp']
      temp_player.name = local_player['attributes']['name']
      temp_player.created_at = local_player['attributes']['createdAt']

      temp_players.push(temp_player)
    end
  else
    temp_player  = Player.new

    local_player = data['data']
    temp_player.uuid = local_player['id']
    temp_player.level = local_player['attributes']['stats']['level']
    temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
    temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
    temp_player.played = local_player['attributes']['stats']['played']
    temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
    temp_player.win_streak = local_player['attributes']['stats']['winStreak']
    temp_player.wins = local_player['attributes']['stats']['wins']
    temp_player.xp = local_player['attributes']['stats']['xp']
    temp_player.name = local_player['attributes']['name']
    temp_player.created_at = local_player['attributes']['createdAt']
  end

  solo ? temp_player : temp_players
end

.roster(data) ⇒ Object



122
123
# File 'lib/gamelocker_api/abstract_parser.rb', line 122

def self.roster(data)
end