Sha256: d377f4ff06cfad50e3a4bd55fc8b77bf808d1feb8e96d7afce61dbb641046e09

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'faraday_middleware'
require 'faraday/request/multipart_with_file'
require 'faraday/request/gateway'
require 'faraday/request/evrythng_oauth'
require 'faraday/request/basic_authentication'
require 'faraday/response/raise_http_4xx'
require 'faraday/response/raise_http_5xx'

module Evrythng
  # @private
  module Connection
    private

    def connection(format=format)
      options = {
        :headers => {
          :accept => "application/#{format}",
          :user_agent => user_agent
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => api_endpoint,
      }

      Faraday.new(options) do |builder|
        builder.use Faraday::Request::MultipartWithFile
        # builder.use Faraday::Request::EvrythngOAuth, authentication if authenticated?
        builder.use Faraday::Request::BasicAuthentication, username, password
        builder.use Faraday::Request::Multipart
        builder.use Faraday::Request::UrlEncoded
        builder.use Faraday::Request::Gateway, gateway if gateway
        builder.use Faraday::Response::RaiseHttp4xx
        builder.use Faraday::Response::Mashify
        builder.use Faraday::Response::ParseJson
        builder.use Faraday::Response::RaiseHttp5xx
        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrythng-0.0.5 lib/evrythng/connection.rb