lib/pipekit/webmock/errors.rb in pipekit-webmock-0.1.0 vs lib/pipekit/webmock/errors.rb in pipekit-webmock-0.2.0
- old
+ new
@@ -1,36 +1,28 @@
require "rack"
require "webmock"
+require "pipekit/webmock/request_signature_snippet"
+
module Pipekit
module WebMock
class UnregisteredPipedriveRequestError < StandardError
WebMockNetConnectNotAllowedError = ::WebMock::NetConnectNotAllowedError unless const_defined?(:WebMockNetConnectNotAllowedError)
def initialize(request_signature)
- return WebMockNetConnectNotAllowedError.new(request_signature) unless request_signature.uri.hostname == "api.pipedrive.com"
+ request_signature_snippet = RequestSignatureSnippet.new(request_signature)
- resource = request_signature.uri.path.split("/").last[0..-2]
- query = request_signature.uri.query
- body = request_signature.body
+ return WebMockNetConnectNotAllowedError.new(request_signature) unless request_signature_snippet.pipedrive_request?
text = [
- "Unregistered request to Pipedrive: #{request_signature.uri}",
+ "Unregistered request to Pipedrive: #{request_signature}",
"with params:",
- extract_params(resource, query),
+ request_signature_snippet.params,
"and body:",
- extract_params(resource, body),
+ request_signature_snippet.body,
"="*60
].compact.join("\n\n")
- super(text)
- end
- def extract_params(resource, 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")
+ super(text)
end
end
end
end