Sha256: 770c6035aa257b1c87f3a2f50a5035763f8e8967aab249f854b80c170f9e98d1

Contents?: true

Size: 871 Bytes

Versions: 8

Compression:

Stored size: 871 Bytes

Contents

module Pipekit
  module WebMock
    class RequestSignatureSnippet
      def initialize(request_signature)
        @uri = request_signature.uri
        @body = request_signature.body
      end

      def pipedrive_request?
        @uri.hostname == "api.pipedrive.com"
      end

      def params
        extract_params(@uri.query)
      end

      def body
        extract_params(@body)
      end

      private

      def resource
        @uri.path.split("/")[2][0..-2]
      end

      def extract_params(query)
        params = Rack::Utils.parse_nested_query(query)
        params.reduce({}) do |result, (field, value)|
          field = Config.field_name(resource, field)
          value = Config.field_value(resource, field, value)
          result.tap { |result| result[field] = value }
        end.map { |k, v| "#{k}: #{v}" }.join("\n")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pipekit-webmock-0.4.5 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.4.4 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.4.3 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.4.2 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.4.1 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.4.0 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.3.0 lib/pipekit/webmock/request_signature_snippet.rb
pipekit-webmock-0.2.0 lib/pipekit/webmock/request_signature_snippet.rb