require 'faraday' require 'evrythng/core_ext/hash' require 'evrythng/request/gateway' require 'evrythng/request/token_authentication' require 'evrythng/response/parse_json' require 'evrythng/response/raise_client_error' require 'evrythng/response/raise_server_error' module Evrythng module Connection private # Returns a Faraday::Connection object # # @param options [Hash] A hash of options # @return [Faraday::Connection] def connection(options={}) default_options = { :headers => { :accept => 'application/vnd.evrythng-v2+json', :user_agent => user_agent, }, :proxy => proxy, :ssl => {:verify => false}, :url => options.fetch(:endpoint, endpoint), } Faraday.new(default_options.deep_merge(connection_options)) do |builder| builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded builder.use Evrythng::Request::Gateway, gateway if gateway builder.use Evrythng::Request::TokenAuthentication, token builder.use Evrythng::Response::RaiseClientError builder.use Evrythng::Response::ParseJson unless options[:raw] builder.use Evrythng::Response::RaiseServerError builder.adapter(adapter) end end end end