Module: Spree::API::Client::Connection

Included in:
Spree::API::Client
Defined in:
lib/spree-api-client/connection.rb

Instance Method Summary collapse

Instance Method Details

#connection(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spree-api-client/connection.rb', line 5

def connection(options={})
  options = {
    :authenticate     => true,
    :force_urlencoded => false,
    :raw              => false,
    :ssl              => { :verify => false },
    :url              => api_endpoint,
    :path_prefix      => '/api'
  }.merge(options)

  connection = Faraday.new(options) do |builder|
    builder.request :json

    builder.use FaradayMiddleware::FollowRedirects
    builder.use FaradayMiddleware::Mashify
    builder.use Faraday::Response::RaiseError

    builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/

    builder.adapter  Faraday.default_adapter
  end
  connection
end