Class: Poms::Api::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/poms/api/request.rb

Overview

The ‘Request` object is an implementation-agnostic description of an HTTP request, representing a combination of an HTTP method, URI, body and headers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, method: :get, credentials: nil, body: nil, headers: {}) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/poms/api/request.rb', line 11

def initialize(
  uri:, method: :get, credentials: nil, body: nil, headers: {}
)
  @uri = uri
  @method = method.to_sym
  @body = body || ''
  @headers = headers.to_h.freeze
  @credentials = credentials
  validate!
  freeze
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/poms/api/request.rb', line 9

def body
  @body
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



9
10
11
# File 'lib/poms/api/request.rb', line 9

def credentials
  @credentials
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/poms/api/request.rb', line 9

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/poms/api/request.rb', line 9

def method
  @method
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/poms/api/request.rb', line 9

def uri
  @uri
end

Instance Method Details

#attributesObject



27
28
29
30
31
32
33
34
35
# File 'lib/poms/api/request.rb', line 27

def attributes
  {
    method: method,
    uri: uri,
    body: body,
    headers: headers,
    credentials: credentials
  }
end

#get?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/poms/api/request.rb', line 37

def get?
  @method == :get
end

#merge(new_attributes) ⇒ Object



23
24
25
# File 'lib/poms/api/request.rb', line 23

def merge(new_attributes)
  self.class.new(attributes.merge(new_attributes))
end

#post?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/poms/api/request.rb', line 41

def post?
  @method == :post
end