cadburybot 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21a58b8e6245e6d82b0cde452f25faf3bb72c1d848409ff19285dbafc56c9b97
4
+ data.tar.gz: 13981ddf87b7fd490140b1f61c1d821cf9ed846e77d5f03f16182c18de5b68d5
5
+ SHA512:
6
+ metadata.gz: cfaee1d9908ee62c4ee66e301276a571c8ceeed530b96b5264a2c0ffe485eef898743c30ba09ccc5f69e1114a14fd0645d59144971022e65b35bbd0e7f4c8544
7
+ data.tar.gz: af2066155f7c920226378d7c343bfa1f265bdbba94616422204b33d2c23a88c4a4a04861b5702206531e4194842ee5aef6c8c98bfe4dbbdedf91113c2f98a73f
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Cadbury
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cadbury`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cadbury'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cadbury
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cadbury. 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]/cadbury/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Cadbury project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cadbury/blob/master/CODE_OF_CONDUCT.md).
data/bin/cadburybot ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../lib/cadbury", __dir__)
4
+
5
+ Cadbury::CLI.start(ARGV)
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "cadbury"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module Cadbury
6
+ class CLI < Thor
7
+ desc "hello [name]", "say my name"
8
+
9
+ def hello(name)
10
+ if name == "Heisenberg"
11
+ puts "you are goddman right"
12
+ else
13
+ puts "say my name"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "fileutils"
5
+
6
+ class EnvironmentBuilder
7
+ APIBOT_DIR = "#{Dir.home}/apibot"
8
+ ENV_FILE_PATH = "#{APIBOT_DIR}/environment.json"
9
+
10
+ attr_accessor :configs
11
+
12
+ def self.create_environment
13
+ config_util = EnvironmentBuilder.new
14
+ config_util.get_environment
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
+ def initialize
22
+ puts "Hi, I am ApiBot!"
23
+ print "You can have multiple environments of API requests and easily switch between them. "
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 : {}
29
+ @env = "dev"
30
+ end
31
+
32
+ def self.read_configs
33
+ config = File.open ENV_FILE_PATH
34
+ config_json = JSON.load config
35
+ config.close
36
+ config_json
37
+ rescue StandardError => e
38
+ if e.message.include? "No such file or directory"
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}"
42
+ end
43
+ exit
44
+ end
45
+
46
+ def self.get_config(env:)
47
+ EnvironmentBuilder.read_configs[env]
48
+ end
49
+
50
+ def get_environment
51
+ puts "Enter the environment name: [dev]"
52
+ env = $stdin.gets.chomp
53
+ @env = env unless env.empty?
54
+ @configs[@env] = {} unless @configs.key?(@env)
55
+ end
56
+
57
+ def get_base_url
58
+ puts "Enter the Base URL: ['']"
59
+ env = $stdin.gets.chomp
60
+ @configs[@env]["base_url"] = env.empty? ? "" : env
61
+ end
62
+
63
+ def get_auth_token_header_key
64
+ puts "Enter the authorization token header key: [Authorization]"
65
+ env = $stdin.gets.chomp
66
+ @configs[@env]["token_key"] = env.empty? ? "Authorization" : env
67
+ end
68
+
69
+ def get_auth_token_header_value
70
+ puts "Enter the authorization token header value. Eg., Bearer asda23245tfasd: ['']"
71
+ env = $stdin.gets.chomp
72
+ @configs[@env]["token_value"] = env.empty? ? "" : env
73
+ end
74
+
75
+ def save_config_as_json
76
+ FileUtils.mkdir_p APIBOT_DIR
77
+ File.open(ENV_FILE_PATH, "w") do |config|
78
+ config.write(JSON.pretty_generate(@configs))
79
+ puts "Config saved successfully in #{ENV_FILE_PATH}"
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Global
4
+ OPTIONS = { env: "dev", headers: {} }.freeze
5
+ DIVIDER = "-" * 50
6
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+ require_relative './environment_builder'
5
+ require_relative './global'
6
+ require "json"
7
+ require "whirly"
8
+ require "paint"
9
+
10
+ class HttpClient
11
+ include HTTParty
12
+ config = EnvironmentBuilder.get_config(env: Global::OPTIONS[:env])
13
+ base_uri config["base_url"]
14
+ headers config["headers"]
15
+
16
+ def self.send_get_request
17
+ Whirly.start do
18
+ Whirly.status = "Loading..."
19
+ response = HttpClient.get(ARGV[1])
20
+ HttpClient.pretty_print(response)
21
+ end
22
+ end
23
+
24
+ def self.pretty_print(response)
25
+ puts Global::DIVIDER
26
+ puts response.request.uri
27
+ puts Global::DIVIDER
28
+ puts "#{response.code} #{response.message}"
29
+ puts Global::DIVIDER
30
+ puts response.body
31
+ puts Global::DIVIDER
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cadbury
4
+ VERSION = "0.1.2"
5
+ end
data/lib/cadbury.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cadbury/cli"
4
+ require "thor"
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cadburybot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Sharran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.20'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.20'
83
+ - !ruby/object:Gem::Dependency
84
+ name: whirly
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.2.26
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.2.26
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Write a longer description or delete this line.
126
+ email:
127
+ - sharran.murali@gmail.com
128
+ executables:
129
+ - cadburybot
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - README.md
134
+ - bin/cadburybot
135
+ - bin/console
136
+ - bin/setup
137
+ - lib/cadbury.rb
138
+ - lib/cadbury/cli.rb
139
+ - lib/cadbury/helpers/environment_builder.rb
140
+ - lib/cadbury/helpers/global.rb
141
+ - lib/cadbury/helpers/http_client.rb
142
+ - lib/cadbury/version.rb
143
+ homepage: https://github.com/sharran-murali/cadbury
144
+ licenses:
145
+ - MIT
146
+ metadata:
147
+ allowed_push_host: https://rubygems.org
148
+ homepage_uri: https://github.com/sharran-murali/cadbury
149
+ source_code_uri: https://github.com/sharran-murali/cadbury
150
+ changelog_uri: https://github.com/sharran-murali/cadbury/CHANGELOG.md
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 2.6.0
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubygems_version: 3.2.22
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Write a short summary, because RubyGems requires one.
170
+ test_files: []