Class: Delete

Inherits:
Object
  • Object
show all
Defined in:
lib/red_drop/delete.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Delete

Returns a new instance of Delete.



2
3
4
# File 'lib/red_drop/delete.rb', line 2

def initialize(client)
  @client = client
end

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/red_drop/delete.rb', line 6

def execute
  puts "loading... \n"

  droplets = JSON.parse(@client.get.body)["droplets"]

  if droplets.length == 0
    puts "\nThere are no droplets in your DigitalOcean cloud.\n"
    return
  end

  hash = {}
  droplets.each_with_index { |drop, i| hash[i.to_s] = drop } 
  droplets = hash

  option = nil

  until droplets.has_key? option
    puts "\noption: droplet_id\n"
    droplets.each { |key, droplet| puts "#{key}: #{droplet["id"]}" }
    puts "\nPlease enter an option for a droplet to delete?\n\n"

    option = gets.chomp
  end

  response = @client.delete(droplets[option]["id"].to_s)

  if response.success?
    puts "\ndelete request processed succesfully\n\n"
  else 
    puts response.body
  end
end