Class: Status

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Status

Returns a new instance of Status.



2
3
4
# File 'lib/red_drop/status.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
# File 'lib/red_drop/status.rb', line 6

def execute
  puts "loading... \n\n"

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

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

  droplets.each do |droplet|
    droplet["networks"] = droplet["networks"]["v4"].find { |n| n["type"] == "public" } 

    if droplet["networks"]
      droplet["status"] = "running on #{droplet["networks"]["ip_address"]}"
    else
      droplet["status"] = "ip not yet assigned, try again in a minute"
    end

    puts "droplet: #{droplet["id"]} #{droplet["status"]}"
  end
end