Class: Botch::Client::FaradayClient

Inherits:
AbstractClient show all
Defined in:
lib/botch/clients/faraday_client.rb

Instance Attribute Summary

Attributes inherited from AbstractClient

#client

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ FaradayClient

Returns a new instance of FaradayClient.



4
5
6
7
8
9
10
# File 'lib/botch/clients/faraday_client.rb', line 4

def initialize(settings = {})
  @client     = :faraday
  @handler    = Faraday.new(settings) do |builder|
    builder.use Faraday::Adapter::NetHttp
    builder.use Faraday::Request::UrlEncoded
  end
end

Instance Method Details

#get(url, options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/botch/clients/faraday_client.rb', line 12

def get(url, options = {})
  options.each_pair{ |key, value| @handler.headers[key] = value }
  response = @handler.get(url)
  parse_response(response)
end

#parse_response(response) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/botch/clients/faraday_client.rb', line 24

def parse_response(response)
  result = {}
  result[:status]   = response.status
  result[:header]   = response.headers
  result[:body]     = response.body
  result[:response] = response
  result
end

#post(url, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/botch/clients/faraday_client.rb', line 18

def post(url, options = {})
  options.each_pair{ |key, value| @handler.headers[key] = value }
  response = @handler.post(url)
  parse_response(response)
end