Skip to content

Commit

Permalink
added 0.0.4 release
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.addictedtonew.com/public/gems/twitter@24 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information
jnunemaker committed Jan 21, 2007
1 parent 551b448 commit e6737ec
Show file tree
Hide file tree
Showing 20 changed files with 2,198 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/twitter-0.0.1/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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
2 changes: 1 addition & 1 deletion pkg/twitter-0.0.1/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 = 3
TINY = 4

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
1 change: 1 addition & 0 deletions pkg/twitter-0.0.2/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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
2 changes: 1 addition & 1 deletion pkg/twitter-0.0.2/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 = 3
TINY = 4

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
1 change: 1 addition & 0 deletions pkg/twitter-0.0.3/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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
2 changes: 1 addition & 1 deletion pkg/twitter-0.0.3/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 = 3
TINY = 4

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
Binary file added pkg/twitter-0.0.4.gem
Binary file not shown.
Binary file added pkg/twitter-0.0.4.tgz
Binary file not shown.
4 changes: 4 additions & 0 deletions pkg/twitter-0.0.4/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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
46 changes: 46 additions & 0 deletions pkg/twitter-0.0.4/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
57 changes: 57 additions & 0 deletions pkg/twitter-0.0.4/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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
35 changes: 35 additions & 0 deletions pkg/twitter-0.0.4/bin/twitter
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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!
46 changes: 46 additions & 0 deletions pkg/twitter-0.0.4/lib/twitter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# = addicted to twitter
#
# ... a sweet little diddy that helps you twitter your life away
#
#
# == Install
#
# $ sudo gem install 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
%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'
104 changes: 104 additions & 0 deletions pkg/twitter-0.0.4/lib/twitter/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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})

res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
Status.new_from_xml(Hpricot.parse(res.body).at('status'))
end
alias :update :post

private
# Converts xml to an array of statuses
def statuses(res)
statuses = []
doc = Hpricot.parse(res)
(doc/:status).each do |status|
statuses << Status.new_from_xml(status)
end
statuses
end

# Converts xml to an array of users
def users(res)
users = []
doc = Hpricot.parse(res)
(doc/:user).each do |user|
users << User.new_from_xml(user)
end
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'
response.body
rescue
raise CantConnect
end
end
end
end
Loading

0 comments on commit e6737ec

Please sign in to comment.