class Otis::HttpClient
Public Class Methods
new(map, url)
click to toggle source
# File lib/otis/http_client.rb, line 5 def initialize(map, url) @routes = map.routes @client = create_client(url) end
Public Instance Methods
operations()
click to toggle source
# File lib/otis/http_client.rb, line 10 def operations @routes.keys end
Protected Instance Methods
call(action, url, options)
click to toggle source
# File lib/otis/http_client.rb, line 15 def call(action, url, options) response = @client.get "#{url}", options, {'Content-Type' => 'application/json'} respond(response) end
create_client(url)
click to toggle source
# File lib/otis/http_client.rb, line 25 def create_client(url) Faraday.new(:url => url) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end end
respond(response)
click to toggle source
TODO: make it more robust
# File lib/otis/http_client.rb, line 21 def respond(response) response.status == 304 ? {} : JSON.parse(response.body).merge(headers: response.headers) end