Skip to content

Instantly share code, notes, and snippets.

@errordeveloper
Last active December 17, 2015 23:48
Show Gist options
  • Save errordeveloper/5691447 to your computer and use it in GitHub Desktop.
Save errordeveloper/5691447 to your computer and use it in GitHub Desktop.
Xively request log subscriber. It takes two arguments: username and a master API key. It requires Ruby version 1.9.3.
require 'json'
require 'socket'
abort "Usage: #{$0} username xi_api_key" if ARGV.size != 2
username = ARGV[0]
xi_api_key = ARGV[1]
xi = TCPSocket.open('api.xively.com', 8081)
xi.puts({
method: "subscribe",
resource: "/users/#{username}/requests",
headers: { "X-ApiKey" => "#{xi_api_key}" },
}.to_json)
while line = xi.gets
puts line
end
xi.close
#!/bin/sh
# You can do this with telnet:
# telnet 'api.xively.com' 8081
# Trying 64.94.18.120...
# Connected to api.xively.com.
# Escape character is '^]'.
# {"method":"subscribe", "resource":"/users/<your_username>/requests", "headers":{ "X-ApiKey":"<your_api_key>" }}
# And you will get response similar to this followed by many log lines:
# {"status":200,"resource":"/users/errordeveloper/requests"}
#
# Here is the version of this that is using netcat.
if [ ! $# = 2 ]
then
echo "Usage: $0 <username> <api_key>"
exit 1
fi
json_call='{ "method":"subscribe", "resource":"/users/%s/requests", "headers":{ "X-ApiKey":"%s" }}\n'
tail -f <<< $(printf "$json_call" $1 $2) | nc api.xively.com 8081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment