Skip to content
Browse files

added some tests; removed relative_created_at and replaced with creat…

…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...
1 parent c0f4a48 commit ff1ae65766109c75f80c4b15797e12a69d7c29ad jnunemaker committed
Showing with 146 additions and 10,871 deletions.
  1. +8 −6 Rakefile
  2. +2 −1 examples/twitter.rb
  3. +29 −54 lib/twitter/command.rb
  4. +6 −19 lib/twitter/status.rb
  5. +0 −17 lib/twitter/user.rb
  6. +2 −2 lib/twitter/version.rb
  7. BIN pkg/twitter-0.0.1.gem
  8. BIN pkg/twitter-0.0.1.tgz
  9. +0 −5 pkg/twitter-0.0.1/CHANGELOG
  10. +0 −12 pkg/twitter-0.0.1/Manifest.txt
  11. +0 −46 pkg/twitter-0.0.1/README
  12. +0 −57 pkg/twitter-0.0.1/Rakefile
  13. +0 −35 pkg/twitter-0.0.1/bin/twitter
  14. +0 −7 pkg/twitter-0.0.1/lib/twitter.rb
  15. +0 −93 pkg/twitter-0.0.1/lib/twitter/base.rb
  16. +0 −190 pkg/twitter-0.0.1/lib/twitter/command.rb
  17. +0 −43 pkg/twitter-0.0.1/lib/twitter/easy_class_maker.rb
  18. +0 −33 pkg/twitter-0.0.1/lib/twitter/status.rb
  19. +0 −32 pkg/twitter-0.0.1/lib/twitter/user.rb
  20. +0 −9 pkg/twitter-0.0.1/lib/twitter/version.rb
  21. +0 −1,585 pkg/twitter-0.0.1/setup.rb
  22. BIN pkg/twitter-0.0.2.gem
  23. BIN pkg/twitter-0.0.2.tgz
  24. +0 −5 pkg/twitter-0.0.2/CHANGELOG
  25. +0 −46 pkg/twitter-0.0.2/README
  26. +0 −57 pkg/twitter-0.0.2/Rakefile
  27. +0 −35 pkg/twitter-0.0.2/bin/twitter
  28. +0 −7 pkg/twitter-0.0.2/lib/twitter.rb
  29. +0 −93 pkg/twitter-0.0.2/lib/twitter/base.rb
  30. +0 −190 pkg/twitter-0.0.2/lib/twitter/command.rb
  31. +0 −43 pkg/twitter-0.0.2/lib/twitter/easy_class_maker.rb
  32. +0 −33 pkg/twitter-0.0.2/lib/twitter/status.rb
  33. +0 −32 pkg/twitter-0.0.2/lib/twitter/user.rb
  34. +0 −9 pkg/twitter-0.0.2/lib/twitter/version.rb
  35. +0 −1,585 pkg/twitter-0.0.2/setup.rb
  36. BIN pkg/twitter-0.0.3.gem
  37. BIN pkg/twitter-0.0.3.tgz
  38. +0 −5 pkg/twitter-0.0.3/CHANGELOG
  39. +0 −46 pkg/twitter-0.0.3/README
  40. +0 −57 pkg/twitter-0.0.3/Rakefile
  41. +0 −35 pkg/twitter-0.0.3/bin/twitter
  42. +0 −7 pkg/twitter-0.0.3/lib/twitter.rb
  43. +0 −93 pkg/twitter-0.0.3/lib/twitter/base.rb
  44. +0 −190 pkg/twitter-0.0.3/lib/twitter/command.rb
  45. +0 −43 pkg/twitter-0.0.3/lib/twitter/easy_class_maker.rb
  46. +0 −33 pkg/twitter-0.0.3/lib/twitter/status.rb
  47. +0 −32 pkg/twitter-0.0.3/lib/twitter/user.rb
  48. +0 −9 pkg/twitter-0.0.3/lib/twitter/version.rb
  49. +0 −1,585 pkg/twitter-0.0.3/setup.rb
  50. BIN pkg/twitter-0.0.4.gem
  51. BIN pkg/twitter-0.0.4.tgz
  52. +0 −5 pkg/twitter-0.0.4/CHANGELOG
  53. +0 −46 pkg/twitter-0.0.4/README
  54. +0 −57 pkg/twitter-0.0.4/Rakefile
  55. +0 −35 pkg/twitter-0.0.4/bin/twitter
  56. +0 −7 pkg/twitter-0.0.4/lib/twitter.rb
  57. +0 −93 pkg/twitter-0.0.4/lib/twitter/base.rb
  58. +0 −190 pkg/twitter-0.0.4/lib/twitter/command.rb
  59. +0 −43 pkg/twitter-0.0.4/lib/twitter/easy_class_maker.rb
  60. +0 −33 pkg/twitter-0.0.4/lib/twitter/status.rb
  61. +0 −40 pkg/twitter-0.0.4/lib/twitter/user.rb
  62. +0 −9 pkg/twitter-0.0.4/lib/twitter/version.rb
  63. +0 −1,585 pkg/twitter-0.0.4/setup.rb
  64. BIN pkg/twitter-0.0.5.gem
  65. BIN pkg/twitter-0.0.5.tgz
  66. +0 −5 pkg/twitter-0.0.5/CHANGELOG
  67. +0 −46 pkg/twitter-0.0.5/README
  68. +0 −44 pkg/twitter-0.0.5/README.txt
  69. +0 −57 pkg/twitter-0.0.5/Rakefile
  70. +0 −35 pkg/twitter-0.0.5/bin/twitter
  71. +0 −25 pkg/twitter-0.0.5/examples/twitter.rb
  72. +0 −7 pkg/twitter-0.0.5/lib/twitter.rb
  73. +0 −93 pkg/twitter-0.0.5/lib/twitter/base.rb
  74. +0 −190 pkg/twitter-0.0.5/lib/twitter/command.rb
  75. +0 −43 pkg/twitter-0.0.5/lib/twitter/easy_class_maker.rb
  76. +0 −33 pkg/twitter-0.0.5/lib/twitter/status.rb
  77. +0 −40 pkg/twitter-0.0.5/lib/twitter/user.rb
  78. +0 −9 pkg/twitter-0.0.5/lib/twitter/version.rb
  79. +0 −1,585 pkg/twitter-0.0.5/setup.rb
  80. +20 −0 test/test_helper.rb
  81. +12 −0 test/unit/base.rb
  82. 0 test/unit/command.rb
  83. 0 test/unit/easy_class_maker.rb
  84. +27 −0 test/unit/status.rb
  85. +40 −0 test/unit/user.rb
View
14 Rakefile
@@ -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
View
3 examples/twitter.rb
@@ -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|
View
83 lib/twitter/command.rb
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
View
25 lib/twitter/status.rb
@@ -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
View
17 lib/twitter/user.rb
@@ -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
View
4 lib/twitter/version.rb
@@ -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
View
BIN pkg/twitter-0.0.1.gem
Binary file not shown.
View
BIN pkg/twitter-0.0.1.tgz
Binary file not shown.
View
5 pkg/twitter-0.0.1/CHANGELOG
@@ -1,5 +0,0 @@
-0.0.5 - just a bit of code cleanup
-0.0.4 - added :location, :description, :url, :profile_image_url to user class (Alex Payne)
-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
View
12 pkg/twitter-0.0.1/Manifest.txt
@@ -1,12 +0,0 @@
-README
-CHANGELOG
-Rakefile
-setup.rb
-bin/twitter
-lib/twitter.rb
-lib/twitter/base.rb
-lib/twitter/command.rb
-lib/twitter/easy_class_maker.rb
-lib/twitter/status.rb
-lib/twitter/user.rb
-lib/twitter/version.rb
View
46 pkg/twitter-0.0.1/README
@@ -1,46 +0,0 @@
-addicted to twitter
-==================
-
-... a sweet little diddy that helps you twitter your life away
-
-
-== Command Line Use
-
-$ twitter
-
-That will show the commands and each command will either run or show you the options it needs to run
-
-$ twitter post "releasing my new twitter gem"
-
-That will post a status update to your twitter
-
-== Examples
-
- Twitter::Base.new('your email', 'your password').update('watching veronica mars')
-
- # or you can use post
- Twitter::Base.new('your email', 'your password').post('post works too')
-
- puts "Public Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline(:public).each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline.each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends", "=" * 50
- Twitter::Base.new('your email', 'your password').friends.each do |u|
- puts u.name, u.status.text
- puts
- end
-
- puts '', "Followers", "=" * 50
- Twitter::Base.new('your email', 'your password').followers.each do |u|
- puts u.name, u.status.text
- puts
- end
View
57 pkg/twitter-0.0.1/Rakefile
@@ -1,57 +0,0 @@
-require 'rubygems'
-require 'rake'
-require 'rake/clean'
-require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/contrib/rubyforgepublisher'
-require 'fileutils'
-require 'hoe'
-include FileUtils
-require File.join(File.dirname(__FILE__), 'lib', 'twitter', 'version')
-
-AUTHOR = "John Nunemaker" # can also be an array of Authors
-EMAIL = "nunemaker@gmail.com"
-DESCRIPTION = "a command line interface for twitter, also a library which wraps the twitter api"
-GEM_NAME = "twitter" # what ppl will type to install your gem
-RUBYFORGE_PROJECT = "twitter" # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
-
-
-NAME = "twitter"
-REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
-VERS = ENV['VERSION'] || (Twitter::VERSION::STRING + (REV ? ".#{REV}" : ""))
-CLEAN.include ['**/.*.sw?', '*.gem', '.config']
-RDOC_OPTS = ['--quiet', '--title', "twitter documentation",
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.author = AUTHOR
- p.description = DESCRIPTION
- p.email = EMAIL
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/*_test.rb"]
- p.clean_globs = CLEAN #An array of file patterns to delete on clean.
-
- # == Optional
- #p.changes - A description of the release's latest changes.
- p.extra_deps = %w( hpricot )
- #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`
-end
View
35 pkg/twitter-0.0.1/bin/twitter
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-# = addicted to twitter
-#
-# ... a sweet little diddy that helps you twitter your life away from the command line
-#
-# == Install
-#
-# $ sudo gem install twitter
-#
-# == Command Line Use
-#
-# $ twitter
-#
-# Usage: twitter <command> [options]
-#
-# Available Commands:
-# - post
-# - timeline
-# - friends
-# - friend
-# - followers
-# - follower
-#
-# That will show the commands and each command will either run or show you the options it needs to run
-#
-# $ twitter post "releasing my new twitter gem"
-#
-# Got it! New twitter created at: Mon Nov 27 00:22:27 UTC 2006
-#
-# That will post a status update to your twitter
-require 'rubygems'
-require 'twitter'
-require 'twitter/command'
-
-Twitter::Command.process!
View
7 pkg/twitter-0.0.1/lib/twitter.rb
@@ -1,7 +0,0 @@
-%w(uri net/http yaml rubygems hpricot).each { |f| require f }
-
-require 'twitter/version'
-require 'twitter/easy_class_maker'
-require 'twitter/base'
-require 'twitter/user'
-require 'twitter/status'
View
93 pkg/twitter-0.0.1/lib/twitter/base.rb
@@ -1,93 +0,0 @@
-# This is the base class for the twitter library. It makes all the requests
-# 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.
-module Twitter
- class Untwitterable < StandardError; end
- class CantConnect < Untwitterable; end
- class BadResponse < Untwitterable; end
- class UnknownTimeline < ArgumentError; end
-
- class Base
-
- # Twitter's url, duh!
- @@api_url = 'twitter.com'
-
- # Timelines exposed by the twitter api
- @@timelines = [:friends, :public]
-
- def self.timelines
- @@timelines
- end
-
- # Initializes the configuration for making requests to twitter
- def initialize(email, password)
- @config, @config[:email], @config[:password] = {}, email, password
- end
-
- # Returns an array of statuses for a timeline;
- # Available timelines are determined from the @@timelines variable
- # Defaults to your friends timeline
- def timeline(which=:friends)
- raise UnknownTimeline unless @@timelines.include?(which)
- auth = which.to_s.include?('public') ? false : true
- statuses(call("#{which}_timeline", :auth => auth))
- end
-
- # Returns an array of users who are in your friends list
- def friends
- users(call(:friends))
- end
-
- # Returns an array of users who are following you
- def followers
- users(call(:followers))
- end
-
- # Updates your twitter with whatever status string is passed in
- def post(status)
- url = URI.parse("http://#{@@api_url}/statuses/update.xml")
- req = Net::HTTP::Post.new(url.path)
-
- req.basic_auth(@config[:email], @config[:password])
- req.set_form_data({'status' => status})
-
- result = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
- Status.new_from_xml(Hpricot.XML(result.body).at('status'))
- end
- alias :update :post
-
- private
- # Converts xml to an array of statuses
- def statuses(doc)
- (doc/:status).inject([]) { |statuses, status| statuses << Status.new_from_xml(status); statuses }
- end
-
- # Converts xml to an array of users
- def users(doc)
- (doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
- end
-
- # Calls whatever api method requested
- #
- # ie: call(:public_timeline, :auth => false)
- def call(method, arg_options={})
- options = { :auth => true }.merge(arg_options)
- path = "/statuses/#{method.to_s}.xml"
- headers = { "User-Agent" => @config[:email] }
-
- begin
- response = Net::HTTP.start(@@api_url, 80) do |http|
- req = Net::HTTP::Get.new(path, headers)
- req.basic_auth(@config[:email], @config[:password]) if options[:auth]
- http.request(req)
- end
-
- raise BadResponse unless response.message == 'OK'
- Hpricot.XML(response.body)
- rescue
- raise CantConnect
- end
- end
- end
-end
View
190 pkg/twitter-0.0.1/lib/twitter/command.rb
@@ -1,190 +0,0 @@
-# The command class is used for the command line interface.
-# It is only used and included in the bin/twitter file.
-module Twitter
- class Command
- @@commands = [:post, :timeline, :friends, :friend, :followers, :follower]
-
- @@template = <<EOF
-# .twitter
-#
-# Please fill in fields like this:
-#
-# email: bla@bla.com
-# password: secret
-#
-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
-
- case command
- when "post" then Command.post
- when "timeline" then Command.timeline
- when "friends" then Command.friends
- when "friend" then Command.friend
- when "followers" then Command.followers
- when "follower" then Command.follower
- else
- puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
- Twitter::Command.commands.each do |com|
- puts " - #{com}"
- end
- end
- end
-
- def commands
- @@commands
- end
-
- # Posts an updated status to twitter
- def post
- config = create_or_find_config
-
- 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 = 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
- end
-
- # Shows status, time and user for the specified timeline
- def timeline
- config = create_or_find_config
-
- 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
- end
- 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.relative_created_at}\n-- #{u.status.text}"
- puts
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a friend
- # Needs a screen name
- def friend
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- # Shows all followers and their last updated status
- def followers
- config = create_or_find_config
-
- 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
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a follower
- # Needs a screen name
- def follower
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- private
- # Checks for the config, creates it if not found
- def create_or_find_config
- begin
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- rescue
- open(ENV["HOME"] + '/.twitter','w').write(@@template)
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- end
-
- if config['email'] == nil or config['password'] == nil
- puts "Please edit ~/.twitter to include your twitter email and password\nTextmate users: mate ~/.twitter"
- exit(0)
- end
-
- config
- end
- end
- end
-end
View
43 pkg/twitter-0.0.1/lib/twitter/easy_class_maker.rb
@@ -1,43 +0,0 @@
-# This is pretty much just a macro for creating a class that allows
-# using a block to initialize stuff and to define getters and setters
-# really quickly.
-module Twitter
- module EasyClassMaker
-
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- # creates the attributes class variable and creates each attribute's accessor methods
- def attributes(*attrs)
- @@attributes = attrs
- @@attributes.each { |a| attr_accessor a }
- end
-
- # read method for attributes class variable
- def self.attributes; @@attributes end
- end
-
- # allows for any class that includes this to use a block to initialize
- # variables instead of assigning each one seperately
- #
- # Example:
- #
- # instead of...
- #
- # s = Status.new
- # s.foo = 'thing'
- # s.bar = 'another thing'
- #
- # you can ...
- #
- # Status.new do |s|
- # s.foo = 'thing'
- # s.bar = 'another thing'
- # end
- def initialize
- yield self if block_given?
- end
- end
-end
View
33 pkg/twitter-0.0.1/lib/twitter/status.rb
@@ -1,33 +0,0 @@
-# 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
-
- 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')
- end
- end
- end
- end
-end
View
32 pkg/twitter-0.0.1/lib/twitter/user.rb
@@ -1,32 +0,0 @@
-# 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>1</id>
-# <name>John Nunemaker</name>
-# <screen_name>jnunemaker</screen_name>
-# <status>
-# <id>1</id>
-# <created_at>a date</created_at>
-# <text>some text</text>
-# <relative_created_at>about 1 min ago</relative_created_at>
-# </status>
-# </user>
-module Twitter
- class User
- include EasyClassMaker
-
- attributes :id, :name, :screen_name, :status
-
- class << self
- # Creates a new user from a piece of xml
- def new_from_xml(xml)
- User.new do |u|
- u.id = (xml).at('id').innerHTML
- u.name = (xml).at('name').innerHTML
- u.screen_name = (xml).at('screen_name').innerHTML
- u.status = Status.new_from_xml(xml) if (xml).at('status')
- end
- end
- end
- end
-end
View
9 pkg/twitter-0.0.1/lib/twitter/version.rb
@@ -1,9 +0,0 @@
-module Twitter #:nodoc:
- module VERSION #:nodoc:
- MAJOR = 0
- MINOR = 0
- TINY = 5
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end
View
1,585 pkg/twitter-0.0.1/setup.rb
0 additions, 1,585 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN pkg/twitter-0.0.2.gem
Binary file not shown.
View
BIN pkg/twitter-0.0.2.tgz
Binary file not shown.
View
5 pkg/twitter-0.0.2/CHANGELOG
@@ -1,5 +0,0 @@
-0.0.5 - just a bit of code cleanup
-0.0.4 - added :location, :description, :url, :profile_image_url to user class (Alex Payne)
-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
View
46 pkg/twitter-0.0.2/README
@@ -1,46 +0,0 @@
-addicted to twitter
-==================
-
-... a sweet little diddy that helps you twitter your life away
-
-
-== Command Line Use
-
-$ twitter
-
-That will show the commands and each command will either run or show you the options it needs to run
-
-$ twitter post "releasing my new twitter gem"
-
-That will post a status update to your twitter
-
-== Examples
-
- Twitter::Base.new('your email', 'your password').update('watching veronica mars')
-
- # or you can use post
- Twitter::Base.new('your email', 'your password').post('post works too')
-
- puts "Public Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline(:public).each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline.each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends", "=" * 50
- Twitter::Base.new('your email', 'your password').friends.each do |u|
- puts u.name, u.status.text
- puts
- end
-
- puts '', "Followers", "=" * 50
- Twitter::Base.new('your email', 'your password').followers.each do |u|
- puts u.name, u.status.text
- puts
- end
View
57 pkg/twitter-0.0.2/Rakefile
@@ -1,57 +0,0 @@
-require 'rubygems'
-require 'rake'
-require 'rake/clean'
-require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/contrib/rubyforgepublisher'
-require 'fileutils'
-require 'hoe'
-include FileUtils
-require File.join(File.dirname(__FILE__), 'lib', 'twitter', 'version')
-
-AUTHOR = "John Nunemaker" # can also be an array of Authors
-EMAIL = "nunemaker@gmail.com"
-DESCRIPTION = "a command line interface for twitter, also a library which wraps the twitter api"
-GEM_NAME = "twitter" # what ppl will type to install your gem
-RUBYFORGE_PROJECT = "twitter" # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
-
-
-NAME = "twitter"
-REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
-VERS = ENV['VERSION'] || (Twitter::VERSION::STRING + (REV ? ".#{REV}" : ""))
-CLEAN.include ['**/.*.sw?', '*.gem', '.config']
-RDOC_OPTS = ['--quiet', '--title', "twitter documentation",
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.author = AUTHOR
- p.description = DESCRIPTION
- p.email = EMAIL
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/*_test.rb"]
- p.clean_globs = CLEAN #An array of file patterns to delete on clean.
-
- # == Optional
- #p.changes - A description of the release's latest changes.
- p.extra_deps = %w( hpricot )
- #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`
-end
View
35 pkg/twitter-0.0.2/bin/twitter
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-# = addicted to twitter
-#
-# ... a sweet little diddy that helps you twitter your life away from the command line
-#
-# == Install
-#
-# $ sudo gem install twitter
-#
-# == Command Line Use
-#
-# $ twitter
-#
-# Usage: twitter <command> [options]
-#
-# Available Commands:
-# - post
-# - timeline
-# - friends
-# - friend
-# - followers
-# - follower
-#
-# That will show the commands and each command will either run or show you the options it needs to run
-#
-# $ twitter post "releasing my new twitter gem"
-#
-# Got it! New twitter created at: Mon Nov 27 00:22:27 UTC 2006
-#
-# That will post a status update to your twitter
-require 'rubygems'
-require 'twitter'
-require 'twitter/command'
-
-Twitter::Command.process!
View
7 pkg/twitter-0.0.2/lib/twitter.rb
@@ -1,7 +0,0 @@
-%w(uri net/http yaml rubygems hpricot).each { |f| require f }
-
-require 'twitter/version'
-require 'twitter/easy_class_maker'
-require 'twitter/base'
-require 'twitter/user'
-require 'twitter/status'
View
93 pkg/twitter-0.0.2/lib/twitter/base.rb
@@ -1,93 +0,0 @@
-# This is the base class for the twitter library. It makes all the requests
-# 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.
-module Twitter
- class Untwitterable < StandardError; end
- class CantConnect < Untwitterable; end
- class BadResponse < Untwitterable; end
- class UnknownTimeline < ArgumentError; end
-
- class Base
-
- # Twitter's url, duh!
- @@api_url = 'twitter.com'
-
- # Timelines exposed by the twitter api
- @@timelines = [:friends, :public]
-
- def self.timelines
- @@timelines
- end
-
- # Initializes the configuration for making requests to twitter
- def initialize(email, password)
- @config, @config[:email], @config[:password] = {}, email, password
- end
-
- # Returns an array of statuses for a timeline;
- # Available timelines are determined from the @@timelines variable
- # Defaults to your friends timeline
- def timeline(which=:friends)
- raise UnknownTimeline unless @@timelines.include?(which)
- auth = which.to_s.include?('public') ? false : true
- statuses(call("#{which}_timeline", :auth => auth))
- end
-
- # Returns an array of users who are in your friends list
- def friends
- users(call(:friends))
- end
-
- # Returns an array of users who are following you
- def followers
- users(call(:followers))
- end
-
- # Updates your twitter with whatever status string is passed in
- def post(status)
- url = URI.parse("http://#{@@api_url}/statuses/update.xml")
- req = Net::HTTP::Post.new(url.path)
-
- req.basic_auth(@config[:email], @config[:password])
- req.set_form_data({'status' => status})
-
- result = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
- Status.new_from_xml(Hpricot.XML(result.body).at('status'))
- end
- alias :update :post
-
- private
- # Converts xml to an array of statuses
- def statuses(doc)
- (doc/:status).inject([]) { |statuses, status| statuses << Status.new_from_xml(status); statuses }
- end
-
- # Converts xml to an array of users
- def users(doc)
- (doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
- end
-
- # Calls whatever api method requested
- #
- # ie: call(:public_timeline, :auth => false)
- def call(method, arg_options={})
- options = { :auth => true }.merge(arg_options)
- path = "/statuses/#{method.to_s}.xml"
- headers = { "User-Agent" => @config[:email] }
-
- begin
- response = Net::HTTP.start(@@api_url, 80) do |http|
- req = Net::HTTP::Get.new(path, headers)
- req.basic_auth(@config[:email], @config[:password]) if options[:auth]
- http.request(req)
- end
-
- raise BadResponse unless response.message == 'OK'
- Hpricot.XML(response.body)
- rescue
- raise CantConnect
- end
- end
- end
-end
View
190 pkg/twitter-0.0.2/lib/twitter/command.rb
@@ -1,190 +0,0 @@
-# The command class is used for the command line interface.
-# It is only used and included in the bin/twitter file.
-module Twitter
- class Command
- @@commands = [:post, :timeline, :friends, :friend, :followers, :follower]
-
- @@template = <<EOF
-# .twitter
-#
-# Please fill in fields like this:
-#
-# email: bla@bla.com
-# password: secret
-#
-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
-
- case command
- when "post" then Command.post
- when "timeline" then Command.timeline
- when "friends" then Command.friends
- when "friend" then Command.friend
- when "followers" then Command.followers
- when "follower" then Command.follower
- else
- puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
- Twitter::Command.commands.each do |com|
- puts " - #{com}"
- end
- end
- end
-
- def commands
- @@commands
- end
-
- # Posts an updated status to twitter
- def post
- config = create_or_find_config
-
- 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 = 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
- end
-
- # Shows status, time and user for the specified timeline
- def timeline
- config = create_or_find_config
-
- 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
- end
- 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.relative_created_at}\n-- #{u.status.text}"
- puts
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a friend
- # Needs a screen name
- def friend
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- # Shows all followers and their last updated status
- def followers
- config = create_or_find_config
-
- 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
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a follower
- # Needs a screen name
- def follower
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- private
- # Checks for the config, creates it if not found
- def create_or_find_config
- begin
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- rescue
- open(ENV["HOME"] + '/.twitter','w').write(@@template)
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- end
-
- if config['email'] == nil or config['password'] == nil
- puts "Please edit ~/.twitter to include your twitter email and password\nTextmate users: mate ~/.twitter"
- exit(0)
- end
-
- config
- end
- end
- end
-end
View
43 pkg/twitter-0.0.2/lib/twitter/easy_class_maker.rb
@@ -1,43 +0,0 @@
-# This is pretty much just a macro for creating a class that allows
-# using a block to initialize stuff and to define getters and setters
-# really quickly.
-module Twitter
- module EasyClassMaker
-
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- # creates the attributes class variable and creates each attribute's accessor methods
- def attributes(*attrs)
- @@attributes = attrs
- @@attributes.each { |a| attr_accessor a }
- end
-
- # read method for attributes class variable
- def self.attributes; @@attributes end
- end
-
- # allows for any class that includes this to use a block to initialize
- # variables instead of assigning each one seperately
- #
- # Example:
- #
- # instead of...
- #
- # s = Status.new
- # s.foo = 'thing'
- # s.bar = 'another thing'
- #
- # you can ...
- #
- # Status.new do |s|
- # s.foo = 'thing'
- # s.bar = 'another thing'
- # end
- def initialize
- yield self if block_given?
- end
- end
-end
View
33 pkg/twitter-0.0.2/lib/twitter/status.rb
@@ -1,33 +0,0 @@
-# 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
-
- 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')
- end
- end
- end
- end
-end
View
32 pkg/twitter-0.0.2/lib/twitter/user.rb
@@ -1,32 +0,0 @@
-# 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>1</id>
-# <name>John Nunemaker</name>
-# <screen_name>jnunemaker</screen_name>
-# <status>
-# <id>1</id>
-# <created_at>a date</created_at>
-# <text>some text</text>
-# <relative_created_at>about 1 min ago</relative_created_at>
-# </status>
-# </user>
-module Twitter
- class User
- include EasyClassMaker
-
- attributes :id, :name, :screen_name, :status
-
- class << self
- # Creates a new user from a piece of xml
- def new_from_xml(xml)
- User.new do |u|
- u.id = (xml).at('id').innerHTML
- u.name = (xml).at('name').innerHTML
- u.screen_name = (xml).at('screen_name').innerHTML
- u.status = Status.new_from_xml(xml) if (xml).at('status')
- end
- end
- end
- end
-end
View
9 pkg/twitter-0.0.2/lib/twitter/version.rb
@@ -1,9 +0,0 @@
-module Twitter #:nodoc:
- module VERSION #:nodoc:
- MAJOR = 0
- MINOR = 0
- TINY = 5
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end
View
1,585 pkg/twitter-0.0.2/setup.rb
0 additions, 1,585 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN pkg/twitter-0.0.3.gem
Binary file not shown.
View
BIN pkg/twitter-0.0.3.tgz
Binary file not shown.
View
5 pkg/twitter-0.0.3/CHANGELOG
@@ -1,5 +0,0 @@
-0.0.5 - just a bit of code cleanup
-0.0.4 - added :location, :description, :url, :profile_image_url to user class (Alex Payne)
-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
View
46 pkg/twitter-0.0.3/README
@@ -1,46 +0,0 @@
-addicted to twitter
-==================
-
-... a sweet little diddy that helps you twitter your life away
-
-
-== Command Line Use
-
-$ twitter
-
-That will show the commands and each command will either run or show you the options it needs to run
-
-$ twitter post "releasing my new twitter gem"
-
-That will post a status update to your twitter
-
-== Examples
-
- Twitter::Base.new('your email', 'your password').update('watching veronica mars')
-
- # or you can use post
- Twitter::Base.new('your email', 'your password').post('post works too')
-
- puts "Public Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline(:public).each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline.each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends", "=" * 50
- Twitter::Base.new('your email', 'your password').friends.each do |u|
- puts u.name, u.status.text
- puts
- end
-
- puts '', "Followers", "=" * 50
- Twitter::Base.new('your email', 'your password').followers.each do |u|
- puts u.name, u.status.text
- puts
- end
View
57 pkg/twitter-0.0.3/Rakefile
@@ -1,57 +0,0 @@
-require 'rubygems'
-require 'rake'
-require 'rake/clean'
-require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/contrib/rubyforgepublisher'
-require 'fileutils'
-require 'hoe'
-include FileUtils
-require File.join(File.dirname(__FILE__), 'lib', 'twitter', 'version')
-
-AUTHOR = "John Nunemaker" # can also be an array of Authors
-EMAIL = "nunemaker@gmail.com"
-DESCRIPTION = "a command line interface for twitter, also a library which wraps the twitter api"
-GEM_NAME = "twitter" # what ppl will type to install your gem
-RUBYFORGE_PROJECT = "twitter" # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
-
-
-NAME = "twitter"
-REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
-VERS = ENV['VERSION'] || (Twitter::VERSION::STRING + (REV ? ".#{REV}" : ""))
-CLEAN.include ['**/.*.sw?', '*.gem', '.config']
-RDOC_OPTS = ['--quiet', '--title', "twitter documentation",
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.author = AUTHOR
- p.description = DESCRIPTION
- p.email = EMAIL
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/*_test.rb"]
- p.clean_globs = CLEAN #An array of file patterns to delete on clean.
-
- # == Optional
- #p.changes - A description of the release's latest changes.
- p.extra_deps = %w( hpricot )
- #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`
-end
View
35 pkg/twitter-0.0.3/bin/twitter
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-# = addicted to twitter
-#
-# ... a sweet little diddy that helps you twitter your life away from the command line
-#
-# == Install
-#
-# $ sudo gem install twitter
-#
-# == Command Line Use
-#
-# $ twitter
-#
-# Usage: twitter <command> [options]
-#
-# Available Commands:
-# - post
-# - timeline
-# - friends
-# - friend
-# - followers
-# - follower
-#
-# That will show the commands and each command will either run or show you the options it needs to run
-#
-# $ twitter post "releasing my new twitter gem"
-#
-# Got it! New twitter created at: Mon Nov 27 00:22:27 UTC 2006
-#
-# That will post a status update to your twitter
-require 'rubygems'
-require 'twitter'
-require 'twitter/command'
-
-Twitter::Command.process!
View
7 pkg/twitter-0.0.3/lib/twitter.rb
@@ -1,7 +0,0 @@
-%w(uri net/http yaml rubygems hpricot).each { |f| require f }
-
-require 'twitter/version'
-require 'twitter/easy_class_maker'
-require 'twitter/base'
-require 'twitter/user'
-require 'twitter/status'
View
93 pkg/twitter-0.0.3/lib/twitter/base.rb
@@ -1,93 +0,0 @@
-# This is the base class for the twitter library. It makes all the requests
-# 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.
-module Twitter
- class Untwitterable < StandardError; end
- class CantConnect < Untwitterable; end
- class BadResponse < Untwitterable; end
- class UnknownTimeline < ArgumentError; end
-
- class Base
-
- # Twitter's url, duh!
- @@api_url = 'twitter.com'
-
- # Timelines exposed by the twitter api
- @@timelines = [:friends, :public]
-
- def self.timelines
- @@timelines
- end
-
- # Initializes the configuration for making requests to twitter
- def initialize(email, password)
- @config, @config[:email], @config[:password] = {}, email, password
- end
-
- # Returns an array of statuses for a timeline;
- # Available timelines are determined from the @@timelines variable
- # Defaults to your friends timeline
- def timeline(which=:friends)
- raise UnknownTimeline unless @@timelines.include?(which)
- auth = which.to_s.include?('public') ? false : true
- statuses(call("#{which}_timeline", :auth => auth))
- end
-
- # Returns an array of users who are in your friends list
- def friends
- users(call(:friends))
- end
-
- # Returns an array of users who are following you
- def followers
- users(call(:followers))
- end
-
- # Updates your twitter with whatever status string is passed in
- def post(status)
- url = URI.parse("http://#{@@api_url}/statuses/update.xml")
- req = Net::HTTP::Post.new(url.path)
-
- req.basic_auth(@config[:email], @config[:password])
- req.set_form_data({'status' => status})
-
- result = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
- Status.new_from_xml(Hpricot.XML(result.body).at('status'))
- end
- alias :update :post
-
- private
- # Converts xml to an array of statuses
- def statuses(doc)
- (doc/:status).inject([]) { |statuses, status| statuses << Status.new_from_xml(status); statuses }
- end
-
- # Converts xml to an array of users
- def users(doc)
- (doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
- end
-
- # Calls whatever api method requested
- #
- # ie: call(:public_timeline, :auth => false)
- def call(method, arg_options={})
- options = { :auth => true }.merge(arg_options)
- path = "/statuses/#{method.to_s}.xml"
- headers = { "User-Agent" => @config[:email] }
-
- begin
- response = Net::HTTP.start(@@api_url, 80) do |http|
- req = Net::HTTP::Get.new(path, headers)
- req.basic_auth(@config[:email], @config[:password]) if options[:auth]
- http.request(req)
- end
-
- raise BadResponse unless response.message == 'OK'
- Hpricot.XML(response.body)
- rescue
- raise CantConnect
- end
- end
- end
-end
View
190 pkg/twitter-0.0.3/lib/twitter/command.rb
@@ -1,190 +0,0 @@
-# The command class is used for the command line interface.
-# It is only used and included in the bin/twitter file.
-module Twitter
- class Command
- @@commands = [:post, :timeline, :friends, :friend, :followers, :follower]
-
- @@template = <<EOF
-# .twitter
-#
-# Please fill in fields like this:
-#
-# email: bla@bla.com
-# password: secret
-#
-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
-
- case command
- when "post" then Command.post
- when "timeline" then Command.timeline
- when "friends" then Command.friends
- when "friend" then Command.friend
- when "followers" then Command.followers
- when "follower" then Command.follower
- else
- puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
- Twitter::Command.commands.each do |com|
- puts " - #{com}"
- end
- end
- end
-
- def commands
- @@commands
- end
-
- # Posts an updated status to twitter
- def post
- config = create_or_find_config
-
- 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 = 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
- end
-
- # Shows status, time and user for the specified timeline
- def timeline
- config = create_or_find_config
-
- 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
- end
- 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.relative_created_at}\n-- #{u.status.text}"
- puts
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a friend
- # Needs a screen name
- def friend
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- # Shows all followers and their last updated status
- def followers
- config = create_or_find_config
-
- 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
- end
- rescue
- puts @@error_msg
- end
- end
-
- # Shows last updated status and time for a follower
- # Needs a screen name
- def follower
- config = create_or_find_config
-
- 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 = 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"
- end
- puts
- rescue
- puts @@error_msg
- end
- end
-
- private
- # Checks for the config, creates it if not found
- def create_or_find_config
- begin
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- rescue
- open(ENV["HOME"] + '/.twitter','w').write(@@template)
- config = YAML::load open(ENV['HOME'] + "/.twitter")
- end
-
- if config['email'] == nil or config['password'] == nil
- puts "Please edit ~/.twitter to include your twitter email and password\nTextmate users: mate ~/.twitter"
- exit(0)
- end
-
- config
- end
- end
- end
-end
View
43 pkg/twitter-0.0.3/lib/twitter/easy_class_maker.rb
@@ -1,43 +0,0 @@
-# This is pretty much just a macro for creating a class that allows
-# using a block to initialize stuff and to define getters and setters
-# really quickly.
-module Twitter
- module EasyClassMaker
-
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- # creates the attributes class variable and creates each attribute's accessor methods
- def attributes(*attrs)
- @@attributes = attrs
- @@attributes.each { |a| attr_accessor a }
- end
-
- # read method for attributes class variable
- def self.attributes; @@attributes end
- end
-
- # allows for any class that includes this to use a block to initialize
- # variables instead of assigning each one seperately
- #
- # Example:
- #
- # instead of...
- #
- # s = Status.new
- # s.foo = 'thing'
- # s.bar = 'another thing'
- #
- # you can ...
- #
- # Status.new do |s|
- # s.foo = 'thing'
- # s.bar = 'another thing'
- # end
- def initialize
- yield self if block_given?
- end
- end
-end
View
33 pkg/twitter-0.0.3/lib/twitter/status.rb
@@ -1,33 +0,0 @@
-# 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
-
- 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')
- end
- end
- end
- end
-end
View
32 pkg/twitter-0.0.3/lib/twitter/user.rb
@@ -1,32 +0,0 @@
-# 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>1</id>
-# <name>John Nunemaker</name>
-# <screen_name>jnunemaker</screen_name>
-# <status>
-# <id>1</id>
-# <created_at>a date</created_at>
-# <text>some text</text>
-# <relative_created_at>about 1 min ago</relative_created_at>
-# </status>
-# </user>
-module Twitter
- class User
- include EasyClassMaker
-
- attributes :id, :name, :screen_name, :status
-
- class << self
- # Creates a new user from a piece of xml
- def new_from_xml(xml)
- User.new do |u|
- u.id = (xml).at('id').innerHTML
- u.name = (xml).at('name').innerHTML
- u.screen_name = (xml).at('screen_name').innerHTML
- u.status = Status.new_from_xml(xml) if (xml).at('status')
- end
- end
- end
- end
-end
View
9 pkg/twitter-0.0.3/lib/twitter/version.rb
@@ -1,9 +0,0 @@
-module Twitter #:nodoc:
- module VERSION #:nodoc:
- MAJOR = 0
- MINOR = 0
- TINY = 5
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end
View
1,585 pkg/twitter-0.0.3/setup.rb
0 additions, 1,585 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN pkg/twitter-0.0.4.gem
Binary file not shown.
View
BIN pkg/twitter-0.0.4.tgz
Binary file not shown.
View
5 pkg/twitter-0.0.4/CHANGELOG
@@ -1,5 +0,0 @@
-0.0.5 - just a bit of code cleanup
-0.0.4 - added :location, :description, :url, :profile_image_url to user class (Alex Payne)
-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
View
46 pkg/twitter-0.0.4/README
@@ -1,46 +0,0 @@
-addicted to twitter
-==================
-
-... a sweet little diddy that helps you twitter your life away
-
-
-== Command Line Use
-
-$ twitter
-
-That will show the commands and each command will either run or show you the options it needs to run
-
-$ twitter post "releasing my new twitter gem"
-
-That will post a status update to your twitter
-
-== Examples
-
- Twitter::Base.new('your email', 'your password').update('watching veronica mars')
-
- # or you can use post
- Twitter::Base.new('your email', 'your password').post('post works too')
-
- puts "Public Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline(:public).each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends Timeline", "=" * 50
- Twitter::Base.new('your email', 'your password').timeline.each do |s|
- puts s.text, s.user.name
- puts
- end
-
- puts '', "Friends", "=" * 50
- Twitter::Base.new('your email', 'your password').friends.each do |u|
- puts u.name, u.status.text
- puts
- end
-
- puts '', "Followers", "=" * 50
- Twitter::Base.new('your email', 'your password').followers.each do |u|