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.4.0"
Configuration::VALID_OPTIONS_KEYS
Class Method Summary
collapse
-
.check_key ⇒ Object
-
.create_params(locale, version, dataById) ⇒ Object
-
.get_challenger(region, type) ⇒ Object
-
.get_champions(region, free: nil) ⇒ Object
-
.get_champions_by_id(champion_id, region, free: nil) ⇒ Object
-
.get_game(summoner_id, region) ⇒ Object
-
.get_ranked(summoner_id, region, season: nil) ⇒ Object
-
.get_static_champions(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil) ⇒ Object
-
.get_static_items(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object
-
.get_static_mastery(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object
-
.get_static_realm(region) ⇒ Object
-
.get_static_runes(region, id: nil, version: nil, locale: nil, data: nil) ⇒ Object
-
.get_static_spells(region, id: nil, version: nil, locale: nil, data: nil, dataById: nil) ⇒ Object
-
.get_summary(summoner_id, region, season: nil) ⇒ Object
-
.get_summoner(summoner_id, region) ⇒ Object
-
.get_summoner_by_name(name, region) ⇒ Object
-
.get_summoner_league(summoner_id, region, entry: false) ⇒ Object
-
.get_summoner_masteries(summoner_id, region) ⇒ Object
-
.get_summoner_name(summoner_id, region) ⇒ Object
-
.get_summoner_runes(summoner_id, region) ⇒ Object
-
.get_team(team_ids, region) ⇒ Object
-
.get_team_by_summoner(summoner_id, region) ⇒ Object
-
.get_team_league(team_id, region, entry: false) ⇒ Object
-
.parse_id_array(arr) ⇒ Object
-
.query(uri, params: nil) ⇒ Object
configure, reset
Class Method Details
.check_key ⇒ Object
186
187
188
189
190
191
|
# File 'lib/lolapi.rb', line 186
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
174
175
176
177
178
179
180
|
# File 'lib/lolapi.rb', line 174
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.nil?
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.4/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
122
123
124
125
126
127
128
|
# File 'lib/lolapi.rb', line 122
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
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/lolapi.rb', line 52
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
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/lolapi.rb', line 63
def self.get_static_items(region, id: nil, version: nil, locale: nil, data: nil)
str = create_params locale, version, data
if id.nil?
str += 'itemListData=' + data + '&' unless data.nil?
query '/api/lol/static-data/' + region + '/v1.2/item', params: str
else
str += 'itemData=' + data + '&' unless data.nil?
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
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/lolapi.rb', line 75
def self.get_static_mastery(region, id: nil, version: nil, locale: nil, data: nil)
str = create_params locale, version, data
if id.nil?
str += 'masteryListData=' + data + '&' unless data.nil?
query '/api/lol/static-data/' + region + '/v1.2/mastery', params: str
else
str += 'masteryData=' + data + '&' unless data.nil?
query '/api/lol/static-data/' + region + '/v1.2/mastery/' + id.to_s, params: str
end
end
|
.get_static_realm(region) ⇒ Object
87
88
89
|
# File 'lib/lolapi.rb', line 87
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
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/lolapi.rb', line 91
def self.get_static_runes(region, id: nil, version: nil, locale: nil, data: nil)
str = create_params locale, version, data
if id.nil?
str += 'runeListData=' + data + '&' unless data.nil?
query '/api/lol/static-data/' + region + '/v1.2/rune', params: str
else
str += 'runeData=' + data + '&' unless data.nil?
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
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/lolapi.rb', line 103
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
114
115
116
117
118
119
120
|
# File 'lib/lolapi.rb', line 114
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
142
143
144
|
# File 'lib/lolapi.rb', line 142
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
130
131
132
|
# File 'lib/lolapi.rb', line 130
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
41
|
# File 'lib/lolapi.rb', line 34
def self.get_summoner_league(summoner_id, region, entry: false)
str = parse_id_array summoner_id
if entry
query '/api/lol/' + region + '/v2.4/league/by-summoner/' + str + '/entry'
else
query '/api/lol/' + region + '/v2.4/league/by-summoner/' + str
end
end
|
.get_summoner_masteries(summoner_id, region) ⇒ Object
134
135
136
|
# File 'lib/lolapi.rb', line 134
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
146
147
148
|
# File 'lib/lolapi.rb', line 146
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
138
139
140
|
# File 'lib/lolapi.rb', line 138
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
155
156
157
158
|
# File 'lib/lolapi.rb', line 155
def self.get_team(team_ids, region)
str = parse_id_array team_ids
query '/api/lol/' + region + '/v2.3/team/' + str
end
|
.get_team_by_summoner(summoner_id, region) ⇒ Object
150
151
152
153
|
# File 'lib/lolapi.rb', line 150
def self.get_team_by_summoner(summoner_id, region)
str = parse_id_array summoner_id
query '/api/lol/' + region + '/v2.3/team/by-summoner/' + str
end
|
.get_team_league(team_id, region, entry: false) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/lolapi.rb', line 43
def self.get_team_league(team_id, region, entry: false)
str = parse_id_array team_id
if entry
query '/api/lol/' + region + '/v2.4/league/by-team/' + str + '/entry'
else
query '/api/lol/' + region + '/v2.4/league/by-team/' + str
end
end
|
.parse_id_array(arr) ⇒ Object
182
183
184
|
# File 'lib/lolapi.rb', line 182
def self.parse_id_array(arr)
arr.class == Array ? arr * ',' : arr.to_s
end
|
.query(uri, params: nil) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/lolapi.rb', line 160
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
|