Class: HttpClientGenerator::Request
- Inherits:
-
Object
- Object
- HttpClientGenerator::Request
- 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
-
#base ⇒ Object
Returns the value of attribute base.
-
#body ⇒ Object
Returns the value of attribute body.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#rest_args ⇒ Object
Returns the value of attribute rest_args.
-
#url ⇒ Object
Returns the value of attribute url.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #current_headers ⇒ Object
-
#initialize(base:, name:, verb:, content_type:, url:, body:, rest_args:) ⇒ Request
constructor
A new instance of Request.
- #raise_error(e) ⇒ Object
- #raise_message(message) ⇒ Object
- #raw_body ⇒ Object
Constructor Details
#initialize(base:, name:, verb:, content_type:, url:, body:, rest_args:) ⇒ Request
Returns a new instance of Request.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/http_client_generator/request.rb', line 20 def initialize(base:, name:, verb:, content_type:, url:, body:, rest_args:) @base = base @name = name @verb = verb @content_type = content_type @url = url @rest_args = rest_args @body = body @headers = {} @extra = {} end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def base @base end |
#body ⇒ Object
Returns the value of attribute body.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def body @body end |
#content_type ⇒ Object
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 |
#extra ⇒ Object
Returns the value of attribute extra.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def extra @extra end |
#headers ⇒ Object
Returns the value of attribute headers.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def headers @headers end |
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def name @name end |
#response_body ⇒ Object
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 |
#rest_args ⇒ Object
Returns the value of attribute rest_args.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def rest_args @rest_args end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/http_client_generator/request.rb', line 18 def url @url end |
#verb ⇒ Object
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_headers ⇒ Object
32 33 34 |
# File 'lib/http_client_generator/request.rb', line 32 def current_headers default_headers.merge(headers) end |
#raise_error(e) ⇒ Object
44 45 46 47 |
# File 'lib/http_client_generator/request.rb', line 44 def raise_error(e) Sentry.capture_exception(e, extra: { request_id: extra[:request_id] }) if Object.const_defined?(:Sentry) raise base::RequestError, e., e.backtrace, cause: nil end |
#raise_message(message) ⇒ Object
49 50 51 52 |
# File 'lib/http_client_generator/request.rb', line 49 def () Sentry.(, extra: { request_id: extra[:request_id] }) if Object.const_defined?(:Sentry) raise base::RequestError, end |
#raw_body ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/http_client_generator/request.rb', line 36 def raw_body if json? body && body.to_json else body end end |