Skip to content

Instantly share code, notes, and snippets.

@cakebaker
Created March 1, 2009 15:48
Show Gist options
  • Save cakebaker/72358 to your computer and use it in GitHub Desktop.
Save cakebaker/72358 to your computer and use it in GitHub Desktop.
A simple Ruby script to follow/unfollow twitter users from the command line
#
# fou (follow or unfollow) is a simple script which allows you to
# follow/unfollow twitter users from the command line.
#
# Copyright (c) by Daniel Hofstetter (http://cakebaker.42dh.com)
#
# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php
# Redistributions of files must retain the above copyright notice.
#
require 'net/http'
require 'base64'
username = 'your_twitter_username'
password = 'your_twitter_password'
host = 'twitter.com'
create_path = '/friendships/create/'
destroy_path = '/friendships/destroy/'
def show_usage
puts 'Usage:'
puts ' ruby fou.rb follow <username> Follow the specified user'
puts ' ruby fou.rb unfollow <username> Unfollow the specified user'
end
unless ARGV.count == 2
show_usage
exit
end
path = ARGV[0] == 'follow' ? create_path : destroy_path
path += ARGV[1] + '.xml'
auth = 'Basic ' + Base64.encode64("#{username}:#{password}").delete("\n")
Net::HTTP.start(host) do |http|
response = http.post(path, '', {'Authorization' => auth})
puts response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment