Class: Relax2::Request
- Inherits:
-
Struct
- Object
- Struct
- Relax2::Request
- Defined in:
- lib/relax2/request.rb
Overview
Stores abstract request intents for building Net::HTTP::Request
Constant Summary collapse
- SUPPORTED_METHODS =
%w[GET POST PUT PATCH DELETE].freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query_parameters ⇒ Object
Returns the value of attribute query_parameters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
24 25 26 27 |
# File 'lib/relax2/request.rb', line 24 def initialize(...) super freeze end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
5 6 7 |
# File 'lib/relax2/request.rb', line 5 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
5 6 7 |
# File 'lib/relax2/request.rb', line 5 def headers @headers end |
#http_method ⇒ Object
Returns the value of attribute http_method
5 6 7 |
# File 'lib/relax2/request.rb', line 5 def http_method @http_method end |
#path ⇒ Object
Returns the value of attribute path
5 6 7 |
# File 'lib/relax2/request.rb', line 5 def path @path end |
#query_parameters ⇒ Object
Returns the value of attribute query_parameters
5 6 7 |
# File 'lib/relax2/request.rb', line 5 def query_parameters @query_parameters end |
Class Method Details
.from(args:, body: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/relax2/request.rb', line 8 def self.from(args:, body: nil) arg = FluentArg.new(args) raise InvalidArgError, 'STDIN is not acceptable when @body is specified' if arg.magic_parameters[:body] && body body = arg.magic_parameters[:body] ? IO.read(arg.magic_parameters[:body]) : body new( http_method: arg.http_method, path: arg.path, query_parameters: arg.query_parameters.map(&:to_a), headers: arg.headers.map(&:to_a), body: body, ) end |