Sha256: d22bb31e58c83288cf5785d8f6f8a38c95945d8753c3f74f4c23d424a265a767

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'faraday'
require 'flattr/core_ext/hash'
require 'flattr/request/oauth2'
require 'flattr/response/parse_json'
require 'flattr/response/raise_client_error'
require 'flattr/response/raise_server_error'

module Flattr
  module Connection
  private
    def connection(connection_options={})
      default_options = {
        :headers => {
          :accept => 'application/json',
          :user_agent => user_agent,
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => endpoint,
      }
      Faraday.new(default_options.deep_merge(connection_options)) do |builder|
        builder.use Faraday::Request::JSON
        builder.use Faraday::Request::UrlEncoded

        builder.use Flattr::Request::FlattrOAuth2, credentials if credentials?
        builder.use Flattr::Response::RaiseClientError
        builder.use Flattr::Response::ParseJson unless connection_options[:raw]
        builder.use Flattr::Response::RaiseServerError

        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flattr-0.3.1 lib/flattr/connection.rb
flattr-0.3.0 lib/flattr/connection.rb