Sha256: 8571d3acfba87ba9cda38894fc59acff41921b1030cded2f5f20ddc995c76bbb

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Supergood
  module Vendor
    module HTTPrb
      if defined?(::HTTP)
        HTTP::Client.class_eval {
          alias original_perform perform
          def perform(original_request_payload, original_options)
            request = {
              headers: original_request_payload.headers.to_hash,
              method: original_request_payload.verb.upcase.to_s,
              body: Supergood::Utils.safe_parse_json(original_request_payload.body.source),
              url: original_request_payload.uri.to_s,
              path: original_request_payload.uri.path,
              search: original_request_payload.uri.query,
              domain: original_request_payload.uri.host
            }
            Supergood.intercept(request) do
              original_response = original_perform(original_request_payload, original_options)
              status, statusText = original_response.status.to_s.split(' ')
              {
                headers: original_response.headers.to_hash,
                status: status,
                statusText: statusText,
                body: Supergood::Utils.safe_parse_json(original_response),
                original_response: original_response
              }
            end
          end
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
supergood-0.0.4 lib/supergood/vendors/http.rb
supergood-0.0.3 lib/supergood/vendors/http.rb
supergood-0.0.2 lib/supergood/vendors/http.rb