Class: RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cadbury/helpers/request_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name: "", env: "dev") ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



7
8
9
10
11
12
13
14
15
16
# File 'lib/cadbury/helpers/request_builder.rb', line 7

def initialize(name: "", env: "dev")
  @env = env
  @name = name
  @endpoint = ""
  @headers = {}
  @method = "get"
  @body = {}
  @request = {}
  @config_manager = ConfigManager.new
end

Instance Method Details

#create_requestObject



18
19
20
21
22
23
24
# File 'lib/cadbury/helpers/request_builder.rb', line 18

def create_request
  get_endpoint
  get_headers
  get_method
  get_body
  self
end

#get_allObject



26
27
28
# File 'lib/cadbury/helpers/request_builder.rb', line 26

def get_all
  @config_manager.get_all[@env]["requests"]
end

#get_by_name(name) ⇒ Object



30
31
32
# File 'lib/cadbury/helpers/request_builder.rb', line 30

def get_by_name(name)
  @config_manager.get_all[@env]["requests"][name]
end

#saveObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/cadbury/helpers/request_builder.rb', line 34

def save
  configs = @config_manager.get_all
  if configs.nil? || configs == {}
    puts "Error: No Environments detected."
    puts "Please run 'cadburybot env set <env-name>' command to create a new environment"
    exit
  end
  configs[@env]["requests"][@name] = build_request
  @config_manager.save configs
end