deadprogrammer-twitter 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History +186 -0
- data/License +20 -0
- data/Notes +33 -0
- data/README.rdoc +13 -0
- data/Rakefile +103 -0
- data/VERSION.yml +4 -0
- data/examples/connect.rb +30 -0
- data/examples/friendship_existance.rb +13 -0
- data/examples/helpers/config_store.rb +38 -0
- data/examples/httpauth.rb +11 -0
- data/examples/ids.rb +13 -0
- data/examples/search.rb +15 -0
- data/examples/timeline.rb +19 -0
- data/examples/unauthorized.rb +16 -0
- data/examples/update.rb +11 -0
- data/examples/user.rb +5 -0
- data/lib/twitter/base.rb +165 -0
- data/lib/twitter/httpauth.rb +27 -0
- data/lib/twitter/oauth.rb +34 -0
- data/lib/twitter/request.rb +102 -0
- data/lib/twitter/search.rb +106 -0
- data/lib/twitter/trends.rb +19 -0
- data/lib/twitter.rb +64 -0
- data/test/fixtures/firehose.json +1 -0
- data/test/fixtures/follower_ids.json +1 -0
- data/test/fixtures/friend_ids.json +1 -0
- data/test/fixtures/friends_timeline.json +1 -0
- data/test/fixtures/rate_limit_exceeded.json +1 -0
- data/test/fixtures/replies.json +1 -0
- data/test/fixtures/search.json +1 -0
- data/test/fixtures/search_from_jnunemaker.json +1 -0
- data/test/fixtures/status.json +1 -0
- data/test/fixtures/status_show.json +1 -0
- data/test/fixtures/trends.json +1 -0
- data/test/fixtures/user.json +1 -0
- data/test/fixtures/user_timeline.json +1 -0
- data/test/test_helper.rb +36 -0
- data/test/twitter/base_test.rb +95 -0
- data/test/twitter/httpauth_test.rb +70 -0
- data/test/twitter/oauth_test.rb +71 -0
- data/test/twitter/request_test.rb +217 -0
- data/test/twitter/search_test.rb +144 -0
- data/test/twitter/trends_test.rb +21 -0
- data/test/twitter_test.rb +38 -0
- metadata +192 -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,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TrendsTest < Test::Unit::TestCase
|
4
|
+
context "fetching" do
|
5
|
+
setup do
|
6
|
+
stub_get('http://search.twitter.com:80/trends.json', 'trends.json')
|
7
|
+
@trends = Twitter::Trends.new
|
8
|
+
@response = @trends.fetch
|
9
|
+
end
|
10
|
+
|
11
|
+
should "should return results" do
|
12
|
+
@response.trends.size.should == 10
|
13
|
+
end
|
14
|
+
|
15
|
+
should "should be able to iterate over results" do
|
16
|
+
@trends.respond_to?(:each).should be(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
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,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deadprogrammer-twitter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: oauth
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.3.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mash
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: httparty
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.4.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: thoughtbot-shoulda
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jnunemaker-matchy
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: mocha
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: fakeweb
|
77
|
+
type: :development
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: mash
|
87
|
+
type: :development
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
description:
|
96
|
+
email: ron.evans@gmail.com
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
extra_rdoc_files:
|
102
|
+
- README.rdoc
|
103
|
+
files:
|
104
|
+
- History
|
105
|
+
- License
|
106
|
+
- Notes
|
107
|
+
- README.rdoc
|
108
|
+
- Rakefile
|
109
|
+
- VERSION.yml
|
110
|
+
- examples/connect.rb
|
111
|
+
- examples/friendship_existance.rb
|
112
|
+
- examples/helpers/config_store.rb
|
113
|
+
- examples/httpauth.rb
|
114
|
+
- examples/ids.rb
|
115
|
+
- examples/search.rb
|
116
|
+
- examples/timeline.rb
|
117
|
+
- examples/unauthorized.rb
|
118
|
+
- examples/update.rb
|
119
|
+
- examples/user.rb
|
120
|
+
- lib/twitter.rb
|
121
|
+
- lib/twitter/base.rb
|
122
|
+
- lib/twitter/httpauth.rb
|
123
|
+
- lib/twitter/oauth.rb
|
124
|
+
- lib/twitter/request.rb
|
125
|
+
- lib/twitter/search.rb
|
126
|
+
- lib/twitter/trends.rb
|
127
|
+
- test/fixtures/firehose.json
|
128
|
+
- test/fixtures/follower_ids.json
|
129
|
+
- test/fixtures/friend_ids.json
|
130
|
+
- test/fixtures/friends_timeline.json
|
131
|
+
- test/fixtures/rate_limit_exceeded.json
|
132
|
+
- test/fixtures/replies.json
|
133
|
+
- test/fixtures/search.json
|
134
|
+
- test/fixtures/search_from_jnunemaker.json
|
135
|
+
- test/fixtures/status.json
|
136
|
+
- test/fixtures/status_show.json
|
137
|
+
- test/fixtures/trends.json
|
138
|
+
- test/fixtures/user.json
|
139
|
+
- test/fixtures/user_timeline.json
|
140
|
+
- test/test_helper.rb
|
141
|
+
- test/twitter/base_test.rb
|
142
|
+
- test/twitter/httpauth_test.rb
|
143
|
+
- test/twitter/oauth_test.rb
|
144
|
+
- test/twitter/request_test.rb
|
145
|
+
- test/twitter/search_test.rb
|
146
|
+
- test/twitter/trends_test.rb
|
147
|
+
- test/twitter_test.rb
|
148
|
+
has_rdoc: true
|
149
|
+
homepage: http://github.com/deadprogrammer/twitter
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options:
|
152
|
+
- --charset=UTF-8
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: "0"
|
160
|
+
version:
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: "0"
|
166
|
+
version:
|
167
|
+
requirements: []
|
168
|
+
|
169
|
+
rubyforge_project: twitter
|
170
|
+
rubygems_version: 1.2.0
|
171
|
+
signing_key:
|
172
|
+
specification_version: 2
|
173
|
+
summary: wrapper for the twitter api (oauth only)
|
174
|
+
test_files:
|
175
|
+
- test/test_helper.rb
|
176
|
+
- test/twitter/base_test.rb
|
177
|
+
- test/twitter/httpauth_test.rb
|
178
|
+
- test/twitter/oauth_test.rb
|
179
|
+
- test/twitter/request_test.rb
|
180
|
+
- test/twitter/search_test.rb
|
181
|
+
- test/twitter/trends_test.rb
|
182
|
+
- test/twitter_test.rb
|
183
|
+
- examples/connect.rb
|
184
|
+
- examples/friendship_existance.rb
|
185
|
+
- examples/helpers/config_store.rb
|
186
|
+
- examples/httpauth.rb
|
187
|
+
- examples/ids.rb
|
188
|
+
- examples/search.rb
|
189
|
+
- examples/timeline.rb
|
190
|
+
- examples/unauthorized.rb
|
191
|
+
- examples/update.rb
|
192
|
+
- examples/user.rb
|