Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created June 2, 2009 17:58
Show Gist options
  • Save willbailey/122396 to your computer and use it in GitHub Desktop.
Save willbailey/122396 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'cgi'
require 'time'
# =====================================================
# = Proof of Concept Shareflow Command Line Interface =
# =====================================================
# currently it just gets the list of your 10 most recent
# comment posts and prints them out with comments.
#
# I'll be adding some more features. Feel free to hack
# on this as well
# can get your token in Shareflow from firebug
# Channels.Application.currentUser.get('auth_token')
token = '<auth token>'
domain = 'corp.zenbe.com'
# ShareFlow API call for recent posts
#
recent_posts = {
"posts" => {
"limit" => 10,
"order" => 'updated_at DESC',
"type" => ['IN', 'CommentPost']
}
}
# read requests are posted as "query"
api_call = "query=" + CGI.escape(recent_posts.to_json)
# curl command to run
cmd = "curl http://biz.zenbe.com/#{domain}/shareflow/api/v1.json?key=#{token} -d \"#{api_call}\""
# parse the result of the curl command
response = JSON.parse(IO.popen("curl #{cmd} -s").read)
# iterate over the posts
posts = response["posts"]
posts.each do |post|
if post["content"]
puts "\033[0;31m#{Time.parse(post["updated_at"]).strftime("%b %d, %Y")}\e[0m #{post["user"]["first_name"]} posted a comment..."
puts post["content"]
if post["comments"] && post["comments"].size > 0
puts "Comments:\n"
post["comments"].each do |comment|
puts "\033[0;33m#{Time.parse(comment["updated_at"]).strftime("%b %D, %Y")}\e[0m\n#{comment["user"]["first_name"]} commented... \n#{comment["content"]}\n"
end
end
puts "************************************\n\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment