Class: DevSuite::RequestBuilder::Builder::Http

Inherits:
Base
  • Object
show all
Defined in:
lib/dev_suite/request_builder/builder/http.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#headers, #tool, #url

Instance Method Summary collapse

Constructor Details

#initialize(url:, http_method: "GET", headers: {}, body: nil, tool:) ⇒ Http

Returns a new instance of Http.



9
10
11
12
13
# File 'lib/dev_suite/request_builder/builder/http.rb', line 9

def initialize(url:, http_method: "GET", headers: {}, body: nil, tool:)
  super(url: url, headers: headers, tool: tool)
  @http_method = http_method.upcase
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/dev_suite/request_builder/builder/http.rb', line 7

def body
  @body
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



7
8
9
# File 'lib/dev_suite/request_builder/builder/http.rb', line 7

def http_method
  @http_method
end

Instance Method Details

#build_commandObject



15
16
17
18
19
20
21
22
# File 'lib/dev_suite/request_builder/builder/http.rb', line 15

def build_command
  case tool
  when :curl
    Tool::Curl.new.build_command(http_method: http_method, url: url, headers: headers, body: format_body(body))
  else
    raise ArgumentError, "Unknown tool: #{tool}"
  end
end