Sha256: 4ad9c99d910f86c2217d0e639c5f1c0ae10a988eb23924cf1a931db36a9d52f1

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module Patron

  class Session

    def request_with_logging(action_name, url, headers, options={})
      create_request_event(action_name, headers, options, url)
      response = nil
      time_taken_in_seconds = ::Benchmark.realtime do
        response = request_without_logging(action_name, url, headers, options)
      end
      create_response_event(response, time_taken_in_seconds)
      response
    end

    alias_method_chain :request, :logging

    private

    def create_response_event(response, time_taken_in_seconds)
      HttpEventLogger::Event::Response.new(
        request:               @request_event,
        time_taken_in_seconds: time_taken_in_seconds,
        status:                response.status,
        headers:               response.headers,
        body:                  response.body
      )
    end

    def create_request_event(action_name, headers, options, url)
      @request_event = HttpEventLogger::Event::Request.new(
        method:  action_name,
        uri:     url,
        headers: headers,
        body:    options[:data]
      )
    end

  end

end if defined?(Patron)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
http_event_logger-0.1.0 ./lib/http_event_logger/adapter/patron.rb
http_event_logger-0.1.0.rc4 ./lib/http_event_logger/adapter/patron.rb
http_event_logger-0.1.0.rc3 ./lib/http_event_logger/adapter/patron.rb
http_event_logger-0.1.0.rc2 ./lib/http_event_logger/adapter/patron.rb
http_event_logger-0.1.0.rc1 ./lib/http_event_logger/adapter/patron.rb