Skip to content

Commit

Permalink
added some tests; removed relative_created_at and replaced with creat…
Browse files Browse the repository at this point in the history
…ed at; getting ready to release 0.1

git-svn-id: http://svn.addictedtonew.com/public/gems/twitter@40 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information
jnunemaker committed Mar 31, 2007
1 parent c0f4a48 commit ff1ae65
Show file tree
Hide file tree
Showing 85 changed files with 146 additions and 10,871 deletions.
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
#p.spec_extras - A hash of extra values to set in the gemspec.
end



desc "Package and Install Gem"
task :package_and_install do
`rake package`
`sudo gem install pkg/#{NAME}-#{VERS}.gem`
desc 'Publish HTML to RubyForge'
task :publish_html do
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
host = "#{config["username"]}@rubyforge.org"
remote_dir = "/var/www/gforge-projects/snitch/"
local_dir = 'html'
sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
`rake publish_docs`
end
3 changes: 2 additions & 1 deletion examples/twitter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require '../lib/twitter'
require 'rubygems'
require 'twitter'

puts "Public Timeline", "=" * 50
Twitter::Base.new('emailaddress', 'password').timeline(:public).each do |s|
Expand Down
83 changes: 29 additions & 54 deletions lib/twitter/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ 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!
command = ARGV.shift
Expand Down Expand Up @@ -51,12 +50,8 @@ def post

post = ARGV.shift

begin
status = Twitter::Base.new(config['email'], config['password']).post(post)
puts "\nGot it! New twitter created at: #{status.created_at}\n"
rescue
puts "\nTwitter what?. Something went wrong and your status could not be updated.\n"
end
status = Twitter::Base.new(config['email'], config['password']).post(post)
puts "\nGot it! New twitter created at: #{status.created_at}\n"
end

# Shows status, time and user for the specified timeline
Expand All @@ -66,28 +61,20 @@ def timeline
timeline = :friends
timeline = ARGV.shift.intern if ARGV.size > 0 && Twitter::Base.timelines.include?(ARGV[0].intern)

begin
puts
Twitter::Base.new(config['email'], config['password']).timeline(timeline).each do |s|
puts "#{s.text}\n-- #{s.relative_created_at} by #{s.user.name}"
puts
end
rescue
puts @@error_msg
puts
Twitter::Base.new(config['email'], config['password']).timeline(timeline).each do |s|
puts "#{s.text}\n-- #{s.created_at} by #{s.user.name}"
end
puts
end

def friends
config = create_or_find_config

begin
puts
Twitter::Base.new(config['email'], config['password']).friends.each do |u|
puts "#{u.name} (#{u.screen_name}) last updated #{u.status.created_at}\n-- #{u.status.text}"
puts
Twitter::Base.new(config['email'], config['password']).friends.each do |u|
puts "#{u.name} (#{u.screen_name}) last updated #{u.status.relative_created_at}\n-- #{u.status.text}"
puts
end
rescue
puts @@error_msg
end
end

Expand All @@ -103,23 +90,17 @@ def friend

screen_name = ARGV.shift

begin
puts
found = false
Twitter::Base.new(config['email'], config['password']).friends.each do |u|
if u.screen_name == screen_name
puts "#{u.name} last updated #{u.status.relative_created_at}\n-- #{u.status.text}"
found = true
end
end

unless found
puts "Sorry couldn't find a friend of yours with #{screen_name} as a screen name"
puts
found = false
Twitter::Base.new(config['email'], config['password']).friends.each do |u|
if u.screen_name == screen_name
puts "#{u.name} last updated #{u.status.created_at}\n-- #{u.status.text}"
found = true
end
puts
rescue
puts @@error_msg
end

puts "Sorry couldn't find a friend of yours with #{screen_name} as a screen name" unless found
puts
end

# Shows all followers and their last updated status
Expand All @@ -129,7 +110,7 @@ def followers
begin
puts
Twitter::Base.new(config['email'], config['password']).followers.each do |u|
puts "#{u.name} last updated #{u.status.relative_created_at}\n-- #{u.status.text}"
puts "#{u.name} last updated #{u.status.created_at}\n-- #{u.status.text}"
puts
end
rescue
Expand All @@ -149,23 +130,17 @@ def follower

screen_name = ARGV.shift

begin
puts
found = false
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
end
end

unless found
puts "Sorry couldn't find a follower of yours with #{screen_name} as a screen name"
puts
found = false
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.created_at}\n-- #{u.status.text}"
found = true
end
puts
rescue
puts @@error_msg
end

puts "Sorry couldn't find a follower of yours with #{screen_name} as a screen name" unless found
puts
end

private
Expand Down
25 changes: 6 additions & 19 deletions lib/twitter/status.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
# The attributes are created_at, id, text, relative_created_at, and user (which is a user object)
# new_from_xml expects xml along the lines of:
# <status>
# <id>1</id>
# <created_at>a date</created_at>
# <text>some text</text>
# <relative_created_at>about 1 min ago</relative_created_at>
# <user>
# <id>1</id>
# <name>John Nunemaker</name>
# <screen_name>jnunemaker</screen_name>
# </user>
# </status>
module Twitter
class Status
include EasyClassMaker

attributes :created_at, :id, :text, :relative_created_at, :user
attributes :created_at, :id, :text, :user

class << self
# Creates a new status from a piece of xml
def new_from_xml(xml)
Status.new do |s|
s.id = (xml).at('id').innerHTML
s.created_at = (xml).at('created_at').innerHTML
s.text = (xml).at('text').innerHTML
s.relative_created_at = (xml).at('relative_created_at').innerHTML
s.user = User.new_from_xml(xml) if (xml).at('user')
s.id = (xml).at('id').innerHTML
s.created_at = (xml).at('created_at').innerHTML
s.text = (xml).at('text').innerHTML
s.created_at = (xml).at('created_at').innerHTML
s.user = User.new_from_xml(xml) if (xml).at('user')
end
end
end
Expand Down
17 changes: 0 additions & 17 deletions lib/twitter/user.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# The attributes for user are id, name, screen_name, status (which is a status object)
# new_from_xml expects xml along the lines of:
# <user>
# <id>12796</id>
# <name>William H Harle Jr.</name>
# <screen_name>wharle</screen_name>
# <location>South Bend, IN</location>
# <description></description>
# <profile_image_url>http://twitter.com/system/user/profile_image/12796/normal/Photo_248.jpg</profile_image_url>
# <url>http://90percentgravity.com</url>
# <status>
# <created_at>Sat Jan 20 14:02:33 +0000 2007</created_at>
# <id>3450573</id>
# <text>proud of the weekend workout, day 4 of power 90 done</text>
# <relative_created_at>about 15 hours ago</relative_created_at>
# </status>
# </user>
module Twitter
class User
include EasyClassMaker
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 0
TINY = 5
MINOR = 1
TINY = 0

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
Binary file removed pkg/twitter-0.0.1.gem
Binary file not shown.
Binary file removed pkg/twitter-0.0.1.tgz
Binary file not shown.
5 changes: 0 additions & 5 deletions pkg/twitter-0.0.1/CHANGELOG

This file was deleted.

12 changes: 0 additions & 12 deletions pkg/twitter-0.0.1/Manifest.txt

This file was deleted.

46 changes: 0 additions & 46 deletions pkg/twitter-0.0.1/README

This file was deleted.

57 changes: 0 additions & 57 deletions pkg/twitter-0.0.1/Rakefile

This file was deleted.

35 changes: 0 additions & 35 deletions pkg/twitter-0.0.1/bin/twitter

This file was deleted.

Loading

0 comments on commit ff1ae65

Please sign in to comment.