Class: CobotClient::Request

Inherits:
Object
  • Object
show all
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

UrlHelper::DEFAULT_SITE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UrlHelper

#cobot_uri, #cobot_url, site, site=

Constructor Details

#initialize(verb) ⇒ Request

Returns a new instance of Request.

Raises:

  • (ArgumentError)


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

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/cobot_client/request.rb', line 10

def body
  @body
end

#headersObject

Returns the value of attribute headers.



10
11
12
# File 'lib/cobot_client/request.rb', line 10

def headers
  @headers
end

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/cobot_client/request.rb', line 10

def uri
  @uri
end

#verbObject (readonly)

Returns the value of attribute verb.



10
11
12
# File 'lib/cobot_client/request.rb', line 10

def verb
  @verb
end

Instance Method Details

#submitObject



33
34
35
36
37
# File 'lib/cobot_client/request.rb', line 33

def submit
  Response.new(
    http.request(net_http_request)
  )
end