Sha256: 0521977ae98f5deda15dda50a18f37aa0fbf78f56940617d332aa3e91eaec99d

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 Bytes

Contents

require 'faraday_middleware'
require 'faraday/response/raise_http_1xxx'

module Instapaper
  # @private
  module Connection
    private

    def connection(raw=false)
      merged_options = connection_options.merge({
        :headers => {
          'Accept' => "application/json",
          'User-Agent' => user_agent
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => api_endpoint
      })

      Faraday.new(merged_options) do |builder|
        if authenticated?
          builder.use Faraday::Request::OAuth, authentication
        else
          builder.use Faraday::Request::OAuth, consumer_tokens
        end
        builder.use Faraday::Request::Multipart
        builder.use Faraday::Request::UrlEncoded
        builder.use Faraday::Response::Rashify unless raw
        builder.use Faraday::Response::ParseJson unless raw
        builder.use Faraday::Response::RaiseHttp1xxx
        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
instapaper-0.3.0 lib/instapaper/connection.rb
instapaper-0.2.1 lib/instapaper/connection.rb
instapaper-0.2.0 lib/instapaper/connection.rb