Class: Vertebrae::Connection
- Inherits:
-
Object
- Object
- Vertebrae::Connection
- Includes:
- Authorization, Constants
- Defined in:
- lib/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
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#connection ⇒ Object
Returns a Fraday::Connection object.
-
#default_middleware ⇒ Object
Default middleware stack that uses default adapter as specified at configuration stage.
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
-
#stack(&block) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
Methods included from Authorization
#authenticated?, #authentication, #basic_auth, #password?, #username?
Constructor Details
#initialize(options) ⇒ Connection
23 24 25 26 27 28 |
# File 'lib/connection.rb', line 23 def initialize() = @configuration = Vertebrae::Configuration.new() @connection = nil @stack = nil end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/connection.rb', line 13 def configuration @configuration end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/connection.rb', line 12 def end |
Instance Method Details
#connection ⇒ Object
Returns a Fraday::Connection object
64 65 66 67 68 69 70 |
# File 'lib/connection.rb', line 64 def connection if @connection @connection else @connection ||= Faraday.new(configuration..merge(:builder => stack)) end end |
#default_middleware ⇒ Object
Default middleware stack that uses default adapter as specified at configuration stage.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/connection.rb', line 33 def default_middleware Proc.new do |builder| builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded builder.use Vertebrae::Request::BasicAuth, configuration.authentication if configuration.authenticated? builder.use Faraday::Response::Logger if ENV['DEBUG'] unless [:raw] builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson end builder.use Vertebrae::Response::RaiseError builder.adapter configuration.adapter end end |
#stack(&block) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
52 53 54 55 56 57 58 59 60 |
# File 'lib/connection.rb', line 52 def stack(&block) @stack ||= begin if block_given? Faraday::Builder.new(&block) else Faraday::Builder.new(&default_middleware) end end end |