Module: RSpecApi::HttpClient

Included in:
Requests::Valid
Defined in:
lib/rspec-api/http_client.rb

Instance Method Summary collapse

Instance Method Details

#send_request(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rspec-api/http_client.rb', line 7

def send_request(options = {})
  conn = Faraday.new options[:host] do |c|
    c.use FaradayMiddleware::EncodeJson
    c.adapter *(options.fetch :adapter, [:net_http])
  end
  conn.headers[:user_agent] = 'RSpec API'
  conn.headers[:accept] = 'application/json'
  conn.authorization *options[:authorize_with].flatten if options[:authorize_with]
  sleep options[:throttle] if options[:throttle]
  conn.send *options.values_at(:action, :route, :body)
rescue Faraday::Error::ConnectionFailed => e
  pending "Could not connect: #{e}"
end