Class: LolApi::Connection
- Inherits:
-
Object
- Object
- LolApi::Connection
- Defined in:
- lib/lol_api/connection.rb
Instance Method Summary collapse
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #request(method, url, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 |
# File 'lib/lol_api/connection.rb', line 7 def initialize @faraday = Faraday.new do |faraday| faraday.response :json faraday.adapter Faraday.default_adapter end end |
Instance Method Details
#request(method, url, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lol_api/connection.rb', line 14 def request(method, url, = {}) option_string = .map{ |a,b| a.to_s << "=" << b.to_s }.join("&") final_url = url << "?" << option_string puts final_url response = @faraday.public_send(method) do |request| begin request.url(url, ) rescue => e puts e sleep(2) request(method, url, ) end end response.body end |