Module: Admincredible::Connection

Included in:
Client
Defined in:
lib/admincredible/connection.rb

Instance Method Summary collapse

Instance Method Details

#build_connectionObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/admincredible/connection.rb', line 12

def build_connection
  Faraday.new(config.connection_options) do |builder|
    # Response
    builder.use Faraday::Response::RaiseError
    builder.use Admincredible::Middleware::Response::Logger, config.logger if config.logger
    builder.response :json, :content_type => 'application/json'

    # Request
    builder.use Faraday::Request::OAuth, config.oauth_options if config.oauth?
    builder.request :multipart
    builder.request :json
    builder.request :retry, 2 unless config.oauth?
    builder.request :step     unless config.oauth?

    builder.adapter config.adapter || Faraday.default_adapter
  end
end

#connectionObject



3
4
5
6
# File 'lib/admincredible/connection.rb', line 3

def connection
  @connection ||= build_connection
  return @connection
end

#rebuild_connectionObject



8
9
10
# File 'lib/admincredible/connection.rb', line 8

def rebuild_connection
  @connection = build_connection
end