Module: FaradayStack

Extended by:
Faraday::AutoloadHelper, Forwardable
Defined in:
lib/faraday_stack.rb,
lib/faraday_stack/caching.rb,
lib/faraday_stack/response_xml.rb,
lib/faraday_stack/response_html.rb,
lib/faraday_stack/response_json.rb,
lib/faraday_stack/instrumentation.rb,
lib/faraday_stack/rack_compatible.rb,
lib/faraday_stack/follow_redirects.rb,
lib/faraday_stack/response_middleware.rb

Defined Under Namespace

Classes: Caching, FollowRedirects, Instrumentation, RackCompatible, RedirectLimitReached, ResponseHTML, ResponseJSON, ResponseMiddleware, ResponseXML

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_connectionObject

THE ÜBER STACK



20
21
22
# File 'lib/faraday_stack.rb', line 20

def self.default_connection
  @default_connection ||= self.build
end

Class Method Details

.build(url = nil, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/faraday_stack.rb', line 30

def self.build(url = nil, options = {})
  klass = nil
  if    url.is_a?(Hash)   then options = url.dup
  elsif url.is_a?(Class)  then klass = url
  else  options = options.merge(:url => url)
  end

  klass ||= options.delete(:class) || Faraday::Connection

  klass.new(options) do |builder|
    builder.request :url_encoded
    builder.request :json
    yield builder if block_given?
    builder.use ResponseXML,  :content_type => /[+\/]xml$/
    builder.use ResponseHTML, :content_type => 'text/html'
    builder.use ResponseJSON, :content_type => /[+\/]json$/
    builder.use ResponseJSON::MimeTypeFix, :content_type => /text\/(plain|javascript)/
    builder.use FollowRedirects
    builder.response :raise_error
    builder.adapter Faraday.default_adapter
  end
end