Class: HttpClientGenerator::Request

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

Constant Summary collapse

CONTENT_TYPES =
%i[json text].freeze
DEFAULT_HEADERS_BY_CONTENT_TYPE =
{
  json: { accept: 'application/json', content_type: 'application/json' },
  text: { content_type: 'text/plain' },
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb:, content_type:, url:, body:, rest_args:) ⇒ Request

Returns a new instance of Request.



20
21
22
23
24
25
26
27
# File 'lib/http_client_generator/request.rb', line 20

def initialize(verb:, content_type:, url:, body:, rest_args:)
  @verb = verb
  @content_type = content_type
  @url = url
  @rest_args = rest_args
  @body = body
  @headers = {}
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def content_type
  @content_type
end

#headersObject

Returns the value of attribute headers.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def headers
  @headers
end

#request_idObject

Returns the value of attribute request_id.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def request_id
  @request_id
end

#response_bodyObject

Returns the value of attribute response_body.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def response_body
  @response_body
end

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def url
  @url
end

#verbObject

Returns the value of attribute verb.



18
19
20
# File 'lib/http_client_generator/request.rb', line 18

def verb
  @verb
end

Instance Method Details

#current_headersObject



29
30
31
# File 'lib/http_client_generator/request.rb', line 29

def current_headers
  default_headers.merge(headers)
end