ruby-lol 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -0
- data/lib/lol/client.rb +5 -0
- data/lib/lol/league_request.rb +1 -1
- data/lib/lol/request.rb +1 -2
- data/lib/lol/static_request.rb +66 -0
- data/lib/lol/version.rb +1 -1
- data/spec/fixtures/v1/get-champion-by-id.json +952 -0
- data/spec/fixtures/v1/get-champion.json +708 -0
- data/spec/fixtures/v1/get-item-by-id.json +5 -0
- data/spec/fixtures/v1/get-item.json +982 -0
- data/spec/fixtures/v1/get-mastery-by-id.json +9 -0
- data/spec/fixtures/v1/get-mastery.json +1359 -0
- data/spec/fixtures/v1/get-realm.json +18 -0
- data/spec/fixtures/v1/get-rune-by-id.json +22 -0
- data/spec/fixtures/v1/get-rune.json +6465 -0
- data/spec/fixtures/v1/get-summoner-spell-by-id.json +64 -0
- data/spec/fixtures/v1/get-summoner-spell.json +657 -0
- data/spec/fixtures/v1.1/get-champion.json +1512 -1
- data/spec/fixtures/v1.2/get-ranked_stats.json +1448 -1
- data/spec/fixtures/v1.2/get-stats.json +115 -1
- data/spec/fixtures/v1.3/get-game.json +1040 -1
- data/spec/fixtures/v1.3/get-summoner-by-name.json +16 -1
- data/spec/fixtures/v1.3/get-summoner-masteries.json +2316 -1
- data/spec/fixtures/v1.3/get-summoner-name.json +4 -1
- data/spec/fixtures/v1.3/get-summoner-runes.json +6374 -1
- data/spec/fixtures/v1.3/get-summoner.json +16 -1
- data/spec/lol/client_spec.rb +12 -0
- data/spec/lol/request_spec.rb +0 -9
- data/spec/lol/static_request_spec.rb +93 -0
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bcac1b72dd226f3ef709a14ae8be712cd5fedcb
|
4
|
+
data.tar.gz: cd08d35b7dc9e8b5c1df996bb08d515dee4ad1f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636209f1b3f0e8aa9f9e14321296245b56ba7cec490b42ab729a23bb3a608d63c0da62784e28fbf6e2e051be0e1f213f95b9ac69a9e4db63f62a049ede78d978
|
7
|
+
data.tar.gz: 40cb048f2ab8c666badc91cd6a8c9d2f0a83c7d888d75cf4de99f16b9f920c3644758b0d34bab180049df93ffa70807f767fccc6107994b11efd84f638c529a9
|
data/README.md
CHANGED
@@ -77,6 +77,39 @@ client.team.get(summoner_id)
|
|
77
77
|
# => Array
|
78
78
|
```
|
79
79
|
|
80
|
+
# Making Static Requests
|
81
|
+
The Riot API has a [section](http://developer.riotgames.com/api/methods#!/378) carved out for static-data. These requests don't count against your rate limit. The mechanism for using them is similar to the standard requests above.
|
82
|
+
|
83
|
+
Each static endpoint has two possible requests: `get` and `get(id)`. `get` returns an array of OpenStructs representing the data from Riot's API, and `get(id)` returns an OpenStruct with a single record. Here are some examples:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
client.static
|
87
|
+
# => Lol::StaticRequest
|
88
|
+
**NOTE**: StaticRequest is not meant to be used directly, but can be!
|
89
|
+
|
90
|
+
client.static.champion
|
91
|
+
# => Lol::StaticRequest (for endpoint /static-data/champion)
|
92
|
+
|
93
|
+
client.static.champion.get
|
94
|
+
# => [OpenStruct] (with keys from http://developer.riotgames.com/api/methods#!/378/1349)
|
95
|
+
|
96
|
+
client.static.champion.get(id)
|
97
|
+
# => OpenStruct (with keys from http://developer.riotgames.com/api/methods#!/378/1349)
|
98
|
+
```
|
99
|
+
|
100
|
+
You can also pass query parameters as listed in the Riot API documentation. For example:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
|
104
|
+
# returns all attributes
|
105
|
+
client.static.champion.get(champData: 'all')
|
106
|
+
|
107
|
+
# returns only lore information
|
108
|
+
client.static.champion.get(champData: 'lore')
|
109
|
+
```
|
110
|
+
|
111
|
+
**NOTE**: The realm endpoint is not implemented. Let us know if you need it, but it seemed somewhat unnecessary.
|
112
|
+
|
80
113
|
## Contributing
|
81
114
|
|
82
115
|
1. Fork it
|
data/lib/lol/client.rb
CHANGED
@@ -39,6 +39,11 @@ module Lol
|
|
39
39
|
@summoner_request ||= SummonerRequest.new(api_key, region)
|
40
40
|
end
|
41
41
|
|
42
|
+
# @return [StaticRequest]
|
43
|
+
def static
|
44
|
+
@static_request ||= StaticRequest.new(api_key, region)
|
45
|
+
end
|
46
|
+
|
42
47
|
# Initializes a Lol::Client
|
43
48
|
# @param api_key [String]
|
44
49
|
# @param options [Hash]
|
data/lib/lol/league_request.rb
CHANGED
@@ -6,7 +6,7 @@ module Lol
|
|
6
6
|
"v2.3"
|
7
7
|
end
|
8
8
|
|
9
|
-
# Retrieves leagues data for summoner, including leagues for all of summoner's teams
|
9
|
+
# Retrieves leagues data for summoner, including leagues for all of summoner's teams
|
10
10
|
# @param [String]
|
11
11
|
# @return [Array]
|
12
12
|
def get summoner_id
|
data/lib/lol/request.rb
CHANGED
@@ -27,9 +27,8 @@ module Lol
|
|
27
27
|
# @param path [String] API path to call
|
28
28
|
# @return [String] full fledged url
|
29
29
|
def api_url path, params = {}
|
30
|
-
lol = self.class.api_version == "v2.1" ? "" : "lol"
|
31
30
|
query_string = URI.encode_www_form params.merge api_key: api_key
|
32
|
-
File.join "http://prod.api.pvp.net/api/
|
31
|
+
File.join "http://prod.api.pvp.net/api/lol/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}"
|
33
32
|
end
|
34
33
|
|
35
34
|
# Calls the API via HTTParty and handles errors
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Lol
|
2
|
+
class StaticRequest < Request
|
3
|
+
STANDARD_ENDPOINTS = %w(champion item mastery rune summoner_spell)
|
4
|
+
|
5
|
+
def self.api_version
|
6
|
+
"v1"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns a full url for an API call
|
10
|
+
# Overrides api_url from Request
|
11
|
+
# @param path [String] API path to call
|
12
|
+
# @return [String] full fledged url
|
13
|
+
def api_url path, params = {}
|
14
|
+
query_string = URI.encode_www_form params.merge api_key: api_key
|
15
|
+
File.join "http://prod.api.pvp.net/api/lol/static-data/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}"
|
16
|
+
end
|
17
|
+
|
18
|
+
STANDARD_ENDPOINTS.each do |endpoint|
|
19
|
+
define_method(endpoint) { Proxy.new self, endpoint }
|
20
|
+
end
|
21
|
+
def realm
|
22
|
+
Proxy.new self, 'realm'
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(endpoint, id=nil, params={})
|
26
|
+
id ? find(endpoint, id, params) : all(endpoint, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def find(endpoint, id, params={})
|
32
|
+
model_class(endpoint).new \
|
33
|
+
perform_request(api_url("#{endpoint.dasherize}/#{id}", params)).to_hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def all(endpoint, params={})
|
37
|
+
if endpoint == "realm"
|
38
|
+
model_class(endpoint).new perform_request(api_url(endpoint.dasherize, params)).to_hash
|
39
|
+
else
|
40
|
+
perform_request(api_url(endpoint.dasherize, params))["data"].map do |id, values|
|
41
|
+
model_class(endpoint).new(values.merge(id: id))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def model_class(endpoint)
|
47
|
+
OpenStruct
|
48
|
+
end
|
49
|
+
|
50
|
+
class Proxy
|
51
|
+
def initialize(request, endpoint)
|
52
|
+
@request = request
|
53
|
+
@endpoint = endpoint
|
54
|
+
end
|
55
|
+
|
56
|
+
def get(id=nil, params={})
|
57
|
+
if id.is_a?(Hash)
|
58
|
+
params = id
|
59
|
+
id = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
@request.get @endpoint, id, params
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/lol/version.rb
CHANGED