Class: GameLockerAPI::AbstractParser

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

Class Method Summary collapse

Class Method Details

.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