Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created August 3, 2010 09:51
Show Gist options
  • Save jamesu/506127 to your computer and use it in GitHub Desktop.
Save jamesu/506127 to your computer and use it in GitHub Desktop.
# Teambox API script which un-watches all conversations in a project.
#
# Usage: stop_watching_teambox.rb [project name] [last_id](optional)
#
# Feel free to use! - James
#
require 'rubygems'
require 'httparty'
module Teambox
include HTTParty
# IMPORTANT: Be sure to put in the correct details here!
base_uri "teambox.com/api/1"
basic_auth 'user', 'password'
API_LIMIT=25
# Util to grab a lot of items in separate requests
def self.grab_list(url, max, options={})
count = 0
query = (options[:query]||{}).merge({:count => [API_LIMIT,max].min})
items = []
while count < max
list = get(url, options.merge(:query => query))
items << list
count += list.length
break if list.length == 0
query[:max_id] = list[-1]['id']
end
items.flatten
end
def self.conversations(project, since_id=nil)
query = since_id.nil? ? {} : {:since_id => since_id}
grab_list('/projects/teambox/conversations', 1000, :query => query)
end
def self.unwatch_conversation(project, id)
put("/projects/teambox/conversations/#{id}/unwatch", :body => {:user_id => profile['id']})
end
def self.profile
@profile ||= get('/account')
end
end
list = Teambox.conversations(ARGV[0], ARGV[1])
if list.length > 0
puts "Last Conversation: #{list[0]['id']}"
end
puts "Logged in as: #{Teambox.profile['username']} (#{Teambox.profile['id']})"
list.each do |conversation|
includes_user = conversation['watchers'].include? Teambox.profile['id']
if includes_user
print "Removing from #{conversation['name']}..."
Teambox.unwatch_conversation(ARGV[0], conversation['id'])
print "Done\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment