Sha256: 0abe30e18d51dc47d7d814a7b700ef0ee1eee3303874211e5799bfce21338d60

Contents?: true

Size: 962 Bytes

Versions: 3

Compression:

Stored size: 962 Bytes

Contents

require 'faraday'
require 'faraday_middleware'

module ReadabilityParser
  module Connection
    # Instantiate a Faraday::Connection
    # @private
    private

    # Returns a Faraday::Connection object
    #
    # @return [Faraday::Connection]
    def connection(options={})

      options = {
        :url => ReadabilityParser.api_endpoint
        }.merge(options)

      connection = Faraday.new(options) do |c|
        c.use Faraday::Request::UrlEncoded                  # encode request params as "www-form-urlencoded"
        c.use FaradayMiddleware::FollowRedirects, limit: 3
        c.use Faraday::Response::RaiseError                 # raise exceptions on 40x, 50x responses

        c.response :xml, :content_type => /\bxml$/
        c.response :json, :content_type => /\bjson$/

        c.adapter Faraday.default_adapter
      end

      connection.headers[:user_agent] = ReadabilityParser.user_agent

      connection
    end
  end # Connection
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
readability_parser-0.0.3 lib/readability_parser/connection.rb
readability_parser-0.0.2 lib/readability_parser/connection.rb
readability_parser-0.0.1 lib/readability_parser/connection.rb