Class: Pact::Request::Base

Inherits:
Object
  • Object
show all
Includes:
SymbolizeKeys
Defined in:
lib/pact/shared/request.rb

Direct Known Subclasses

Consumer::Request::Actual, Expected

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Constructor Details

#initialize(method, path, headers, body, query) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
20
# File 'lib/pact/shared/request.rb', line 14

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
  @query = is_unspecified?(query) ? query : Pact::Query.create(query)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



12
13
14
# File 'lib/pact/shared/request.rb', line 12

def query
  @query
end

Instance Method Details

#content_typeObject



41
42
43
44
# File 'lib/pact/shared/request.rb', line 41

def content_type
  return nil unless specified?(:headers) && headers['Content-Type']
  Pact::Reification.from_term(headers['Content-Type'])
end

#content_type?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/pact/shared/request.rb', line 46

def content_type? content_type
  self.content_type == content_type
end

#full_pathObject



37
38
39
# File 'lib/pact/shared/request.rb', line 37

def full_path
  display_path + display_query
end

#method_and_pathObject



33
34
35
# File 'lib/pact/shared/request.rb', line 33

def method_and_path
  "#{method.upcase} #{full_path}"
end

#modifies_resource?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pact/shared/request.rb', line 50

def modifies_resource?
  http_method_modifies_resource? && body_specified?
end

#specified?(key) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/pact/shared/request.rb', line 54

def specified? key
  !is_unspecified?(self.send(key))
end

#to_hashObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/pact/shared/request.rb', line 22

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