Last active
December 17, 2015 23:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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