Module: LoLAPI

Extended by:
Configuration
Defined in:
lib/lolapi.rb,
lib/LoLAPI/version.rb

Constant Summary collapse

BASE_URL =
'http://prod.api.pvp.net'
VERSION =
"0.3.0"

Constants included from Configuration

Configuration::VALID_OPTIONS_KEYS

Class Method Summary collapse

Methods included from Configuration

configure, reset

Class Method Details

.check_keyObject



179
180
181
182
183
184
# File 'lib/lolapi.rb', line 179

def self.check_key
  if self.api_key.nil?
    puts "ERROR: Please initialize lolapi with an API Key."
    return 1
  end
end

.create_params(locale, version, dataById) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/lolapi.rb', line 171

def self.create_params(locale, version, dataById)
  str = String.new
  str += 'locale=' + locale + '&' unless locale.nil?
  str += 'version=' + version + '&' unless version.nil?
  str += 'dataById=' + dataById + '&' unless dataById == 'false'
  return str
end

.get_challenger(region, type) ⇒ Object



30
31
32
# File 'lib/lolapi.rb', line 30

def self.get_challenger(region, type)
  query '/api/lol/' + region + '/v2.3/league/challenger', params: 'type=' + type.to_s
end

.get_champions(region, free: nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/lolapi.rb', line 10

def self.get_champions(region, free: nil)
  if free.nil?
    query '/api/lol/' + region + '/v1.2/champion'
  else
    query '/api/lol/' + region + '/v1.2/champion', params: 'freeToPlay=' + free.to_s
  end
end

.get_champions_by_id(champion_id, region, free: nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/lolapi.rb', line 18

def self.get_champions_by_id(champion_id, region, free: nil)
  if free.nil?
    query '/api/lol/' + region + '/v1.2/champion/' + champion_id.to_s
  else
    query '/api/lol/' + region + '/v1.2/champion/' + champion_id.to_s, params: 'freeToPlay=' + free.to_s
  end
end

.get_game(summoner_id, region) ⇒ Object



26
27
28
# File 'lib/lolapi.rb', line 26

def self.get_game(summoner_id, region)
  query '/api/lol/' + region + '/v1.3/game/by-summoner/' + summoner_id.to_s + '/recent'
end

.get_ranked(summoner_id, region, season: nil) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/lolapi.rb', line 117

def self.get_ranked(summoner_id, region, season: nil)
  if season.nil?
    query '/api/lol/' + region + '/v1.3/stats/by-summoner/' + summoner_id.to_s + '/ranked'
  else
    query '/api/lol/' + region + '/v1.3/stats/by-summoner/' + summoner_id.to_s + '/ranked', params: 'season=' + season
  end
end

.get_static_champions(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/lolapi.rb', line 50

def self.get_static_champions(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil)
  str = create_params locale, version, dataById
  str += 'champData=' + data + '&' unless data.nil?

  if id.nil?
    query '/api/lol/static-data/' + region + '/v1.2/champion', params: str
  else
    query '/api/lol/static-data/' + region + '/v1.2/champion/' + id.to_s, params: str
  end
end

.get_static_items(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/lolapi.rb', line 61

def self.get_static_items(region, id: nil, version: nil, locale: nil, data: nil)
  str = create_params locale, version, 'false'
  str += 'itemData=' + data + '&' unless data.nil?

  if id.nil?
    query '/api/lol/static-data/' + region + '/v1.2/item', params: str
  else
    query '/api/lol/static-data/' + region + '/v1.2/item/' + id.to_s, params: str
  end
end

.get_static_mastery(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/lolapi.rb', line 72

def self.get_static_mastery(region, id: nil, version: nil, locale: nil, data: nil)
  str = create_params locale, version, 'false'
  str += 'masteryData=' + data + '&' unless data.nil?

  if id.nil?
    query '/api/lol/static-data/' + region + '/v1.2/mastery', params: str
  else
    query '/api/lol/static-data/' + region + '/v1.2/mastery/' + id.to_s, params: str
  end
end

.get_static_realm(region) ⇒ Object



83
84
85
# File 'lib/lolapi.rb', line 83

def self.get_static_realm(region)
  query '/api/lol/static-data/' + region + '/v1.2/realm'
end

.get_static_runes(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/lolapi.rb', line 87

def self.get_static_runes(region, id: nil, version: nil, locale: nil, data: nil)
  str = create_params locale, version, 'false'
  str += 'runeData=' + data + '&' unless data.nil?

  if id.nil?
    query '/api/lol/static-data/' + region + '/v1.2/rune', params: str
  else
    query '/api/lol/static-data/' + region + '/v1.2/rune/' + id.to_s, params: str
  end
end

.get_static_spells(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/lolapi.rb', line 98

def self.get_static_spells(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil)
  str = create_params locale, version, dataById
  str += 'spellData=' + data + '&' unless data.nil?

  if id.nil?
    query '/api/lol/static-data/' + region + '/v1.2/summoner-spell', params: str
  else
    query '/api/lol/static-data/' + region + '/v1.2/summoner-spell/' + id.to_s, params: str
  end
end

.get_summary(summoner_id, region, season: nil) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/lolapi.rb', line 109

def self.get_summary(summoner_id, region, season: nil)
  if season.nil?
    query '/api/lol/' + region + '/v1.3/stats/by-summoner/' + summoner_id.to_s + '/summary'
  else
    query '/api/lol/' + region + '/v1.3/stats/by-summoner/' + summoner_id.to_s + '/summary', params: 'season=' + season
  end
end

.get_summoner(summoner_id, region) ⇒ Object



137
138
139
# File 'lib/lolapi.rb', line 137

def self.get_summoner(summoner_id, region)
  query '/api/lol/' + region + '/v1.4/summoner/' + summoner_id.to_s
end

.get_summoner_by_name(name, region) ⇒ Object



125
126
127
# File 'lib/lolapi.rb', line 125

def self.get_summoner_by_name(name, region)
  query '/api/lol/' + region + '/v1.4/summoner/by-name/' + name.delete(' ')
end

.get_summoner_league(summoner_id, region, entry: false) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/lolapi.rb', line 34

def self.get_summoner_league(summoner_id, region, entry: false)
  if entry
    query '/api/lol/' + region + '/v2.3/league/by-summoner/' + summoner_id.to_s + '/entry'
  else
    query '/api/lol/' + region + '/v2.3/league/by-summoner/' + summoner_id.to_s
  end
end

.get_summoner_masteries(summoner_id, region) ⇒ Object



129
130
131
# File 'lib/lolapi.rb', line 129

def self.get_summoner_masteries(summoner_id, region)
  query '/api/lol/' + region + '/v1.4/summoner/' + summoner_id.to_s + '/masteries'
end

.get_summoner_name(summoner_id, region) ⇒ Object



141
142
143
# File 'lib/lolapi.rb', line 141

def self.get_summoner_name(summoner_id, region)
  query '/api/lol/' + region + '/v1.4/summoner/' + summoner_id.to_s + '/name'
end

.get_summoner_runes(summoner_id, region) ⇒ Object



133
134
135
# File 'lib/lolapi.rb', line 133

def self.get_summoner_runes(summoner_id, region)
  query '/api/lol/' + region + '/v1.4/summoner/' + summoner_id.to_s + '/runes'
end

.get_team(team_ids, region) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/lolapi.rb', line 149

def self.get_team(team_ids, region)
  if team_ids.class == Array
    query '/api/lol/' + region + '/v2.2/team/' + team_ids * ","
  else
    query '/api/lol/' + region + '/v2.2/team/' + team_ids.to_s
  end
end

.get_team_by_summoner(summoner_id, region) ⇒ Object



145
146
147
# File 'lib/lolapi.rb', line 145

def self.get_team_by_summoner(summoner_id, region)
  query '/api/lol/' + region + '/v2.2/team/by-summoner/' + summoner_id.to_s
end

.get_team_league(team_id, region, entry: false) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/lolapi.rb', line 42

def self.get_team_league(team_id, region, entry: false)
  if entry
    query '/api/lol/' + region + '/v2.3/league/by-team/' + team_id.to_s + '/entry'
  else
    query '/api/lol/' + region + '/v2.3/league/by-team/' + team_id.to_s
  end
end

.query(uri, params: nil) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/lolapi.rb', line 157

def self.query(uri, params: nil)
  if check_key == 1
    return nil
  end

  if params.nil?
    response = Net::HTTP.get(URI(BASE_URL + uri + '?api_key=' + self.api_key))
  else
    response = Net::HTTP.get(URI(BASE_URL + uri + '?' + params + '&api_key=' + self.api_key))
  end

  JSON.parse(response)
end