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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5299caf56619ad787d30d86f076a8fd100005036
4
- data.tar.gz: 7201902288c4e3c4d8a6c22f0721f30b6edbf835
3
+ metadata.gz: 4bcac1b72dd226f3ef709a14ae8be712cd5fedcb
4
+ data.tar.gz: cd08d35b7dc9e8b5c1df996bb08d515dee4ad1f0
5
5
  SHA512:
6
- metadata.gz: 7bdcb6a21e9c493969974df3ebac981e839a89fbe864d5ed60572a74eedfe5fad0e2007c787f6f7e73126162090283b95c67c411fbc24efb5ca05fa6a64bf13e
7
- data.tar.gz: 24edf369c35e6a4732f95575d7b51a5acb740c67b8392e102d8a83fdb72933488b91b42acc40ed29561d77e2f97a303c62c64668d828c6923084c6e80b780025
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]
@@ -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, v2.1
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/", lol, "/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}"
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
@@ -1,3 +1,3 @@
1
1
  module Lol
2
- VERSION = "0.9.9"
2
+ VERSION = "0.9.10"
3
3
  end