Class: LolApi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/lol_api/connection.rb

Instance Method Summary collapse

Constructor Details

#initializeConnection

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, options = {})
  option_string = options.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, options) 
    rescue => e
      puts e
      sleep(2) 
      request(method, url, options)
    end
  end

  response.body
end