Class: CobotClient::Request
- Inherits:
-
Object
- Object
- CobotClient::Request
- Includes:
- UrlHelper
- Defined in:
- lib/cobot_client/request.rb
Constant Summary collapse
- CONTENT_TYPE_HEADER =
{'Content-Type' => 'application/json'}.freeze
- VERBS =
%i[get post put patch delete].freeze
Constants included from UrlHelper
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(verb) ⇒ Request
constructor
A new instance of Request.
- #submit ⇒ Object
Methods included from UrlHelper
#cobot_uri, #cobot_url, site, site=
Constructor Details
#initialize(verb) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cobot_client/request.rb', line 12 def initialize(verb, *) raise ArgumentError, "Unsupported verb: #{verb.inspect}" unless VERBS.include?(verb) @verb = verb @headers = CONTENT_TYPE_HEADER url, subdomain, path, params = parse_args(*) @uri, @body = case @verb when :get, :delete [build_uri(url || subdomain, path, **params), nil] else [build_uri(url || subdomain, path), params.to_json] end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/cobot_client/request.rb', line 10 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
10 11 12 |
# File 'lib/cobot_client/request.rb', line 10 def headers @headers end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/cobot_client/request.rb', line 10 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
10 11 12 |
# File 'lib/cobot_client/request.rb', line 10 def verb @verb end |