red_drop 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 650b690e863fa3223fa8111c28f1105f644107396b006614980e6394096d8f59
4
- data.tar.gz: 23a050d37eb35151c4c91fb08a98d98a074d897e4aab159610bf157ec1bbe183
3
+ metadata.gz: 0d28d88532deca7906c0a221dea00ed41441a10327fe2b0f8645683fd3212051
4
+ data.tar.gz: 4092ed01f7810eb0f9f44862422a55a7d6657ca8dfc2b91baf1ad5353a40d18f
5
5
  SHA512:
6
- metadata.gz: e24b7f0d8a9f898a75f79aef5e3e6a448ea8a58880c430a4b386361e84e10bab1493be6d56a1b60a6311eab83b7bf1420e55b94e5d883a6bfaa7608831894682
7
- data.tar.gz: 14c7800731c053b00a2d2562dbb5b4e2ab4688551ec0c85068f3907abe100773642fee970fb3d6b69f371ab0c62757679c7606aaac0ebd45b201a208673dd631
6
+ metadata.gz: 6b3924b1f24754a170c46b7f09bf6fcc35e5ab079999f6f448ed7bdd6fbe23e7e94613aa7df2413a20c99ea8d17f796620018cd71db3df18fadd03d800eb9e55
7
+ data.tar.gz: bf86b6c9813d0e560f5d9b89ab7dc4d66dc5d6a6fe58a1167ce2f06d90ca0532bde3f685d100567fa1fb2dadeb3ea4a7b311e77e710a0cd32f1abd0a1ca3b1aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- red_drop (0.3.1)
4
+ red_drop (0.3.2)
5
5
  droplet_kit (~> 3.18)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -28,11 +28,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sergio
28
28
 
29
29
  ### Todos
30
30
 
31
- - Research: TDD whether its w/ minitest or rspec
32
31
  - Refactor: status module to match delete module droplets data structure
33
- - Research: converting delete module droplets array to hash to avoid accidental deletions
34
32
  - Refactor: delete module while loop to match that of red_drop.rb
35
- - Research: Faraday, used by DropletKit, to replace built-in HTTP client library
33
+ - Research: TDD whether its w/ minitest or rspec
34
+ - Research: converting delete module droplets array to hash to avoid accidental deletions
36
35
  - Research: status module to get ip address of runnning droplets
37
36
  - Research: delete module to get droplet status before executing
38
37
  - Research: using cloud_init to automate server config for SSH, ufw, docker
data/exe/red_drop CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "red_drop"
4
4
 
5
- RedDrop.start
5
+ RedDrop.new.begin
data/lib/red_drop/auth.rb CHANGED
@@ -1,27 +1,28 @@
1
- require "net/http"
1
+ require "faraday"
2
2
 
3
3
  class Auth
4
4
  def initialize
5
+ puts "loading..."
6
+
5
7
  file = File.open("secret.txt", "a+")
6
8
  @secret = file.read
7
9
  file.close
8
10
 
9
- uri = URI('https://api.digitalocean.com/v2/droplets')
10
- @http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https')
11
- @req = Net::HTTP::Get.new(uri)
12
-
13
- @req["Authorization"] = "Bearer #{@secret}"
14
- @res = @http.request(@req)
11
+ @faraday = Faraday.new("https://api.digitalocean.com/v2/droplets")
12
+ @res = @faraday.get do |req|
13
+ req.headers["Authorization"] = "Bearer #{@secret}"
14
+ end
15
15
  end
16
16
 
17
17
  def token
18
- while @secret.empty? or not @res.code === "200"
19
- puts "There in no valid API token in memory,\nplease enter a valid API token."
18
+ while @secret.empty? or not @res.success?
19
+ puts "\nThere in no valid API token in memory,\nplease enter a valid API token."
20
20
  @secret = gets.chomp
21
21
  File.write("secret.txt", @secret)
22
22
 
23
- @req["Authorization"] = "Bearer #{@secret}"
24
- @res = @http.request(@req)
23
+ @res = @faraday.get do |req|
24
+ req.headers["Authorization"] = "Bearer #{@secret}"
25
+ end
25
26
  end
26
27
  @secret
27
28
  end
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedDrop
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
data/lib/red_drop.rb CHANGED
@@ -1,27 +1,29 @@
1
1
  require "red_drop/auth"
2
- require 'droplet_kit'
2
+ require "droplet_kit"
3
3
  require "red_drop/create"
4
4
  require "red_drop/status"
5
5
  require "red_drop/delete"
6
6
 
7
7
  class RedDrop
8
- client = DropletKit::Client.new(access_token: Auth.new.token)
8
+ def initialize
9
+ client = DropletKit::Client.new(access_token: Auth.new.token)
9
10
 
10
- @@task_menu = {
11
- "create" => Create.new(client),
12
- "status" => Status.new(client),
13
- "delete" => Delete.new(client)
14
- }
11
+ @task_menu = {
12
+ "create" => Create.new(client),
13
+ "status" => Status.new(client),
14
+ "delete" => Delete.new(client)
15
+ }
16
+ end
15
17
 
16
- def self.start
18
+ def begin
17
19
  input = nil
18
20
 
19
21
  until input.eql? "exit"
20
- puts "\nEnter from task menu below.\n#{@@task_menu.keys << "exit"}\n\n"
22
+ puts "\nEnter from task menu below.\n#{@task_menu.keys << "exit"}\n\n"
21
23
 
22
24
  input = gets.chomp
23
25
 
24
- @@task_menu[input].execute if @@task_menu.has_key? input
26
+ @task_menu[input].execute if @task_menu.has_key? input
25
27
  end
26
28
  end
27
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_drop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Ortiz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-reporters