class Pact::Request::Base
Attributes
body[R]
headers[R]
method[R]
options[R]
path[R]
query[R]
Public Class Methods
new(method, path, headers, body, query)
click to toggle source
# File lib/pact/shared/request.rb, line 12 def initialize(method, path, headers, body, query) @method = method.to_s @path = path @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant @body = body set_query(query) end
Protected Class Methods
key_not_found()
click to toggle source
# File lib/pact/shared/request.rb, line 63 def self.key_not_found raise NotImplementedError end
Public Instance Methods
content_type()
click to toggle source
# File lib/pact/shared/request.rb, line 39 def content_type return nil unless specified?(:headers) && headers['Content-Type'] Pact::Reification.from_term(headers['Content-Type']) end
content_type?(content_type)
click to toggle source
# File lib/pact/shared/request.rb, line 44 def content_type? content_type self.content_type == content_type end
full_path()
click to toggle source
# File lib/pact/shared/request.rb, line 35 def full_path display_path + display_query end
method_and_path()
click to toggle source
# File lib/pact/shared/request.rb, line 31 def method_and_path "#{method.upcase} #{full_path}" end
modifies_resource?()
click to toggle source
# File lib/pact/shared/request.rb, line 48 def modifies_resource? http_method_modifies_resource? && body_specified? end
specified?(key)
click to toggle source
# File lib/pact/shared/request.rb, line 52 def specified? key !is_unspecified?(self.send(key)) end
to_hash()
click to toggle source
# File lib/pact/shared/request.rb, line 20 def to_hash hash = { method: method, path: path, } hash[:query] = query if specified?(:query) hash[:headers] = headers if specified?(:headers) hash[:body] = body if specified?(:body) hash end
Protected Instance Methods
body_specified?()
click to toggle source
# File lib/pact/shared/request.rb, line 67 def body_specified? specified?(:body) end
display_path()
click to toggle source
# File lib/pact/shared/request.rb, line 84 def display_path reified_path = Pact::Reification.from_term(path) reified_path.empty? ? "/" : reified_path end
display_query()
click to toggle source
# File lib/pact/shared/request.rb, line 89 def display_query (query.nil? || query.empty?) ? '' : "?#{Pact::Reification.from_term(query)}" end
http_method_modifies_resource?()
click to toggle source
Not including DELETE, as we don't care about the resources updated state.
# File lib/pact/shared/request.rb, line 59 def http_method_modifies_resource? ['PUT','POST','PATCH'].include?(method.to_s.upcase) end
is_unspecified?(value)
click to toggle source
# File lib/pact/shared/request.rb, line 71 def is_unspecified? value value.is_a? self.class.key_not_found.class end
set_query(query)
click to toggle source
# File lib/pact/shared/request.rb, line 93 def set_query(query) @query = if is_unspecified?(query) query else if Pact::Query.is_a_query_object?(query) query else Pact::Query.create(query) end end end
to_hash_without_body_or_query()
click to toggle source
# File lib/pact/shared/request.rb, line 75 def to_hash_without_body_or_query hash = { method: method.upcase, path: path } hash[:headers] = headers if specified?(:headers) hash end