public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 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
# An example of using Cloudkick's oauth API. Make sure the
# key you're using has read/write privileges (the default
# is just execute privileges). You'll need the json and
# the oauth gems installed as well for this to work properly.
 
require 'rubygems'
require 'oauth'
require 'json'
 
# make the consumer out of your secret and key
consumer_key = "<key>"
consumer_secret = "<secret>"
consumer = OAuth::Consumer.new(consumer_key, consumer_secret,
:site => "https://api.cloudkick.com",
:http_method => :get)
 
# make the access token from your consumer
access_token = OAuth::AccessToken.new(consumer)
 
# make a signed request!
req = access_token.get("/1.0/query/nodes")
 
case req.response.code
when "200"
nodes = JSON.parse(req.response.body, :symbolize_names => true)
else
puts "error: #{req.inspect}"
end
 
# loop through all nodes, removing any that have agents in the disconnected state
nodes.each do |node|
if node[:agent_state] == "disconnected"
puts "removing #{node[:name]}..."
req = access_token.delete("/1.0/node/#{node[:id]}")
puts req.inspect # 204 => successful
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.