Class: Vertebrae::Connection

Inherits:
Object
  • Object
show all
Includes:
Authorization, Constants
Defined in:
lib/vertebrae/connection.rb

Constant Summary collapse

ALLOWED_OPTIONS =
[
    :headers,
    :url,
    :params,
    :request,
    :ssl
].freeze

Constants included from Constants

Vertebrae::Constants::ACCEPT, Vertebrae::Constants::ACCEPT_CHARSET, Vertebrae::Constants::CACHE_CONTROL, Vertebrae::Constants::CONTENT_LENGTH, Vertebrae::Constants::CONTENT_TYPE, Vertebrae::Constants::DATE, Vertebrae::Constants::ETAG, Vertebrae::Constants::LOCATION, Vertebrae::Constants::RATELIMIT_LIMIT, Vertebrae::Constants::RATELIMIT_REMAINING, Vertebrae::Constants::SERVER, Vertebrae::Constants::USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#authenticated?, #authentication, #basic_auth, #password?, #username?

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



26
27
28
29
30
# File 'lib/vertebrae/connection.rb', line 26

def initialize(options)
  @options = options
  @configuration = Vertebrae::Configuration.new(options)
  @stack = nil
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



15
16
17
# File 'lib/vertebrae/connection.rb', line 15

def configuration
  @configuration
end

#faraday_connectionObject

Returns the value of attribute faraday_connection.



16
17
18
# File 'lib/vertebrae/connection.rb', line 16

def faraday_connection
  @faraday_connection
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/vertebrae/connection.rb', line 14

def options
  @options
end

Instance Method Details

#connectionObject

Returns a Faraday::Connection object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vertebrae/connection.rb', line 39

def connection
  self.faraday_connection ||= Faraday.new(configuration.faraday_options) do |f|
    if configuration.authenticated?
      f.request :authorization, :basic, configuration.username, configuration.password
    end
    f.request :multipart
    f.request :url_encoded
    unless options[:raw]
      f.response :mashify
      f.response :json
    end

    f.response :raise_error
    f.adapter configuration.adapter
  end
end