cadburybot 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +15 -29
 - data/bin/{cadburybot → cb} +0 -0
 - data/lib/cadbury/environment.rb +8 -4
 - data/lib/cadbury/helpers/config_manager.rb +32 -0
 - data/lib/cadbury/helpers/environment_builder.rb +32 -38
 - data/lib/cadbury/helpers/global.rb +2 -0
 - data/lib/cadbury/helpers/request_builder.rb +83 -0
 - data/lib/cadbury/request.rb +29 -0
 - data/lib/cadbury/version.rb +1 -1
 - data/lib/cadbury.rb +8 -0
 - metadata +8 -5
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2c371c8182fbcbea0a95fba155932c49773f1369ece5f872aa029140b69749d5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fba23894de55ff18063b000afc7e58ccdadedf9ecf3a5e731922f2ce4f8015e5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 70fef744a7aedcdbd74d3588105c1afac2b9c3596a64d8d0b8f992f515a6e8d92560f636ca24230ddb76955091f2324c76f59320424d82647750830c96f89646
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c998b25201a0b1423289efa4604110636f7f5393a364cd3c587bd781f9688931934ac5592753f5cde6b90e42a50c989aaa6e93324e9350af2baddb40538c6d3c
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,24 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # CadburyBot :man_in_tuxedo:
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## Under development 🚧
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            ##  
     | 
| 
      
 5 
     | 
    
         
            +
            ## Usage
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            ```bash
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
            cb env get # lists all the environments
         
     | 
| 
      
 9 
     | 
    
         
            +
            cb env get <env-name> # lists the asked envrironment
         
     | 
| 
      
 10 
     | 
    
         
            +
            cb env set <environment-name> # Creates or updates environment by asking questions to you.
         
     | 
| 
      
 11 
     | 
    
         
            +
            cb env delete <environment-name>
         
     | 
| 
      
 12 
     | 
    
         
            +
            cb env default <environment-name> # sets the default environment
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            cb request get # lists all the request for the default environment
         
     | 
| 
      
 15 
     | 
    
         
            +
            cb request get <request-name> # lists the asked request
         
     | 
| 
      
 16 
     | 
    
         
            +
            cb request set <request-name> # add/update request to the default environment by answering the questions like request endpoint, http method etc.,
         
     | 
| 
      
 17 
     | 
    
         
            +
            cb request delete <request-name>
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            cb send <request-name> #uses default environment
         
     | 
| 
       20 
20 
     | 
    
         
             
            or
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
            cb send <request-name> --env <env-name>
         
     | 
| 
       22 
22 
     | 
    
         
             
            ```
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
            > Pro tip: CadburyBot saves all these configurations as JSON file under `~/cadburybot` directory. Instead of using `request` or `env` command, You can also manually update them.
         
     | 
| 
         @@ -39,20 +39,6 @@ Or install it yourself as: 
     | 
|
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                $ gem install cadburybot
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            ## Usage
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
            TODO: Write usage instructions here
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            ## Development
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
            ## Contributing
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
            Bug reports and pull requests are welcome on GitHub at https://github.com/sharran-murali/cadburybot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cadburybot/blob/master/CODE_OF_CONDUCT.md).
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
42 
     | 
    
         
             
            ## License
         
     | 
| 
       57 
43 
     | 
    
         | 
| 
       58 
44 
     | 
    
         
             
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         
     | 
    
        data/bin/{cadburybot → cb}
    RENAMED
    
    | 
         
            File without changes
         
     | 
    
        data/lib/cadbury/environment.rb
    CHANGED
    
    | 
         @@ -1,22 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "thor"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "json"
         
     | 
| 
       3 
3 
     | 
    
         
             
            require_relative "./helpers/environment_builder"
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative "./helpers/loader"
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
5 
     | 
    
         
             
            module Cadbury
         
     | 
| 
       7 
6 
     | 
    
         
             
              class Env < Thor
         
     | 
| 
       8 
7 
     | 
    
         
             
                desc "set [environment-name]", "Creates a new environment or updates the existing environment"
         
     | 
| 
       9 
8 
     | 
    
         
             
                def set(name)
         
     | 
| 
       10 
     | 
    
         
            -
                  EnvironmentBuilder.create_environment name
         
     | 
| 
      
 9 
     | 
    
         
            +
                  EnvironmentBuilder.new.create_environment name
         
     | 
| 
       11 
10 
     | 
    
         
             
                end
         
     | 
| 
       12 
11 
     | 
    
         | 
| 
       13 
12 
     | 
    
         
             
                desc "get 'or' get [environment-name]", "Gets all environments or the asked environment"
         
     | 
| 
       14 
13 
     | 
    
         
             
                def get(name = nil)
         
     | 
| 
       15 
14 
     | 
    
         
             
                  if name.nil?
         
     | 
| 
       16 
     | 
    
         
            -
                    puts JSON.pretty_generate EnvironmentBuilder. 
     | 
| 
      
 15 
     | 
    
         
            +
                    puts JSON.pretty_generate EnvironmentBuilder.new.list_environments
         
     | 
| 
       17 
16 
     | 
    
         
             
                  else
         
     | 
| 
       18 
     | 
    
         
            -
                    puts JSON.pretty_generate EnvironmentBuilder. 
     | 
| 
      
 17 
     | 
    
         
            +
                    puts JSON.pretty_generate EnvironmentBuilder.new.get_environment(name: name)
         
     | 
| 
       19 
18 
     | 
    
         
             
                  end
         
     | 
| 
       20 
19 
     | 
    
         
             
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                desc "delete [environment-name]", "Deletes the environment"
         
     | 
| 
      
 22 
     | 
    
         
            +
                def delete(name)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  EnvironmentBuilder.new.delete_environment name
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
       21 
25 
     | 
    
         
             
              end
         
     | 
| 
       22 
26 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "json"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "fileutils"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "./global"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            class ConfigManager
         
     | 
| 
      
 6 
     | 
    
         
            +
              def get_all
         
     | 
| 
      
 7 
     | 
    
         
            +
                config = File.open Global::ENV_FILE_PATH
         
     | 
| 
      
 8 
     | 
    
         
            +
                config_json = JSON.load config
         
     | 
| 
      
 9 
     | 
    
         
            +
                config.close
         
     | 
| 
      
 10 
     | 
    
         
            +
                config_json
         
     | 
| 
      
 11 
     | 
    
         
            +
              rescue StandardError => e
         
     | 
| 
      
 12 
     | 
    
         
            +
                if e.message.include? "No such file or directory"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  puts "Error: No Environment file found at #{ENV_FILE_PATH}."
         
     | 
| 
      
 14 
     | 
    
         
            +
                  puts "Please run 'cadburybot env set <env-name>' command to create a new environment"
         
     | 
| 
      
 15 
     | 
    
         
            +
                else
         
     | 
| 
      
 16 
     | 
    
         
            +
                  puts "Error: #{e.message}"
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
                exit
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def get_by_env(env:)
         
     | 
| 
      
 22 
     | 
    
         
            +
                get_all[env]
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def save(configs)
         
     | 
| 
      
 26 
     | 
    
         
            +
                FileUtils.mkdir_p Global::APIBOT_DIR
         
     | 
| 
      
 27 
     | 
    
         
            +
                File.open(Global::ENV_FILE_PATH, "w") do |f|
         
     | 
| 
      
 28 
     | 
    
         
            +
                  f.write(JSON.pretty_generate(configs))
         
     | 
| 
      
 29 
     | 
    
         
            +
                  puts "Config updated successfully in #{Global::ENV_FILE_PATH}"
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -2,57 +2,55 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require "json"
         
     | 
| 
       4 
4 
     | 
    
         
             
            require "fileutils"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative "./config_manager"
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            class EnvironmentBuilder
         
     | 
| 
       7 
     | 
    
         
            -
              APIBOT_DIR = "#{Dir.home}/apibot".freeze
         
     | 
| 
       8 
     | 
    
         
            -
              ENV_FILE_PATH = "#{APIBOT_DIR}/environment.json".freeze
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
8 
     | 
    
         
             
              attr_accessor :configs
         
     | 
| 
       11 
9 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              def self.create_environment(name)
         
     | 
| 
       13 
     | 
    
         
            -
                config_util = EnvironmentBuilder.new
         
     | 
| 
       14 
     | 
    
         
            -
                config_util.set_environment name
         
     | 
| 
       15 
     | 
    
         
            -
                config_util.get_base_url
         
     | 
| 
       16 
     | 
    
         
            -
                config_util.get_auth_token_header_key
         
     | 
| 
       17 
     | 
    
         
            -
                config_util.get_auth_token_header_value
         
     | 
| 
       18 
     | 
    
         
            -
                config_util.save_config_as_json
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
10 
     | 
    
         
             
              def initialize
         
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                puts "To create an environment please follow the steps,\n"
         
     | 
| 
       25 
     | 
    
         
            -
                puts "Note: I have created some default values for easily getting started."
         
     | 
| 
       26 
     | 
    
         
            -
                puts "Press enter for using default value."
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                @configs = File.exist?(ENV_FILE_PATH) ? EnvironmentBuilder.read_configs : {}
         
     | 
| 
      
 11 
     | 
    
         
            +
                @config_manager = ConfigManager.new
         
     | 
| 
      
 12 
     | 
    
         
            +
                @configs = {}
         
     | 
| 
       29 
13 
     | 
    
         
             
                @env = "dev"
         
     | 
| 
       30 
14 
     | 
    
         
             
              end
         
     | 
| 
       31 
15 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
              def  
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  puts "Error: No Environment file found at #{ENV_FILE_PATH}. Please run 'init' command to create a new environment"
         
     | 
| 
       40 
     | 
    
         
            -
                else
         
     | 
| 
       41 
     | 
    
         
            -
                  puts "Error: #{e.message}"
         
     | 
| 
      
 16 
     | 
    
         
            +
              def create_environment(name, silent: false)
         
     | 
| 
      
 17 
     | 
    
         
            +
                unless silent
         
     | 
| 
      
 18 
     | 
    
         
            +
                  puts "Hi, I am ApiBot!"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  print "You can have multiple environments of API requests and easily switch between them. "
         
     | 
| 
      
 20 
     | 
    
         
            +
                  puts "To create an environment please follow the steps,\n"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  puts "Note: I have created some default values for easily getting started."
         
     | 
| 
      
 22 
     | 
    
         
            +
                  puts "Press enter for using default value."
         
     | 
| 
       42 
23 
     | 
    
         
             
                end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                @configs = @config_manager.get_all if File.exist?(Global::ENV_FILE_PATH)
         
     | 
| 
      
 26 
     | 
    
         
            +
                set_environment name
         
     | 
| 
      
 27 
     | 
    
         
            +
                get_base_url
         
     | 
| 
      
 28 
     | 
    
         
            +
                get_auth_token_header_key
         
     | 
| 
      
 29 
     | 
    
         
            +
                get_auth_token_header_value
         
     | 
| 
      
 30 
     | 
    
         
            +
                save_config_as_json
         
     | 
| 
       44 
31 
     | 
    
         
             
              end
         
     | 
| 
       45 
32 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
              def  
     | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
      
 33 
     | 
    
         
            +
              def list_environments
         
     | 
| 
      
 34 
     | 
    
         
            +
                @config_manager.get_all
         
     | 
| 
       48 
35 
     | 
    
         
             
              end
         
     | 
| 
       49 
36 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
               
     | 
| 
      
 37 
     | 
    
         
            +
              def get_environment(name:)
         
     | 
| 
      
 38 
     | 
    
         
            +
                @config_manager.get_by_env(env: name)
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              def delete_environment(name)
         
     | 
| 
      
 42 
     | 
    
         
            +
                environments = @config_manager.get_all
         
     | 
| 
      
 43 
     | 
    
         
            +
                environments.delete(name)
         
     | 
| 
      
 44 
     | 
    
         
            +
                @config_manager.save environments
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              private
         
     | 
| 
       51 
48 
     | 
    
         | 
| 
       52 
49 
     | 
    
         
             
              def set_environment(name)
         
     | 
| 
       53 
50 
     | 
    
         
             
                env = name
         
     | 
| 
       54 
51 
     | 
    
         
             
                @env = env unless env.empty?
         
     | 
| 
       55 
52 
     | 
    
         
             
                @configs[@env] = {} unless @configs.key?(@env)
         
     | 
| 
      
 53 
     | 
    
         
            +
                @configs[@env]["requests"] = {}
         
     | 
| 
       56 
54 
     | 
    
         
             
              end
         
     | 
| 
       57 
55 
     | 
    
         | 
| 
       58 
56 
     | 
    
         
             
              def get_base_url
         
     | 
| 
         @@ -74,10 +72,6 @@ class EnvironmentBuilder 
     | 
|
| 
       74 
72 
     | 
    
         
             
              end
         
     | 
| 
       75 
73 
     | 
    
         | 
| 
       76 
74 
     | 
    
         
             
              def save_config_as_json
         
     | 
| 
       77 
     | 
    
         
            -
                 
     | 
| 
       78 
     | 
    
         
            -
                File.open(ENV_FILE_PATH, "w") do |config|
         
     | 
| 
       79 
     | 
    
         
            -
                  config.write(JSON.pretty_generate(@configs))
         
     | 
| 
       80 
     | 
    
         
            -
                  puts "Config saved successfully in #{ENV_FILE_PATH}"
         
     | 
| 
       81 
     | 
    
         
            -
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
                @config_manager.save(@configs)
         
     | 
| 
       82 
76 
     | 
    
         
             
              end
         
     | 
| 
       83 
77 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,83 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "json"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "fileutils"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "./global"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "./config_manager"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class RequestBuilder
         
     | 
| 
      
 7 
     | 
    
         
            +
              def initialize(name: "", env: "dev")
         
     | 
| 
      
 8 
     | 
    
         
            +
                @env = env
         
     | 
| 
      
 9 
     | 
    
         
            +
                @name = name
         
     | 
| 
      
 10 
     | 
    
         
            +
                @endpoint = ""
         
     | 
| 
      
 11 
     | 
    
         
            +
                @headers = {}
         
     | 
| 
      
 12 
     | 
    
         
            +
                @method = "get"
         
     | 
| 
      
 13 
     | 
    
         
            +
                @body = {}
         
     | 
| 
      
 14 
     | 
    
         
            +
                @request = {}
         
     | 
| 
      
 15 
     | 
    
         
            +
                @config_manager = ConfigManager.new
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              def create_request
         
     | 
| 
      
 19 
     | 
    
         
            +
                get_endpoint
         
     | 
| 
      
 20 
     | 
    
         
            +
                get_headers
         
     | 
| 
      
 21 
     | 
    
         
            +
                get_method
         
     | 
| 
      
 22 
     | 
    
         
            +
                get_body
         
     | 
| 
      
 23 
     | 
    
         
            +
                self
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              def get_all
         
     | 
| 
      
 27 
     | 
    
         
            +
                @config_manager.get_all[@env]["requests"]
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              def get_by_name(name)
         
     | 
| 
      
 31 
     | 
    
         
            +
                @config_manager.get_all[@env]["requests"][name]
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              def save
         
     | 
| 
      
 35 
     | 
    
         
            +
                configs = @config_manager.get_all
         
     | 
| 
      
 36 
     | 
    
         
            +
                if configs.nil? || configs == {}
         
     | 
| 
      
 37 
     | 
    
         
            +
                  puts "Error: No Environments detected."
         
     | 
| 
      
 38 
     | 
    
         
            +
                  puts "Please run 'cadburybot env set <env-name>' command to create a new environment"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  exit
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
                configs[@env]["requests"][@name] = build_request
         
     | 
| 
      
 42 
     | 
    
         
            +
                @config_manager.save configs
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              private
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def get_endpoint
         
     | 
| 
      
 48 
     | 
    
         
            +
                puts "Endpoint: eg., /api/check-weather"
         
     | 
| 
      
 49 
     | 
    
         
            +
                @endpoint = $stdin.gets.chomp
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              def get_headers
         
     | 
| 
      
 53 
     | 
    
         
            +
                loop do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  puts "Headers: [headerKey:headerValue] ---> Type value or press <Enter> to skip"
         
     | 
| 
      
 55 
     | 
    
         
            +
                  key, value = $stdin.gets.chomp.split ":"
         
     | 
| 
      
 56 
     | 
    
         
            +
                  break if key.nil? || value.nil?
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  @headers[key] = value
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              rescue StandardError => e
         
     | 
| 
      
 61 
     | 
    
         
            +
                puts "Error: #{e.message}"
         
     | 
| 
      
 62 
     | 
    
         
            +
                exit
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              def get_method
         
     | 
| 
      
 66 
     | 
    
         
            +
                puts "Method: [GET]"
         
     | 
| 
      
 67 
     | 
    
         
            +
                @method = $stdin.gets.chomp.upcase
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              def get_body
         
     | 
| 
      
 71 
     | 
    
         
            +
                puts "Body: []"
         
     | 
| 
      
 72 
     | 
    
         
            +
                body = $stdin.gets.chomp
         
     | 
| 
      
 73 
     | 
    
         
            +
                @body = JSON.parse body unless body.empty?
         
     | 
| 
      
 74 
     | 
    
         
            +
              end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
              def build_request
         
     | 
| 
      
 77 
     | 
    
         
            +
                {
         
     | 
| 
      
 78 
     | 
    
         
            +
                  method: @method,
         
     | 
| 
      
 79 
     | 
    
         
            +
                  headers: @headers,
         
     | 
| 
      
 80 
     | 
    
         
            +
                  body: @body
         
     | 
| 
      
 81 
     | 
    
         
            +
                }
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "thor"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "json"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "./helpers/request_builder"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Cadbury
         
     | 
| 
      
 6 
     | 
    
         
            +
              class Request < Thor
         
     | 
| 
      
 7 
     | 
    
         
            +
                desc "set [request-name]", "Creates a new request or updates the existing request"
         
     | 
| 
      
 8 
     | 
    
         
            +
                def set(name)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  RequestBuilder
         
     | 
| 
      
 10 
     | 
    
         
            +
                    .new(name: name, env: options[:env])
         
     | 
| 
      
 11 
     | 
    
         
            +
                    .create_request
         
     | 
| 
      
 12 
     | 
    
         
            +
                    .save
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                desc "get 'or' get [environment-name]", "Gets all environments or the asked environment"
         
     | 
| 
      
 16 
     | 
    
         
            +
                def get(name = nil)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  if name.nil?
         
     | 
| 
      
 18 
     | 
    
         
            +
                    puts JSON.pretty_generate RequestBuilder.new(env: options[:env]).get_all
         
     | 
| 
      
 19 
     | 
    
         
            +
                  else
         
     | 
| 
      
 20 
     | 
    
         
            +
                    puts JSON.pretty_generate RequestBuilder.new(name: name).get_by_name name
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                desc "delete [environment-name]", "Deletes the environment"
         
     | 
| 
      
 25 
     | 
    
         
            +
                def delete(name)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  # EnvironmentBuilder.delete_environment(name)
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/cadbury/version.rb
    CHANGED
    
    
    
        data/lib/cadbury.rb
    CHANGED
    
    | 
         @@ -1,9 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "cadbury/environment"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "cadbury/request"
         
     | 
| 
       2 
3 
     | 
    
         
             
            require "thor"
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            module Cadbury
         
     | 
| 
       5 
6 
     | 
    
         
             
              class CLI < Thor
         
     | 
| 
      
 7 
     | 
    
         
            +
                shared_options = [:env, { type: :string, required: true }]
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       6 
9 
     | 
    
         
             
                desc "env [command]", "CRUD operations for environment"
         
     | 
| 
      
 10 
     | 
    
         
            +
                method_option(*shared_options)
         
     | 
| 
       7 
11 
     | 
    
         
             
                subcommand "env", Cadbury::Env
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                desc "request [command]", "CRUD operations for request"
         
     | 
| 
      
 14 
     | 
    
         
            +
                method_option(*shared_options)
         
     | 
| 
      
 15 
     | 
    
         
            +
                subcommand "request", Cadbury::Request
         
     | 
| 
       8 
16 
     | 
    
         
             
              end
         
     | 
| 
       9 
17 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cadburybot
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Sharran
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-08- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-08-31 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: httparty
         
     | 
| 
         @@ -126,20 +126,23 @@ description: Write a longer description or delete this line. 
     | 
|
| 
       126 
126 
     | 
    
         
             
            email:
         
     | 
| 
       127 
127 
     | 
    
         
             
            - sharran.murali@gmail.com
         
     | 
| 
       128 
128 
     | 
    
         
             
            executables:
         
     | 
| 
       129 
     | 
    
         
            -
            -  
     | 
| 
      
 129 
     | 
    
         
            +
            - cb
         
     | 
| 
       130 
130 
     | 
    
         
             
            extensions: []
         
     | 
| 
       131 
131 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       132 
132 
     | 
    
         
             
            files:
         
     | 
| 
       133 
133 
     | 
    
         
             
            - README.md
         
     | 
| 
       134 
     | 
    
         
            -
            - bin/ 
     | 
| 
      
 134 
     | 
    
         
            +
            - bin/cb
         
     | 
| 
       135 
135 
     | 
    
         
             
            - bin/console
         
     | 
| 
       136 
136 
     | 
    
         
             
            - bin/setup
         
     | 
| 
       137 
137 
     | 
    
         
             
            - lib/cadbury.rb
         
     | 
| 
       138 
138 
     | 
    
         
             
            - lib/cadbury/environment.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - lib/cadbury/helpers/config_manager.rb
         
     | 
| 
       139 
140 
     | 
    
         
             
            - lib/cadbury/helpers/environment_builder.rb
         
     | 
| 
       140 
141 
     | 
    
         
             
            - lib/cadbury/helpers/global.rb
         
     | 
| 
       141 
142 
     | 
    
         
             
            - lib/cadbury/helpers/http_client.rb
         
     | 
| 
       142 
143 
     | 
    
         
             
            - lib/cadbury/helpers/loader.rb
         
     | 
| 
      
 144 
     | 
    
         
            +
            - lib/cadbury/helpers/request_builder.rb
         
     | 
| 
      
 145 
     | 
    
         
            +
            - lib/cadbury/request.rb
         
     | 
| 
       143 
146 
     | 
    
         
             
            - lib/cadbury/version.rb
         
     | 
| 
       144 
147 
     | 
    
         
             
            homepage: https://github.com/sharran-murali/cadbury
         
     | 
| 
       145 
148 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -157,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       157 
160 
     | 
    
         
             
              requirements:
         
     | 
| 
       158 
161 
     | 
    
         
             
              - - ">="
         
     | 
| 
       159 
162 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       160 
     | 
    
         
            -
                  version:  
     | 
| 
      
 163 
     | 
    
         
            +
                  version: '3.0'
         
     | 
| 
       161 
164 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       162 
165 
     | 
    
         
             
              requirements:
         
     | 
| 
       163 
166 
     | 
    
         
             
              - - ">="
         
     |