Skip to content

Commit

Permalink
released version 0.0.3
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.addictedtonew.com/public/gems/twitter@2 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information
jnunemaker committed Dec 17, 2006
1 parent cd7aecd commit 1763cd8
Show file tree
Hide file tree
Showing 33 changed files with 2,295 additions and 111 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
0.0.3 - added a bit more informative message when things go wrong
0.0.2 - added the command line options i forgot to add (friend and follower); improved some docs
0.0.1 - initial release
2 changes: 1 addition & 1 deletion bin/twitter
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ require 'rubygems'
require 'twitter'
require 'twitter/command'

Twitter::Command.process(ARGV)
Twitter::Command.process!
25 changes: 25 additions & 0 deletions examples/twitter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require '../lib/twitter'

puts "Public Timeline", "=" * 50
Twitter::Base.new('emailaddress', 'password').timeline(:public).each do |s|
puts s.text, s.user.name
puts
end

puts '', "Friends Timeline", "=" * 50
Twitter::Base.new('emailaddress', 'password').timeline.each do |s|
puts s.text, s.user.name
puts
end

puts '', "Friends", "=" * 50
Twitter::Base.new('emailaddress', 'password').friends.each do |u|
puts u.name, u.status.text
puts
end

puts '', "Followers", "=" * 50
Twitter::Base.new('emailaddress', 'password').followers.each do |u|
puts u.name, u.status.text
puts
end
1 change: 1 addition & 0 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# puts u.name, u.status.text
# puts
# end
%w(uri net/http yaml rubygems hpricot).each { |f| require f }

require 'twitter/version'
require 'twitter/easy_class_maker'
Expand Down
5 changes: 0 additions & 5 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# to twitter, parses the xml (using hpricot) and returns ruby objects to play with.
#
# The private methods in this one are pretty fun. Be sure to check out users, statuses and call.
require 'uri'
require 'net/http'
require 'rubygems'
require 'hpricot'

module Twitter
class Untwitterable < StandardError; end
class CantConnect < Untwitterable; end
Expand Down
55 changes: 25 additions & 30 deletions lib/twitter/command.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# The command class is used for the command line interface.
# It is only used and included in the bin/twitter file.
require 'yaml'

module Twitter
class Command
@@commands = [:post, :timeline, :friends, :friend, :followers, :follower]
Expand All @@ -17,18 +15,19 @@ class Command
email:
password:
EOF

@@error_msg = "Something went wrong!!!\n\nMost likely: The twitter gem requires hpricot version >= 0.4.59. Check to make sure that you have at least that version installed. To install the newest version of hpricot:\n\n sudo gem install hpricot --source http://code.whytheluckystiff.net"

class << self
def process(args)
command = args.shift
def process!
command = ARGV.shift

case command
when "post" then Command.post(args)
when "timeline" then Command.timeline(args)
when "post" then Command.post
when "timeline" then Command.timeline
when "friends" then Command.friends
when "friend" then Command.friend(args)
when "friend" then Command.friend
when "followers" then Command.followers
when "follower" then Command.follower(args)
when "follower" then Command.follower
else
puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
Twitter::Command.commands.each do |com|
Expand All @@ -42,15 +41,15 @@ def commands
end

# Posts an updated status to twitter
def post(args)
def post
config = create_or_find_config

if args.size == 0
if ARGV.size == 0
puts %(\n You didn't enter a message to post.\n\n Usage: twitter post "You're fabulous message"\n)
exit(0)
end

post = args.shift
post = ARGV.shift

begin
status = Twitter::Base.new(config['email'], config['password']).post(post)
Expand All @@ -61,11 +60,11 @@ def post(args)
end

# Shows status, time and user for the specified timeline
def timeline(args)
def timeline
config = create_or_find_config

timeline = :friends
timeline = args.shift.intern if args.size > 0 && Twitter::Base.timelines.include?(args[0].intern)
timeline = ARGV.shift.intern if ARGV.size > 0 && Twitter::Base.timelines.include?(ARGV[0].intern)

begin
puts
Expand All @@ -74,7 +73,7 @@ def timeline(args)
puts
end
rescue
puts error_msg
puts @@error_msg
end
end

Expand All @@ -88,21 +87,21 @@ def friends
puts
end
rescue
puts error_msg
puts @@error_msg
end
end

# Shows last updated status and time for a friend
# Needs a screen name
def friend(args)
def friend
config = create_or_find_config

if args.size == 0
if ARGV.size == 0
puts %(\n You forgot to enter a screen name.\n\n Usage: twitter friend jnunemaker\n)
exit(0)
end

screen_name = args.shift
screen_name = ARGV.shift

begin
puts
Expand All @@ -119,7 +118,7 @@ def friend(args)
end
puts
rescue
puts error_msg
puts @@error_msg
end
end

Expand All @@ -134,26 +133,26 @@ def followers
puts
end
rescue
puts error_msg
puts @@error_msg
end
end

# Shows last updated status and time for a follower
# Needs a screen name
def follower(args)
def follower
config = create_or_find_config

if args.size == 0
if ARGV.size == 0
puts %(\n You forgot to enter a screen name.\n\n Usage: twitter follower jnunemaker\n)
exit(0)
end

screen_name = args.shift
screen_name = ARGV.shift

begin
puts
found = false
Twitter::Base.new(config['email'], config['password']).follower.each do |u|
Twitter::Base.new(config['email'], config['password']).followers.each do |u|
if u.screen_name == screen_name
puts "#{u.name} (#{u.screen_name}) last updated #{u.status.relative_created_at}\n-- #{u.status.text}"
found = true
Expand All @@ -165,7 +164,7 @@ def follower(args)
end
puts
rescue
puts error_msg
puts @@error_msg
end
end

Expand All @@ -186,10 +185,6 @@ def create_or_find_config

config
end

def error_msg
"\nTwitter what?. Something went wrong and your status could not be updated.\n"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/twitter/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 0
TINY = 2
TINY = 3

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
1 change: 1 addition & 0 deletions pkg/twitter-0.0.1/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
0.0.3 - added a bit more informative message when things go wrong
0.0.2 - added the command line options i forgot to add (friend and follower); improved some docs
0.0.1 - initial release
2 changes: 1 addition & 1 deletion pkg/twitter-0.0.1/bin/twitter
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ require 'rubygems'
require 'twitter'
require 'twitter/command'

Twitter::Command.process(ARGV)
Twitter::Command.process!
1 change: 1 addition & 0 deletions pkg/twitter-0.0.1/lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# puts u.name, u.status.text
# puts
# end
%w(uri net/http yaml rubygems hpricot).each { |f| require f }

require 'twitter/version'
require 'twitter/easy_class_maker'
Expand Down
5 changes: 0 additions & 5 deletions pkg/twitter-0.0.1/lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# to twitter, parses the xml (using hpricot) and returns ruby objects to play with.
#
# The private methods in this one are pretty fun. Be sure to check out users, statuses and call.
require 'uri'
require 'net/http'
require 'rubygems'
require 'hpricot'

module Twitter
class Untwitterable < StandardError; end
class CantConnect < Untwitterable; end
Expand Down
Loading

0 comments on commit 1763cd8

Please sign in to comment.