Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: sferik/twitter
...
head fork: context/twitter
compare: master
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
1  Manifest.txt
View
@@ -24,6 +24,7 @@ setup.rb
tasks/deployment.rake
tasks/environment.rake
tasks/website.rake
+test/remote.rb
test/test_helper.rb
test/unit/base_test.rb
test/unit/direct_message_test.rb
6 Rakefile
View
@@ -1,4 +1,10 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration
+Hoe.new "twitter", "0.2.6" do |p|
+ p.author = "John Nunemaker"
+ p.email = 'jnunemaker@whatevs.com'
+ p.test_globs << "test/**/*_test.rb"
+end
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
29 lib/twitter/base.rb
View
@@ -34,15 +34,21 @@ def timeline(which=:friends, since=nil)
end
# Returns an array of users who are in your friends list
- def friends(lite = false)
- users(call(:friends, {:args => {:lite => lite}}))
+ def friends(options_or_lite = false)
+ unless options_or_lite.is_a?(Hash)
+ options_or_lite = {:lite => options_or_lite}
+ end
+ users(call(:friends, {:args => options_or_lite}))
end
# Returns an array of users who are friends for the id or username passed in
- def friends_for(id, lite = false)
- users(call(:friends, {:args => {:id => id, :lite => lite}}))
+ def friends_for(id, options_or_lite = false)
+ unless options_or_lite.is_a?(Hash)
+ options_or_lite = {:lite => options_or_lite}
+ end
+ friends options_or_lite.merge(:id => id)
end
-
+
# Returns an array of users who are following you
def followers(lite = false)
users(call(:followers, {:args => {:lite => lite}}))
@@ -126,7 +132,12 @@ def follow(id_or_screenname)
def leave(id_or_screenname)
users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
end
-
+
+ def verify_credentials
+ request("account/verify_credentials", :auth => true)
+ true
+ end
+
# Updates your twitter with whatever status string is passed in
def post(status)
url = URI.parse("http://#{@@api_url}/statuses/update.xml")
@@ -159,7 +170,7 @@ def call(method, options={})
# Following line needed as lite=false doens't work in the API: http://tinyurl.com/yo3h5d
options[:args].delete(:lite) unless options[:args][:lite]
path = "statuses/#{method.to_s}.xml"
- path += '?' + options[:args].inject('') { |qs, h| qs += "#{h[0]}=#{h[1]}&"; qs } unless options[:args].blank?
+ path += '?' + options[:args].inject([]) { |qs, h| qs << "#{h[0]}=#{h[1]}" }.join("&") unless options[:args].blank?
request(path, options)
end
@@ -179,8 +190,8 @@ def request(path, options={})
raise BadResponse unless response.message == 'OK' || response.message == 'Not Modified'
parse(response.body)
- rescue
- raise CantConnect
+ rescue => error
+ raise CantConnect, error.message
end
end
96 test/remote.rb
View
@@ -0,0 +1,96 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class RemoteTest < Test::Unit::TestCase
+ def setup
+ # note to self use webgroup
+ @t = Twitter::Base.new(CONFIG['email'], CONFIG['password'])
+ end
+
+ test 'should verify credentials' do
+ assert_equal true, @t.verify_credentials
+ end
+
+ test 'should have friend and public class level timelines' do
+ assert_equal 3, Twitter::Base.timelines.size
+ end
+
+ test 'should be able to get public timeline' do
+ puts 'Public Timeline', @t.timeline(:public), "*"*50
+ end
+
+ test 'should be able to get friends timeline' do
+ puts 'Friends Timeline', @t.timeline(:friends), "*"*50
+ end
+
+ test 'should be able to get user timeline' do
+ puts 'User Timeline', @t.timeline(:user), "*"*50
+ end
+
+ test 'should be able to get friends for auth user' do
+ puts 'Friends', @t.friends, "*"*50
+ end
+
+ test 'should be able to get featured users' do
+ puts 'Featured', @t.featured, "*"*50
+ end
+
+ test 'should be able to get friends for another user' do
+ puts 'Friends For', @t.friends_for('jnunemaker'), "*"*50
+ end
+
+ test 'should be able to get followers for auth user' do
+ puts 'Followers', @t.followers, "*"*50
+ end
+
+ test 'should be able to get direct messages for auth user' do
+ puts 'Direct Messages', @t.direct_messages, "*"*50
+ end
+
+ test 'should be able to get direct messages for auth user by alias received messages' do
+ puts 'Received Messages', @t.received_messages, "*"*50
+ end
+
+ test 'should be able to send a direct message' do
+ @t.d('jnunemaker', 'just testing')
+ end
+
+ test 'should be able to get sent messages for auth user' do
+ puts 'Sent Messages', @t.sent_messages, "*"*50
+ end
+
+ test 'should be able to get a status by id' do
+ puts "Status 185005122", @t.status(185005122).inspect, "*"*50
+ end
+
+ test 'should be able to get replies for auth user' do
+ puts "Replies", @t.replies, "*"*50
+ end
+
+ test "should be able to get a user's info" do
+ puts "User", @t.user('jnunemaker').inspect, "*"*50
+ end
+
+ test 'should be able to create and destroy friendships' do
+ puts "Destroying Friendship", @t.destroy_friendship('jnunemaker'), "*"*50
+ puts "Creating Friendship", @t.create_friendship('jnunemaker'), "*"*50
+ end
+
+ test 'should be able to follow a user' do
+ puts "Following a user", @t.follow('jnunemaker'), "*"*50
+ end
+
+ test 'should be able to leave a user' do
+ puts "Leaving a user", @t.leave('jnunemaker'), "*"*50
+ end
+
+
+ test 'should be able to destroy a status' do
+ # this has to be checked individually, create a status, put the id in and make sure it was deleted
+ #@t.destroy(185855442)
+ end
+
+ test 'should be able to destroy a direct message' do
+ # must be tested individually
+ @t.destroy_direct_message(4687032)
+ end
+end
6 test/test_helper.rb
View
@@ -1,7 +1,9 @@
require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/twitter'
+require 'rubygems'
require 'mocha'
require 'stubba'
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
+require 'twitter'
class << Test::Unit::TestCase
def test(name, &block)
@@ -18,4 +20,4 @@ def expect(expected_value, &block)
end
# load config
-CONFIG = YAML::load(open('/Users/nunemaker/.twitter'))
+CONFIG = YAML::load(open("#{ENV['HOME']}/.twitter"))
107 test/unit/base_test.rb
View
@@ -2,91 +2,36 @@
class BaseTest < Test::Unit::TestCase
def setup
- # note to self use webgroup
- @t = Twitter::Base.new(CONFIG['email'], CONFIG['password'])
+ @t = Twitter::Base.new('email', 'password')
end
-
- test 'should have friend and public class level timelines' do
- assert_equal 3, Twitter::Base.timelines.size
- end
-
- test 'should be able to get public timeline' do
- puts 'Public Timeline', @t.timeline(:public), "*"*50
- end
-
- test 'should be able to get friends timeline' do
- puts 'Friends Timeline', @t.timeline(:friends), "*"*50
- end
-
- test 'should be able to get user timeline' do
- puts 'User Timeline', @t.timeline(:user), "*"*50
- end
-
- test 'should be able to get friends for auth user' do
- puts 'Friends', @t.friends, "*"*50
- end
-
- test 'should be able to get featured users' do
- puts 'Featured', @t.featured, "*"*50
- end
-
- test 'should be able to get friends for another user' do
- puts 'Friends For', @t.friends_for('jnunemaker'), "*"*50
- end
-
- test 'should be able to get followers for auth user' do
- puts 'Followers', @t.followers, "*"*50
- end
-
- test 'should be able to get direct messages for auth user' do
- puts 'Direct Messages', @t.direct_messages, "*"*50
- end
-
- test 'should be able to get direct messages for auth user by alias received messages' do
- puts 'Recieved Messages', @t.received_messages, "*"*50
- end
-
- test 'should be able to send a direct message' do
- @t.d('jnunemaker', 'just testing')
- end
-
- test 'should be able to get sent messages for auth user' do
- puts 'Sent Messages', @t.sent_messages, "*"*50
- end
-
- test 'should be able to get a status by id' do
- puts "Status 185005122", @t.status(185005122).inspect, "*"*50
- end
-
- test 'should be able to get replies for auth user' do
- puts "Replies", @t.replies, "*"*50
- end
-
- test "should be able to get a user's info" do
- puts "User", @t.user('jnunemaker').inspect, "*"*50
- end
-
- test 'should be able to create and destroy friendships' do
- puts "Destroying Friendship", @t.destroy_friendship('jnunemaker'), "*"*50
- puts "Creating Friendship", @t.create_friendship('jnunemaker'), "*"*50
+
+ test 'default friends method generates request' do
+ @t.expects(:request).with('statuses/friends.xml', {:auth => true, :args => {}})
+ @t.expects(:users)
+ @t.friends
end
-
- test 'should be able to follow a user' do
- puts "Following a user", @t.follow('jnunemaker'), "*"*50
+
+ test 'friends method with lite value generates request' do
+ @t.expects(:request).with('statuses/friends.xml?lite=true', {:auth => true, :args => {:lite => true}})
+ @t.expects(:users)
+ @t.friends(true)
end
-
- test 'should be able to leave a user' do
- puts "Leaving a user", @t.leave('jnunemaker'), "*"*50
+
+ test 'friends method with options generates request' do
+ @t.expects(:request).with('statuses/friends.xml?lite=true', {:auth => true, :args => {:lite => true}})
+ @t.expects(:users)
+ @t.friends(:lite => true)
end
-
-
- test 'should be able to destroy a status' do
- # this has to be checked individually, create a status, put the id in and make sure it was deleted
- #@t.destroy(185855442)
+
+ test 'friends by id method generates request' do
+ @t.expects(:request).with('statuses/friends.xml?id=1', {:auth => true, :args => {:id => 1}})
+ @t.expects(:users)
+ @t.friends_for(1)
end
-
- test 'should be able to destroy a direct message' do
- # must be tested individually
- @t.destroy_direct_message(4687032)
+
+ test 'friends by id and options generates request' do
+ @t.expects(:request).with('statuses/friends.xml?id=1&lite=true', {:auth => true, :args => {:id => 1, :lite => true}})
+ @t.expects(:users)
+ @t.friends_for(1, :lite => true)
end
end
52 twitter.gemspec
View
@@ -0,0 +1,52 @@
+(in /Users/rick/p/twitter)
+Gem::Specification.new do |s|
+ s.name = %q{twitter}
+ s.version = "0.2.6"
+
+ s.specification_version = 2 if s.respond_to? :specification_version=
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["John Nunemaker"]
+ s.date = %q{2008-04-27}
+ s.default_executable = %q{twitter}
+ s.description = %q{a command line interface for twitter, also a library which wraps the twitter api}
+ s.email = %q{nunemaker@gmail.com}
+ s.executables = ["twitter"]
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
+ s.files = ["CHANGELOG", "History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/twitter.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/command.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "log/debug.log", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/remote.rb", "test/test_helper.rb", "test/unit/base_test.rb", "test/unit/direct_message_test.rb", "test/unit/status_test.rb", "test/unit/user_test.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{http://twitter.rubyforge.org}
+ s.rdoc_options = ["--main", "README.txt"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{twitter}
+ s.rubygems_version = %q{1.1.1}
+ s.summary = %q{a command line interface for twitter, also a library which wraps the twitter api}
+ s.test_files = ["test/test_helper.rb"]
+
+ s.add_dependency(%q<hpricot>, [">= 0"])
+ s.add_dependency(%q<activesupport>, [">= 0"])
+end
+Gem::Specification.new do |s|
+ s.name = %q{twitter}
+ s.version = "0.2.6"
+
+ s.specification_version = 2 if s.respond_to? :specification_version=
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["John Nunemaker"]
+ s.date = %q{2008-04-27}
+ s.default_executable = %q{twitter}
+ s.description = %q{}
+ s.email = %q{jnunemaker@whatevs.com}
+ s.executables = ["twitter"]
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
+ s.files = ["CHANGELOG", "History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/twitter.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/command.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "log/debug.log", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/remote.rb", "test/test_helper.rb", "test/unit/base_test.rb", "test/unit/direct_message_test.rb", "test/unit/status_test.rb", "test/unit/user_test.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{... a sweet little diddy that helps you twitter your life away}
+ s.rdoc_options = ["--main", "README.txt"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{twitter}
+ s.rubygems_version = %q{1.1.1}
+ s.summary = %q{}
+ s.test_files = ["test/test_helper.rb", "test/unit/base_test.rb", "test/unit/direct_message_test.rb", "test/unit/status_test.rb", "test/unit/user_test.rb"]
+end

No commit comments for this range

Something went wrong with that request. Please try again.