riot-api 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/README.md +55 -0
- data/lib/riot_api.rb +14 -0
- data/lib/riot_api/champion.rb +28 -0
- data/lib/riot_api/client.rb +37 -0
- data/lib/riot_api/game.rb +30 -0
- data/lib/riot_api/mastery_page.rb +30 -0
- data/lib/riot_api/rune.rb +12 -0
- data/lib/riot_api/rune_page.rb +31 -0
- data/lib/riot_api/summoner.rb +60 -0
- data/lib/riot_api/talent.rb +11 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd4a09b43f7f2dcee1d886fd5cb1b0b893a8111d
|
4
|
+
data.tar.gz: fb712b6fd81492d90e541b1125667403a9621273
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dea2d549bcc05bedaa8438358469587b918a4cc7b22eba093b67b6123e056a278920bb54f080c5521f703da0ef17fb2a2fdbd92b861390b950946c6b4b42bfe1
|
7
|
+
data.tar.gz: fbf7b255adc02bb28d79804354febd50d1030121a8f230812cb817b7d3ec3a8d85d565ab2c28e6cc67a733f1c0cee13dd56ae0768bdf88f3ea6a6e9b1f44411c
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Peter Souter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Riot API
|
2
|
+
|
3
|
+
A Ruby wrapper around connecting to the [Riot API](https://developer.riotgames.com)
|
4
|
+
|
5
|
+
This is an ALPHA version. Please open up issues or send a pull request for any bugs you find =)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'riot-api'
|
13
|
+
```
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
$ gem install riot_api
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage:
|
22
|
+
|
23
|
+
If you haven't already, you'll need to go to [http://developer.riotgames.com/](http://developer.riotgames.com/) and get an API key.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'riot-api'
|
27
|
+
|
28
|
+
# Before you can use the API, you have to give it your API Key
|
29
|
+
RiotAPI::API_KEY = 'API_KEY_HERE'
|
30
|
+
# Search by Summoner name
|
31
|
+
summoner = RiotAPI::Summoner.find_by_name('MrQuackers')
|
32
|
+
# => #<RiotAPI::Summoner:0x000000017a0840 @region="na", @id=20933307, @name="MrQuackers", @profile_icon_id=535, @summoner_level=30, @revision_date=1387030959000, @revision_date_str="12/14/2013 02:22 PM UTC">
|
33
|
+
|
34
|
+
summoner.name # => "MrQuackers"
|
35
|
+
summoner.summoner_level # => 30
|
36
|
+
summoner.mastery_pages # => Returns an array of mastery pages
|
37
|
+
MasteryPage.find("NA", 20933307) # => Equivalent to above
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## [Documentation]()
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
50
|
+
|
51
|
+
For more information and a complete list see [the contributor page on GitHub](https://github.com/petems/riot_api/contributors).
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
[MIT](./LICENSE.md)
|
data/lib/riot_api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
require './riot_api/champion'
|
6
|
+
require './riot_api/game'
|
7
|
+
require './riot_api/client'
|
8
|
+
require './riot_api/aggregated_stat'
|
9
|
+
require './riot_api/mastery_page'
|
10
|
+
require './riot_api/rune'
|
11
|
+
require './riot_api/talent'
|
12
|
+
require './riot_api/player_stat_summary'
|
13
|
+
require './riot_api/rune_page'
|
14
|
+
require './riot_api/summoner'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
# This class represents a champion in League of Legends.
|
3
|
+
# It contains data about the champion.
|
4
|
+
class Champion
|
5
|
+
# Creates a new Champion described by the JSON data returned from the API
|
6
|
+
def initialize(data)
|
7
|
+
data.each do |key, value|
|
8
|
+
key = key.underscore
|
9
|
+
self.class.send(:attr_accessor, key.to_sym)
|
10
|
+
instance_variable_set("@#{key}", value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns all the champions in the game
|
15
|
+
# For only the free to play champions, set `free` to true
|
16
|
+
def self.all(free=false)
|
17
|
+
champs_json = RiotAPI::Client.get('na', 'champion', { freeToPlay: free })
|
18
|
+
champs_json["champions"].map do |c|
|
19
|
+
Champion.new(c)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns all the free to play champions in the game
|
24
|
+
def self.free_to_play_champions
|
25
|
+
all(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class InvalidAPIRequest < StandardError
|
3
|
+
end
|
4
|
+
# This class is what handles the requests to the API.
|
5
|
+
class Client
|
6
|
+
#API Version. Be aware that this is only a default value. It CAN be overriden within the methods.
|
7
|
+
VERSION = 'v1.1'
|
8
|
+
|
9
|
+
# Issues a GET request the the API. Pass in the region, and resource as well as optional query params.
|
10
|
+
# It will return a Hash of the JSON data
|
11
|
+
def self.get(region, resource, options={})
|
12
|
+
region.downcase!
|
13
|
+
options.merge!({api_key: RiotAPI::API_KEY})
|
14
|
+
url = "http://prod.api.pvp.net/api/lol/#{region}/#{VERSION}/#{resource}"
|
15
|
+
response = HTTParty.get(url, query: options)
|
16
|
+
if response.code == 200
|
17
|
+
JSON.parse(response.body)
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Issues a POST request the the API. Pass in the region, and resource as well as optional query params.
|
24
|
+
# It will return a Hash of the JSON data
|
25
|
+
def self.post(region, resource, options={})
|
26
|
+
region.downcase!
|
27
|
+
options.merge!({api_key: RiotAPI::API_KEY})
|
28
|
+
url = "http://prod.api.pvp.net/api/lol/#{region}/#{version}/#{resource}"
|
29
|
+
response = HTTParty.post(url, query: options)
|
30
|
+
if response.code == 200
|
31
|
+
JSON.parse(response.body)
|
32
|
+
else
|
33
|
+
throw InvalidAPIRequest, response.message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class Game
|
3
|
+
attr_reader :statistics
|
4
|
+
def initialize(data)
|
5
|
+
data.each do |key, value|
|
6
|
+
key = key.underscore
|
7
|
+
if key == 'statistics'
|
8
|
+
self.statistics = value
|
9
|
+
else
|
10
|
+
self.class.send(:attr_accessor, key.to_sym)
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the last 10 games for the summoner
|
17
|
+
def self.recent_games(region, summoner_id)
|
18
|
+
response = RiotAPI::Client.get(region, "game/by-summoner/#{summoner_id}/recent")
|
19
|
+
response["games"].map do |data|
|
20
|
+
RiotAPI::Game.new(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def statistics=(value)
|
25
|
+
@statistics = value.map do |stat|
|
26
|
+
AggregatedStat.new(stat)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class MasteryPage
|
3
|
+
attr_reader :talents
|
4
|
+
def initialize(data)
|
5
|
+
data.each do |key, value|
|
6
|
+
key = key.underscore
|
7
|
+
if key == "talents"
|
8
|
+
self.talents = value
|
9
|
+
else
|
10
|
+
self.class.send(:attr_accessor, key.to_sym)
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(region, summoner_id)
|
17
|
+
response = RiotAPI::Client.get(region, "summoner/#{summoner_id}/masteries")
|
18
|
+
response["pages"].map do |data|
|
19
|
+
RiotAPI::MasteryPage.new(data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def talents=(value)
|
24
|
+
@talents = {}
|
25
|
+
value.each do |talent|
|
26
|
+
@talents[talent["id"]] = Talent.new(talent)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class RunePage
|
3
|
+
attr_reader :slots
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
data.each do |key, value|
|
7
|
+
key = key.underscore
|
8
|
+
if key == "slots"
|
9
|
+
self.slots = value
|
10
|
+
else
|
11
|
+
self.class.send(:attr_accessor, key.to_sym)
|
12
|
+
instance_variable_set("@#{key}", value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(region, summoner_id)
|
18
|
+
response = RiotAPI::Client.get(region, "summoner/#{summoner_id}/runes")
|
19
|
+
response["pages"].map do |data|
|
20
|
+
RiotAPI::MasteryPage.new(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def slots=(val)
|
25
|
+
@slots = {}
|
26
|
+
val.each do |slot|
|
27
|
+
@slots[slot["runeSlotId"]] = Rune.new(slot["rune"])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class Summoner
|
3
|
+
attr_accessor :region
|
4
|
+
def initialize(data, region)
|
5
|
+
@region = region
|
6
|
+
data.each do |key, value|
|
7
|
+
key = key.underscore
|
8
|
+
self.class.send(:attr_accessor, key.to_sym)
|
9
|
+
instance_variable_set("@#{key}", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Find a summoner by it's name
|
14
|
+
def self.find_by_name(region, name)
|
15
|
+
response = RiotAPI::Client.get(region, "summoner/by-name/#{name}")
|
16
|
+
if response
|
17
|
+
Summoner.new(response, region)
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Find a summoner by it's summoner ID
|
24
|
+
def self.find(region, summoner_id)
|
25
|
+
response = RiotAPI::Client.get(region, "summoner/#{summoner_id}")
|
26
|
+
if response
|
27
|
+
Summoner.new(response)
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns an array of names. summoner_ids should be an array of summoner_ids
|
34
|
+
def self.names_by_ids(region, summoner_ids)
|
35
|
+
summoner_ids = summoner_ids.join(',').first(40).compact
|
36
|
+
response = RiotAPI::Client.get(region, "summoner/#{summoner_ids}/name")
|
37
|
+
response || []
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the MasteryPage array for the Summoner instance
|
41
|
+
def mastery_pages
|
42
|
+
MasteryPage.find(self.region, self.id)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the RunePage array for the Summoner instance
|
46
|
+
def rune_pages
|
47
|
+
RunePage.find(self.region, self.id)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the Player Stats for the Summoner
|
51
|
+
def player_stats(season='SEASON3')
|
52
|
+
PlayerStatSummary.find(self.region, self.id, season)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the last 10 games for the Summoner
|
56
|
+
def recent_games
|
57
|
+
Game.recent_games(self.region, self.id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riot-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anujan Panchadcharam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: An API that allows users to interact with Riot Games' League of Legends
|
42
|
+
API
|
43
|
+
email: anujan714@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
- LICENSE.md
|
49
|
+
files:
|
50
|
+
- lib/riot_api.rb
|
51
|
+
- lib/riot_api/champion.rb
|
52
|
+
- lib/riot_api/client.rb
|
53
|
+
- lib/riot_api/game.rb
|
54
|
+
- lib/riot_api/mastery_page.rb
|
55
|
+
- lib/riot_api/rune.rb
|
56
|
+
- lib/riot_api/rune_page.rb
|
57
|
+
- lib/riot_api/summoner.rb
|
58
|
+
- lib/riot_api/talent.rb
|
59
|
+
- README.md
|
60
|
+
- LICENSE.md
|
61
|
+
homepage: https://github.com/anujan/riot-api
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.1.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Wrapper for Riot Games' API!
|
85
|
+
test_files: []
|