rpbertp13-twitter 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History +206 -0
  2. data/License +20 -0
  3. data/Notes +33 -0
  4. data/README.rdoc +19 -0
  5. data/Rakefile +103 -0
  6. data/VERSION.yml +4 -0
  7. data/examples/connect.rb +30 -0
  8. data/examples/friendship_existance.rb +13 -0
  9. data/examples/helpers/config_store.rb +38 -0
  10. data/examples/httpauth.rb +11 -0
  11. data/examples/ids.rb +13 -0
  12. data/examples/search.rb +15 -0
  13. data/examples/timeline.rb +19 -0
  14. data/examples/unauthorized.rb +16 -0
  15. data/examples/update.rb +11 -0
  16. data/examples/user.rb +5 -0
  17. data/lib/twitter/base.rb +165 -0
  18. data/lib/twitter/httpauth.rb +27 -0
  19. data/lib/twitter/oauth.rb +41 -0
  20. data/lib/twitter/request.rb +102 -0
  21. data/lib/twitter/search.rb +106 -0
  22. data/lib/twitter/trends.rb +29 -0
  23. data/lib/twitter.rb +57 -0
  24. data/test/fixtures/firehose.json +1 -0
  25. data/test/fixtures/follower_ids.json +1 -0
  26. data/test/fixtures/friend_ids.json +1 -0
  27. data/test/fixtures/friends_timeline.json +1 -0
  28. data/test/fixtures/rate_limit_exceeded.json +1 -0
  29. data/test/fixtures/replies.json +1 -0
  30. data/test/fixtures/search.json +1 -0
  31. data/test/fixtures/search_from_jnunemaker.json +1 -0
  32. data/test/fixtures/status.json +1 -0
  33. data/test/fixtures/status_show.json +1 -0
  34. data/test/fixtures/trends_current.json +1 -0
  35. data/test/fixtures/trends_current_exclude.json +1 -0
  36. data/test/fixtures/trends_daily.json +1 -0
  37. data/test/fixtures/trends_daily_date.json +1 -0
  38. data/test/fixtures/trends_daily_exclude.json +1 -0
  39. data/test/fixtures/trends_weekly.json +1 -0
  40. data/test/fixtures/trends_weekly_date.json +1 -0
  41. data/test/fixtures/trends_weekly_exclude.json +1 -0
  42. data/test/fixtures/user.json +1 -0
  43. data/test/fixtures/user_timeline.json +1 -0
  44. data/test/test_helper.rb +36 -0
  45. data/test/twitter/base_test.rb +95 -0
  46. data/test/twitter/httpauth_test.rb +76 -0
  47. data/test/twitter/oauth_test.rb +81 -0
  48. data/test/twitter/request_test.rb +217 -0
  49. data/test/twitter/search_test.rb +144 -0
  50. data/test/twitter/trends_test.rb +95 -0
  51. data/test/twitter_test.rb +38 -0
  52. metadata +201 -0
@@ -0,0 +1,144 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class SearchTest < Test::Unit::TestCase
4
+ context "searching" do
5
+ setup do
6
+ @search = Twitter::Search.new
7
+ end
8
+
9
+ should "should be able to initialize with a search term" do
10
+ Twitter::Search.new('httparty').query[:q].should include('httparty')
11
+ end
12
+
13
+ should "should be able to specify from" do
14
+ @search.from('jnunemaker').query[:q].should include('from:jnunemaker')
15
+ end
16
+
17
+ should "should be able to specify to" do
18
+ @search.to('jnunemaker').query[:q].should include('to:jnunemaker')
19
+ end
20
+
21
+ should "should be able to specify referencing" do
22
+ @search.referencing('jnunemaker').query[:q].should include('@jnunemaker')
23
+ end
24
+
25
+ should "should alias references to referencing" do
26
+ @search.references('jnunemaker').query[:q].should include('@jnunemaker')
27
+ end
28
+
29
+ should "should alias ref to referencing" do
30
+ @search.ref('jnunemaker').query[:q].should include('@jnunemaker')
31
+ end
32
+
33
+ should "should be able to specify containing" do
34
+ @search.containing('milk').query[:q].should include('milk')
35
+ end
36
+
37
+ should "should alias contains to containing" do
38
+ @search.contains('milk').query[:q].should include('milk')
39
+ end
40
+
41
+ should "should be able to specify hashed" do
42
+ @search.hashed('twitter').query[:q].should include('#twitter')
43
+ end
44
+
45
+ should "should be able to specify the language" do
46
+ @search.lang('en')
47
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json).returns({'foo' => 'bar'})
48
+ @search.fetch()
49
+ end
50
+
51
+ should "should be able to specify the number of results per page" do
52
+ @search.per_page(25)
53
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:rpp => 25, :q => ''}, :format => :json).returns({'foo' => 'bar'})
54
+ @search.fetch()
55
+ end
56
+
57
+ should "should be able to specify the page number" do
58
+ @search.page(20)
59
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:page => 20, :q => ''}, :format => :json).returns({'foo' => 'bar'})
60
+ @search.fetch()
61
+ end
62
+
63
+ should "should be able to specify only returning results greater than an id" do
64
+ @search.since(1234)
65
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:since_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
66
+ @search.fetch()
67
+ end
68
+
69
+ should "should be able to specify geo coordinates" do
70
+ @search.geocode('40.757929', '-73.985506', '25mi')
71
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:geocode => '40.757929,-73.985506,25mi', :q => ''}, :format => :json).returns({'foo' => 'bar'})
72
+ @search.fetch()
73
+ end
74
+
75
+ should "should be able to specify max id" do
76
+ @search.max(1234)
77
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:max_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
78
+ @search.fetch()
79
+ end
80
+
81
+ should "should be able to clear the filters set" do
82
+ @search.from('jnunemaker').to('oaknd1')
83
+ @search.clear.query.should == {:q => []}
84
+ end
85
+
86
+ should "should be able to chain methods together" do
87
+ @search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
88
+ @search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', '#twitter']
89
+ @search.query[:lang].should == 'en'
90
+ @search.query[:rpp].should == 20
91
+ @search.query[:since_id].should == 1234
92
+ @search.query[:geocode].should == '40.757929,-73.985506,25mi'
93
+ end
94
+
95
+ context "fetching" do
96
+ setup do
97
+ stub_get('http://search.twitter.com:80/search.json?q=%40jnunemaker', 'search.json')
98
+ @search = Twitter::Search.new('@jnunemaker')
99
+ @response = @search.fetch
100
+ end
101
+
102
+ should "should return results" do
103
+ @response.results.size.should == 15
104
+ end
105
+
106
+ should "should support dot notation" do
107
+ first = @response.results.first
108
+ first.text.should == %q(Someone asked about a tweet reader. Easy to do in ruby with @jnunemaker's twitter gem and the win32-sapi gem, if you are on windows.)
109
+ first.from_user.should == 'PatParslow'
110
+ end
111
+
112
+ should "cache fetched results so multiple fetches don't keep hitting api" do
113
+ Twitter::Search.expects(:get).never
114
+ @search.fetch
115
+ end
116
+
117
+ should "rehit api if fetch is called with true" do
118
+ Twitter::Search.expects(:get).once
119
+ @search.fetch(true)
120
+ end
121
+ end
122
+
123
+ context "iterating over results" do
124
+ setup do
125
+ stub_get('http://search.twitter.com:80/search.json?q=from%3Ajnunemaker', 'search_from_jnunemaker.json')
126
+ @search.from('jnunemaker')
127
+ end
128
+
129
+ should "work" do
130
+ @search.each { |result| result.should_not be(nil) }
131
+ end
132
+
133
+ should "work multiple times in a row" do
134
+ @search.each { |result| result.should_not be(nil) }
135
+ @search.each { |result| result.should_not be(nil) }
136
+ end
137
+ end
138
+
139
+ should "should be able to iterate over results" do
140
+ @search.respond_to?(:each).should be(true)
141
+ end
142
+ end
143
+
144
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class TrendsTest < Test::Unit::TestCase
4
+ include Twitter
5
+
6
+ context "Getting current trends" do
7
+ should "work" do
8
+ stub_get 'http://search.twitter.com:80/trends/current.json', 'trends_current.json'
9
+ trends = Trends.current
10
+ trends.size.should == 10
11
+ trends[0].name.should == '#musicmonday'
12
+ trends[0].query.should == '#musicmonday'
13
+ trends[1].name.should == '#newdivide'
14
+ trends[1].query.should == '#newdivide'
15
+ end
16
+
17
+ should "be able to exclude hashtags" do
18
+ stub_get 'http://search.twitter.com:80/trends/current.json?exclude=hashtags', 'trends_current_exclude.json'
19
+ trends = Trends.current(:exclude => 'hashtags')
20
+ trends.size.should == 10
21
+ trends[0].name.should == 'New Divide'
22
+ trends[0].query.should == %Q(\"New Divide\")
23
+ trends[1].name.should == 'Star Trek'
24
+ trends[1].query.should == %Q(\"Star Trek\")
25
+ end
26
+ end
27
+
28
+ context "Getting daily trends" do
29
+ should "work" do
30
+ stub_get 'http://search.twitter.com:80/trends/daily.json?', 'trends_daily.json'
31
+ trends = Trends.daily
32
+ trends.size.should == 480
33
+ trends[0].name.should == '#3turnoffwords'
34
+ trends[0].query.should == '#3turnoffwords'
35
+ end
36
+
37
+ should "be able to exclude hastags" do
38
+ stub_get 'http://search.twitter.com:80/trends/daily.json?exclude=hashtags', 'trends_daily_exclude.json'
39
+ trends = Trends.daily(:exclude => 'hashtags')
40
+ trends.size.should == 480
41
+ trends[0].name.should == 'Star Trek'
42
+ trends[0].query.should == %Q(\"Star Trek\")
43
+ end
44
+
45
+ should "be able to get for specific date (with date string)" do
46
+ stub_get 'http://search.twitter.com:80/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
47
+ trends = Trends.daily(:date => '2009-05-01')
48
+ trends.size.should == 440
49
+ trends[0].name.should == 'Swine Flu'
50
+ trends[0].query.should == %Q(\"Swine Flu\")
51
+ end
52
+
53
+ should "be able to get for specific date (with date object)" do
54
+ stub_get 'http://search.twitter.com:80/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
55
+ trends = Trends.daily(:date => Date.new(2009, 5, 1))
56
+ trends.size.should == 440
57
+ trends[0].name.should == 'Swine Flu'
58
+ trends[0].query.should == %Q(\"Swine Flu\")
59
+ end
60
+ end
61
+
62
+ context "Getting weekly trends" do
63
+ should "work" do
64
+ stub_get 'http://search.twitter.com:80/trends/weekly.json?', 'trends_weekly.json'
65
+ trends = Trends.weekly
66
+ trends.size.should == 210
67
+ trends[0].name.should == 'Happy Mothers Day'
68
+ trends[0].query.should == %Q(\"Happy Mothers Day\" OR \"Mothers Day\")
69
+ end
70
+
71
+ should "be able to exclude hastags" do
72
+ stub_get 'http://search.twitter.com:80/trends/weekly.json?exclude=hashtags', 'trends_weekly_exclude.json'
73
+ trends = Trends.weekly(:exclude => 'hashtags')
74
+ trends.size.should == 210
75
+ trends[0].name.should == 'Happy Mothers Day'
76
+ trends[0].query.should == %Q(\"Happy Mothers Day\" OR \"Mothers Day\")
77
+ end
78
+
79
+ should "be able to get for specific date (with date string)" do
80
+ stub_get 'http://search.twitter.com:80/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
81
+ trends = Trends.weekly(:date => '2009-05-01')
82
+ trends.size.should == 210
83
+ trends[0].name.should == 'TGIF'
84
+ trends[0].query.should == 'TGIF'
85
+ end
86
+
87
+ should "be able to get for specific date (with date object)" do
88
+ stub_get 'http://search.twitter.com:80/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
89
+ trends = Trends.weekly(:date => Date.new(2009, 5, 1))
90
+ trends.size.should == 210
91
+ trends[0].name.should == 'TGIF'
92
+ trends[0].query.should == 'TGIF'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class TwitterTest < Test::Unit::TestCase
4
+ should "have firehose method for public timeline" do
5
+ stub_get('http://twitter.com:80/statuses/public_timeline.json', 'firehose.json')
6
+ hose = Twitter.firehose
7
+ hose.size.should == 20
8
+ first = hose.first
9
+ first.text.should == '#torrents Ultimativer Flirt Guide - In 10 Minuten jede Frau erobern: Ultimativer Flirt Guide - In 10 Mi.. http://tinyurl.com/d3okh4'
10
+ first.user.name.should == 'P2P Torrents'
11
+ end
12
+
13
+ should "have user method for unauthenticated calls to get a user's information" do
14
+ stub_get('http://twitter.com:80/users/show/jnunemaker.json', 'user.json')
15
+ user = Twitter.user('jnunemaker')
16
+ user.name.should == 'John Nunemaker'
17
+ user.description.should == 'Loves his wife, ruby, notre dame football and iu basketball'
18
+ end
19
+
20
+ should "have status method for unauthenticated calls to get a status" do
21
+ stub_get('http://twitter.com:80/statuses/show/1533815199.json', 'status_show.json')
22
+ status = Twitter.status(1533815199)
23
+ status.id.should == 1533815199
24
+ status.text.should == 'Eating some oatmeal and butterscotch cookies with a cold glass of milk for breakfast. Tasty!'
25
+ end
26
+
27
+ should "have friend_ids method" do
28
+ stub_get('http://twitter.com:80/friends/ids/jnunemaker.json', 'friend_ids.json')
29
+ ids = Twitter.friend_ids('jnunemaker')
30
+ ids.size.should == 161
31
+ end
32
+
33
+ should "have follower_ids method" do
34
+ stub_get('http://twitter.com:80/followers/ids/jnunemaker.json', 'follower_ids.json')
35
+ ids = Twitter.follower_ids('jnunemaker')
36
+ ids.size.should == 1252
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpbertp13-twitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
5
+ platform: ruby
6
+ authors:
7
+ - John Nunemaker
8
+ - Dan Williams
9
+ - Roberto Thais
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-06-18 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: oauth
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.4
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: peterpunk-mhash
29
+ type: :runtime
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.0.8
36
+ version:
37
+ - !ruby/object:Gem::Dependency
38
+ name: httparty
39
+ type: :runtime
40
+ version_requirement:
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.3
46
+ version:
47
+ - !ruby/object:Gem::Dependency
48
+ name: thoughtbot-shoulda
49
+ type: :development
50
+ version_requirement:
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ - !ruby/object:Gem::Dependency
58
+ name: jeremymcanally-matchy
59
+ type: :development
60
+ version_requirement:
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ type: :development
70
+ version_requirement:
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ - !ruby/object:Gem::Dependency
78
+ name: fakeweb
79
+ type: :development
80
+ version_requirement:
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ - !ruby/object:Gem::Dependency
88
+ name: peterpunk-mhash
89
+ type: :development
90
+ version_requirement:
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ description:
98
+ email: roberto.n.thais@gmail.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - README.rdoc
105
+ files:
106
+ - History
107
+ - License
108
+ - Notes
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION.yml
112
+ - examples/connect.rb
113
+ - examples/friendship_existance.rb
114
+ - examples/helpers/config_store.rb
115
+ - examples/httpauth.rb
116
+ - examples/ids.rb
117
+ - examples/search.rb
118
+ - examples/timeline.rb
119
+ - examples/unauthorized.rb
120
+ - examples/update.rb
121
+ - examples/user.rb
122
+ - lib/twitter.rb
123
+ - lib/twitter/base.rb
124
+ - lib/twitter/httpauth.rb
125
+ - lib/twitter/oauth.rb
126
+ - lib/twitter/request.rb
127
+ - lib/twitter/search.rb
128
+ - lib/twitter/trends.rb
129
+ - test/fixtures/firehose.json
130
+ - test/fixtures/follower_ids.json
131
+ - test/fixtures/friend_ids.json
132
+ - test/fixtures/friends_timeline.json
133
+ - test/fixtures/rate_limit_exceeded.json
134
+ - test/fixtures/replies.json
135
+ - test/fixtures/search.json
136
+ - test/fixtures/search_from_jnunemaker.json
137
+ - test/fixtures/status.json
138
+ - test/fixtures/status_show.json
139
+ - test/fixtures/trends_current.json
140
+ - test/fixtures/trends_current_exclude.json
141
+ - test/fixtures/trends_daily.json
142
+ - test/fixtures/trends_daily_date.json
143
+ - test/fixtures/trends_daily_exclude.json
144
+ - test/fixtures/trends_weekly.json
145
+ - test/fixtures/trends_weekly_date.json
146
+ - test/fixtures/trends_weekly_exclude.json
147
+ - test/fixtures/user.json
148
+ - test/fixtures/user_timeline.json
149
+ - test/test_helper.rb
150
+ - test/twitter/base_test.rb
151
+ - test/twitter/httpauth_test.rb
152
+ - test/twitter/oauth_test.rb
153
+ - test/twitter/request_test.rb
154
+ - test/twitter/search_test.rb
155
+ - test/twitter/trends_test.rb
156
+ - test/twitter_test.rb
157
+ has_rdoc: false
158
+ homepage: http://github.com/rpbertp13/twitter
159
+ post_install_message:
160
+ rdoc_options:
161
+ - --charset=UTF-8
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: "0"
169
+ version:
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: "0"
175
+ version:
176
+ requirements: []
177
+
178
+ rubyforge_project: twitter
179
+ rubygems_version: 1.2.0
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: wrapper for the twitter api (oauth only) [Remixed to use Mhash]
183
+ test_files:
184
+ - test/test_helper.rb
185
+ - test/twitter/base_test.rb
186
+ - test/twitter/httpauth_test.rb
187
+ - test/twitter/oauth_test.rb
188
+ - test/twitter/request_test.rb
189
+ - test/twitter/search_test.rb
190
+ - test/twitter/trends_test.rb
191
+ - test/twitter_test.rb
192
+ - examples/connect.rb
193
+ - examples/friendship_existance.rb
194
+ - examples/helpers/config_store.rb
195
+ - examples/httpauth.rb
196
+ - examples/ids.rb
197
+ - examples/search.rb
198
+ - examples/timeline.rb
199
+ - examples/unauthorized.rb
200
+ - examples/update.rb
201
+ - examples/user.rb