pjdavis-twitter 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/History.txt +106 -0
  2. data/License.txt +19 -0
  3. data/Manifest.txt +71 -0
  4. data/README.txt +84 -0
  5. data/Rakefile +4 -0
  6. data/bin/twitter +15 -0
  7. data/config/hoe.rb +74 -0
  8. data/config/requirements.rb +17 -0
  9. data/examples/blocks.rb +15 -0
  10. data/examples/direct_messages.rb +28 -0
  11. data/examples/favorites.rb +20 -0
  12. data/examples/friends_followers.rb +25 -0
  13. data/examples/friendships.rb +13 -0
  14. data/examples/identica_timeline.rb +7 -0
  15. data/examples/location.rb +8 -0
  16. data/examples/posting.rb +9 -0
  17. data/examples/replies.rb +26 -0
  18. data/examples/search.rb +17 -0
  19. data/examples/sent_messages.rb +26 -0
  20. data/examples/timeline.rb +33 -0
  21. data/examples/twitter.rb +27 -0
  22. data/examples/verify_credentials.rb +13 -0
  23. data/lib/twitter/base.rb +251 -0
  24. data/lib/twitter/cli/config.rb +9 -0
  25. data/lib/twitter/cli/helpers.rb +97 -0
  26. data/lib/twitter/cli/migrations/20080722194500_create_accounts.rb +13 -0
  27. data/lib/twitter/cli/migrations/20080722194508_create_tweets.rb +16 -0
  28. data/lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb +9 -0
  29. data/lib/twitter/cli/migrations/20080722214606_create_configurations.rb +13 -0
  30. data/lib/twitter/cli/models/account.rb +33 -0
  31. data/lib/twitter/cli/models/configuration.rb +13 -0
  32. data/lib/twitter/cli/models/tweet.rb +20 -0
  33. data/lib/twitter/cli.rb +328 -0
  34. data/lib/twitter/direct_message.rb +22 -0
  35. data/lib/twitter/easy_class_maker.rb +43 -0
  36. data/lib/twitter/rate_limit_status.rb +19 -0
  37. data/lib/twitter/search.rb +101 -0
  38. data/lib/twitter/status.rb +22 -0
  39. data/lib/twitter/user.rb +37 -0
  40. data/lib/twitter/version.rb +9 -0
  41. data/lib/twitter.rb +21 -0
  42. data/script/destroy +14 -0
  43. data/script/generate +14 -0
  44. data/script/txt2html +74 -0
  45. data/setup.rb +1585 -0
  46. data/spec/base_spec.rb +109 -0
  47. data/spec/cli/helper_spec.rb +35 -0
  48. data/spec/direct_message_spec.rb +35 -0
  49. data/spec/fixtures/followers.xml +706 -0
  50. data/spec/fixtures/friends.xml +609 -0
  51. data/spec/fixtures/friends_for.xml +584 -0
  52. data/spec/fixtures/friends_lite.xml +192 -0
  53. data/spec/fixtures/friends_timeline.xml +66 -0
  54. data/spec/fixtures/public_timeline.xml +148 -0
  55. data/spec/fixtures/rate_limit_status.xml +7 -0
  56. data/spec/fixtures/search_results.json +1 -0
  57. data/spec/fixtures/status.xml +25 -0
  58. data/spec/fixtures/user.xml +38 -0
  59. data/spec/fixtures/user_timeline.xml +465 -0
  60. data/spec/search_spec.rb +101 -0
  61. data/spec/spec.opts +1 -0
  62. data/spec/spec_helper.rb +12 -0
  63. data/spec/status_spec.rb +40 -0
  64. data/spec/user_spec.rb +42 -0
  65. data/tasks/deployment.rake +50 -0
  66. data/tasks/environment.rake +7 -0
  67. data/tasks/website.rake +17 -0
  68. data/twitter.gemspec +49 -0
  69. data/website/css/common.css +47 -0
  70. data/website/images/terminal_output.png +0 -0
  71. data/website/index.html +156 -0
  72. metadata +181 -0
data/spec/base_spec.rb ADDED
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Twitter::Base" do
4
+ before do
5
+ @base = Twitter::Base.new('foo', 'bar')
6
+ end
7
+
8
+ describe "being initialized" do
9
+ it "should require email and password" do
10
+ lambda { Twitter::Base.new }.should raise_error(ArgumentError)
11
+ end
12
+ end
13
+
14
+ describe "timelines" do
15
+ it "should bomb if given invalid timeline" do
16
+ lambda { @base.timeline(:fakeyoutey) }.should raise_error(Twitter::UnknownTimeline)
17
+ end
18
+
19
+ it "should default to friends timeline"
20
+
21
+ it "should be able to retrieve friends timeline" do
22
+ data = open(File.dirname(__FILE__) + '/fixtures/friends_timeline.xml').read
23
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
24
+ @base.timeline(:friends).size.should == 3
25
+ end
26
+
27
+ it "should be able to retrieve public timeline" do
28
+ data = open(File.dirname(__FILE__) + '/fixtures/public_timeline.xml').read
29
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
30
+ @base.timeline(:public).size.should == 6
31
+ end
32
+
33
+ it "should be able to retrieve user timeline" do
34
+ data = open(File.dirname(__FILE__) + '/fixtures/user_timeline.xml').read
35
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
36
+ @base.timeline(:user).size.should == 19
37
+ end
38
+ end
39
+
40
+ describe "friends and followers" do
41
+ it "should be able to get friends" do
42
+ data = open(File.dirname(__FILE__) + '/fixtures/friends.xml').read
43
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
44
+ @base.friends.size.should == 25
45
+ end
46
+
47
+ it "should be able to get friends without latest status" do
48
+ data = open(File.dirname(__FILE__) + '/fixtures/friends_lite.xml').read
49
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
50
+ @base.friends(:lite => true).size.should == 15
51
+ end
52
+
53
+ it "should be able to get friends for another user" do
54
+ data = open(File.dirname(__FILE__) + '/fixtures/friends_for.xml').read
55
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
56
+ timeline = @base.friends_for(20)
57
+ timeline.size.should == 24
58
+ timeline.first.name.should == 'Jack Dorsey'
59
+ end
60
+
61
+ it "should be able to get followers" do
62
+ data = open(File.dirname(__FILE__) + '/fixtures/followers.xml').read
63
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
64
+ timeline = @base.followers
65
+ timeline.size.should == 29
66
+ timeline.first.name.should == 'Blaine Cook'
67
+ end
68
+ end
69
+
70
+ it "should be able to get single status" do
71
+ data = open(File.dirname(__FILE__) + '/fixtures/status.xml').read
72
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
73
+ @base.status(803478581).created_at.should == 'Sun May 04 23:36:14 +0000 2008'
74
+ end
75
+
76
+ it "should be able to get single user" do
77
+ data = open(File.dirname(__FILE__) + '/fixtures/user.xml').read
78
+ @base.should_receive(:request).and_return(Hpricot::XML(data))
79
+ @base.user('4243').name.should == 'John Nunemaker'
80
+ end
81
+
82
+ describe "rate limit status" do
83
+ before do
84
+ @data = open(File.dirname(__FILE__) + '/fixtures/rate_limit_status.xml').read
85
+ @base.stub!(:request).and_return(Hpricot::XML(@data))
86
+ end
87
+
88
+ it "should request the status" do
89
+ @base.should_receive(:request).and_return(Hpricot::XML(@data))
90
+ @base.rate_limit_status
91
+ end
92
+
93
+ it "should have an hourly limit" do
94
+ @base.rate_limit_status.hourly_limit.should == 20
95
+ end
96
+
97
+ it "should have a reset time in seconds" do
98
+ @base.rate_limit_status.reset_time_in_seconds.should == 1214757610
99
+ end
100
+
101
+ it "should have a reset time" do
102
+ @base.rate_limit_status.reset_time.should == Time.parse('2008-06-29T16:40:10+00:00')
103
+ end
104
+
105
+ it "should have remaining hits" do
106
+ @base.rate_limit_status.remaining_hits.should == 5
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,35 @@
1
+ require 'ostruct'
2
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
3
+ require File.dirname(__FILE__) + '/../../lib/twitter/cli/helpers'
4
+
5
+ class Configuration; end
6
+
7
+ def say(str)
8
+ puts str
9
+ end
10
+
11
+ describe Twitter::CLI::Helpers do
12
+ include Twitter::CLI::Helpers
13
+
14
+ describe "outputting tweets" do
15
+ before do
16
+ Configuration.stub!(:[]=).and_return(true)
17
+ @collection = [
18
+ OpenStruct.new(
19
+ :text => 'This is my long message that I want to see formatted ooooh so pretty with a few words on each line so it is easy to scan.',
20
+ :created_at => Time.mktime(2008, 5, 1, 10, 15, 00).strftime('%Y-%m-%d %H:%M:%S'),
21
+ :user => OpenStruct.new(:screen_name => 'jnunemaker')
22
+ ),
23
+ OpenStruct.new(
24
+ :text => 'This is my long message that I want to see formatted ooooh so pretty with a.',
25
+ :created_at => Time.mktime(2008, 4, 1, 10, 15, 00).strftime('%Y-%m-%d %H:%M:%S'),
26
+ :user => OpenStruct.new(:screen_name => 'danielmorrison')
27
+ )
28
+ ]
29
+ end
30
+
31
+ specify "should properly format" do
32
+ output_tweets(@collection)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Twitter::DirectMessage" do
4
+ it "should create new direct message from xml doc" do
5
+ xml = <<EOF
6
+ <direct_message>
7
+ <id>331681</id>
8
+ <text>thanks for revving the twitter gem! had notice that it was broken but didn't have time to patch.</text>
9
+ <sender_id>18713</sender_id>
10
+ <recipient_id>4243</recipient_id>
11
+ <created_at>Sat Mar 10 22:10:37 +0000 2007</created_at>
12
+ <sender_screen_name>al3x</sender_screen_name>
13
+ <recipient_screen_name>jnunemaker</recipient_screen_name>
14
+ </direct_message>
15
+ EOF
16
+ d = Twitter::DirectMessage.new do |d|
17
+ d.id = '331681'
18
+ d.text = "thanks for revving the twitter gem! had notice that it was broken but didn't have time to patch."
19
+ d.sender_id = '18713'
20
+ d.recipient_id = '4243'
21
+ d.created_at = 'Sat Mar 10 22:10:37 +0000 2007'
22
+ d.sender_screen_name = 'al3x'
23
+ d.recipient_screen_name = 'jnunemaker'
24
+ end
25
+ d2 = Twitter::DirectMessage.new_from_xml(Hpricot.XML(xml))
26
+
27
+ d.id.should == d2.id
28
+ d.text.should == d2.text
29
+ d.sender_id.should == d2.sender_id
30
+ d.recipient_id.should == d2.recipient_id
31
+ d.created_at.should == d2.created_at
32
+ d.sender_screen_name.should == d2.sender_screen_name
33
+ d.recipient_screen_name.should == d2.recipient_screen_name
34
+ end
35
+ end