Class: Clientele::Configuration

Inherits:
BlockParty::Configuration
  • Object
show all
Defined in:
lib/clientele/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/clientele/configuration.rb', line 11

def initialize
  self.logger                = Logger.new($stdout)
  self.adapter               = Faraday.default_adapter
  self.headers               = {}
  self.hashify_content_type  = /\bjson$/
  self.follow_redirects      = true
  self.redirect_limit        = 5
  self.ensure_trailing_slash = true

  self.connection            = default_connection
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def adapter
  @adapter
end

#connectionObject

Returns the value of attribute connection.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def connection
  @connection
end

#ensure_trailing_slashObject

Returns the value of attribute ensure_trailing_slash.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def ensure_trailing_slash
  @ensure_trailing_slash
end

#follow_redirectsObject

Returns the value of attribute follow_redirects.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def follow_redirects
  @follow_redirects
end

#hashify_content_typeObject

Returns the value of attribute hashify_content_type.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def hashify_content_type
  @hashify_content_type
end

#headersObject

Returns the value of attribute headers.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def headers
  @headers
end

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def logger
  @logger
end

#redirect_limitObject

Returns the value of attribute redirect_limit.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def redirect_limit
  @redirect_limit
end

#root_urlObject

Returns the value of attribute root_url.



9
10
11
# File 'lib/clientele/configuration.rb', line 9

def root_url
  @root_url
end

Instance Method Details

#default_connectionObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/clientele/configuration.rb', line 23

def default_connection
  Proc.new do |conn, options|

    conn.use FaradayMiddleware::FollowRedirects, limit: options[:redirect_limit] if options[:follow_redirects]

    conn.request  :url_encoded

    conn.response :rashify
    conn.response :logger, options[:logger], bodies: true
    conn.response :json, content_type: options[:hashify_content_type], preserve_raw: true

    conn.options.params_encoder = options[:params_encoder] if options[:params_encoder]

    yield(conn, options) if block_given?

    conn.adapter options[:adapter] if options[:adapter]

  end
end