Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rrichards
Created May 23, 2011 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrichards/987135 to your computer and use it in GitHub Desktop.
Save rrichards/987135 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment