Sha256: b7b85fb6882f83062bee17e48eb93be7d193bf6b9dc6e66b47c78c4505f0bbcb

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 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|
        # encode request params as "www-form-urlencoded"
        c.use Faraday::Request::UrlEncoded

        c.use FaradayMiddleware::FollowRedirects, limit: 3

        # raise exceptions on 40x, 50x responses
        c.use Faraday::Response::RaiseError

        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

2 entries across 2 versions & 1 rubygems

Version Path
readability_parser-0.0.5 lib/readability_parser/connection.rb
readability_parser-0.0.4 lib/readability_parser/connection.rb