Class: RequestBuilder
- Inherits:
-
Object
- Object
- RequestBuilder
- Defined in:
- lib/cadbury/helpers/request_builder.rb
Instance Method Summary collapse
- #create_request ⇒ Object
- #get_all ⇒ Object
- #get_by_name(name) ⇒ Object
-
#initialize(name: "", env: "dev") ⇒ RequestBuilder
constructor
A new instance of RequestBuilder.
- #save ⇒ Object
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_request ⇒ Object
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_all ⇒ Object
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 |
#save ⇒ Object
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 |