Sha256: d00502fb61d2272c8dcae4770a3ee80c4da3466a2cc22f350036dd222ab31f8e

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

module Elastics
  module HttpClients
    class Patron < Base

      def request(method, path, data=nil)
        # patron would raise an error for :post and :put requests with no data
        # and elasticsearch ignores the data when it expects no data,
        # so we silence patron by adding some dummy data
        data = {} if (method == 'POST' || method == 'PUT') && data.nil?
        opts = options.merge(:data => data)
        session.request method.to_s.downcase.to_sym, path, {}, opts
      rescue ::Patron::TimeoutError
        session.request method.to_s.downcase.to_sym, path, {}, opts
      end

    private

      def session
        Thread.current[:elastics_patron_session] ||= begin
                                                      sess                       = ::Patron::Session.new
                                                      sess.headers['User-Agent'] = "elastics-#{Elastics::VERSION}"
                                                      sess.base_url              = base_uri
                                                      sess
                                                    end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elastics-client-1.0.10 lib/elastics/http_clients/patron.rb
elastics-client-1.0.9 lib/elastics/http_clients/patron.rb
elastics-client-1.0.8 lib/elastics/http_clients/patron.rb
elastics-client-1.0.7 lib/elastics/http_clients/patron.rb
elastics-client-1.0.6 lib/elastics/http_clients/patron.rb
elastics-client-1.0.5 lib/elastics/http_clients/patron.rb
elastics-client-1.0.4 lib/elastics/http_clients/patron.rb