Sha256: 0d08729588fd58bddd2fdc009f219c9049a603e0c04a0b81b6d0a7c364f834c4

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

Contents

require 'faraday_middleware'
require 'faraday/response/raise_http_error'

module Lelylan
  module Connection
    private

    def connection(authenticate=true, raw=false, version=0, force_urlencoded=false)

      options = {
        :headers => {'Accept' => 'application/json', 'User-Agent' => user_agent, 'Content-Type' => 'application/json'},
        :proxy => proxy,
        :ssl => { :verify => false },
        :url => Lelylan.api_endpoint
      }

      if authenticated?
        self.token = token.refresh! if token.expired?
        options[:headers].merge!('Authorization' => "Bearer #{token.token}") 
      end

      connection = Faraday.new(options) do |builder|
        builder.request :json
        builder.use Faraday::Response::RaiseHttpError
        builder.use FaradayMiddleware::Mashify
        builder.use FaradayMiddleware::ParseJson
        builder.adapter(adapter)
      end

      connection
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lelylan-rb-0.0.1 lib/lelylan/connection.rb