lib/pupa/processor/client.rb in pupa-0.1.7 vs lib/pupa/processor/client.rb in pupa-0.1.8

- old
+ new

@@ -1,14 +1,12 @@ require 'active_support/cache' require 'faraday_middleware' require 'faraday_middleware/response_middleware' -require 'pupa/processor/middleware/gzip' require 'pupa/processor/middleware/logger' require 'pupa/processor/middleware/parse_html' require 'pupa/processor/middleware/parse_json' -require 'pupa/processor/middleware/raise_error' require 'pupa/refinements/faraday' require 'pupa/refinements/faraday_middleware' begin require 'multi_xml' @@ -37,11 +35,11 @@ # @return [Faraday::Connection] a configured Faraday HTTP client def self.new(cache_dir: nil, expires_in: 86400, value_max_bytes: 1048576, memcached_username: nil, memcached_password: nil, level: 'INFO', logdev: STDOUT) # 1 day Faraday.new do |connection| connection.request :url_encoded connection.use Middleware::Logger, Logger.new('faraday', level: level) - connection.use Middleware::RaiseError # useful for breaking concurrent requests + connection.use Faraday::Response::RaiseError # @see http://tools.ietf.org/html/rfc4627 connection.use Middleware::ParseJson, preserve_raw: true, content_type: /\bjson$/ # @see http://tools.ietf.org/html/rfc2854 @@ -54,10 +52,12 @@ if defined?(MultiXml) connection.use FaradayMiddleware::ParseXml, preserve_raw: true, content_type: /\bxml$/ end # Must come after the parser middlewares. - connection.use Middleware::Gzip + if FaradayMiddleware.const_defined?(:Gzip) + connection.use FaradayMiddleware::Gzip + end if cache_dir connection.response :caching do address = cache_dir[%r{\Amemcached://(.+)\z}, 1] if address