dustin-twitter 0.3.2.2 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ 0.3.7 - August 26, 2008
2
+ * Fixed source param not getting through
3
+
4
+ 0.3.6 - August 11, 2008
5
+ * Fixed a few more methods that required post.
6
+ * Refactored the remaining methods that were not using #request to use it.
7
+
8
+ 0.3.5 - August 4, 2008
9
+ * Removed sqlite-ruby 1.2.2 as a dependency due to install issues on linux
10
+
11
+ 0.3.4 - August 3, 2008
12
+ * Added search support
13
+
14
+ 0.3.3 - August 3, 2008
15
+ * Now has option for host when initializing to support identi.ca (Dustin Sallings)
16
+ * Twitter changed a bunch of methods to POST only so I updated those to now work
17
+
1
18
  0.3.2 - July 26, 2008
2
19
  * added the CLI gems as dependencies for now until I separate out the CLI from the API wrapper
3
20
  * cleaner CLI errors for no active account or no accounts at all
data/Manifest.txt CHANGED
@@ -3,7 +3,6 @@ License.txt
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
- TODO.txt
7
6
  bin/twitter
8
7
  config/hoe.rb
9
8
  config/requirements.rb
@@ -12,8 +11,11 @@ examples/direct_messages.rb
12
11
  examples/favorites.rb
13
12
  examples/friends_followers.rb
14
13
  examples/friendships.rb
14
+ examples/identica_timeline.rb
15
15
  examples/location.rb
16
+ examples/posting.rb
16
17
  examples/replies.rb
18
+ examples/search.rb
17
19
  examples/sent_messages.rb
18
20
  examples/timeline.rb
19
21
  examples/twitter.rb
@@ -33,6 +35,7 @@ lib/twitter/cli/models/tweet.rb
33
35
  lib/twitter/direct_message.rb
34
36
  lib/twitter/easy_class_maker.rb
35
37
  lib/twitter/rate_limit_status.rb
38
+ lib/twitter/search.rb
36
39
  lib/twitter/status.rb
37
40
  lib/twitter/user.rb
38
41
  lib/twitter/version.rb
@@ -50,9 +53,11 @@ spec/fixtures/friends_lite.xml
50
53
  spec/fixtures/friends_timeline.xml
51
54
  spec/fixtures/public_timeline.xml
52
55
  spec/fixtures/rate_limit_status.xml
56
+ spec/fixtures/search_results.json
53
57
  spec/fixtures/status.xml
54
58
  spec/fixtures/user.xml
55
59
  spec/fixtures/user_timeline.xml
60
+ spec/search_spec.rb
56
61
  spec/spec.opts
57
62
  spec/spec_helper.rb
58
63
  spec/status_spec.rb
data/README.txt CHANGED
@@ -36,8 +36,17 @@ sudo gem install twitter will work just fine. For command line use, you'll need
36
36
  puts u.name, u.status.text
37
37
  puts
38
38
  end
39
+
40
+ == Search Examples
41
+
42
+ Twitter::Search.new('httparty').each { |r| puts r.inspect }
43
+ Twitter::Search.new('httparty').from('jnunemaker').each { |r| puts r.inspect }
44
+ Twitter::Search.new.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect }
45
+
39
46
 
40
47
  == Command Line Use
48
+
49
+ Note: If you want to use twitter from the command line be sure that sqlite3 and the sqlite3-ruby gem are installed. I removed the sqlite3-ruby gem as a dependency because you shouldn't need that to just use the API wrapper. Eventually I'll move the CLI interface into another gem.
41
50
 
42
51
  $ twitter
43
52
 
data/bin/twitter CHANGED
File without changes
data/config/hoe.rb CHANGED
@@ -63,7 +63,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
63
63
  #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
64
64
  p.extra_deps = [['hpricot', '>= 0.6'], ['activesupport', '>= 2.1'],
65
65
  ['main', '>= 2.8.2'], ['highline', '>= 1.4.0'],
66
- ['activerecord', '>= 2.1'], ['sqlite3-ruby', '>= 1.2.2']]
66
+ ['activerecord', '>= 2.1'], ['httparty', '>= 0.1.0']]
67
67
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
68
68
 
69
69
  end
@@ -6,21 +6,23 @@ twitter = Twitter::Base.new(config['email'], config['password'])
6
6
 
7
7
  puts 'SINCE'
8
8
  twitter.direct_messages(:since => Time.now - 5.day).each do |s|
9
- puts "- #{s.text}"
9
+ puts "- #{s.id} #{s.text}"
10
10
  end
11
11
  puts
12
12
  puts
13
13
 
14
- puts 'SINCE_ID'
15
- twitter.direct_messages(:since_id => 33505386).each do |s|
16
- puts "- #{s.text}"
17
- end
18
- puts
19
- puts
14
+ # puts 'SINCE_ID'
15
+ # twitter.direct_messages(:since_id => 33505386).each do |s|
16
+ # puts "- #{s.text}"
17
+ # end
18
+ # puts
19
+ # puts
20
+ #
21
+ # puts 'PAGE'
22
+ # twitter.direct_messages(:page => 1).each do |s|
23
+ # puts "- #{s.text}"
24
+ # end
25
+ # puts
26
+ # puts
20
27
 
21
- puts 'PAGE'
22
- twitter.direct_messages(:page => 1).each do |s|
23
- puts "- #{s.text}"
24
- end
25
- puts
26
- puts
28
+ # puts twitter.destroy_direct_message(34489057).inspect
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3
+ config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4
+
5
+ identica = Twitter::Base.new(config['email'], config['password'], :api_host => 'identi.ca/api')
6
+
7
+ identica.timeline(:public).each { |s| puts s.text, s.user.name, '' }
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3
+ config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4
+
5
+ twitter = Twitter::Base.new(config['email'], config['password'])
6
+ puts twitter.post("This is a test from the example file").inspect
7
+
8
+ # sending a direct message
9
+ # puts twitter.d('jnunemaker', 'this is a test').inspect
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3
+
4
+ Twitter::Search.new('httparty').each { |r| puts r.inspect,'' }
5
+
6
+ # search = Twitter::Search.new
7
+ # search.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect, '' }
8
+ # pp search.result
9
+ # search.clear
10
+
11
+ # search.from('jnunemaker').to('oaknd1').since(814529437).containing('milk').each { |r| puts r.inspect, '' }
12
+ # search.clear
13
+ #
14
+ # search.geocode('40.757929', '-73.985506', '50mi').containing('holland').each { |r| puts r.inspect, '' }
15
+ # search.clear
16
+
17
+ # pp search.from('jnunemaker').fetch()
data/lib/twitter.rb CHANGED
@@ -5,6 +5,7 @@ require 'twitter/version'
5
5
  require 'twitter/easy_class_maker'
6
6
  require 'twitter/base'
7
7
  require 'twitter/user'
8
+ require 'twitter/search'
8
9
  require 'twitter/status'
9
10
  require 'twitter/direct_message'
10
11
  require 'twitter/rate_limit_status'
data/lib/twitter/base.rb CHANGED
@@ -5,12 +5,15 @@
5
5
  # http://groups.google.com/group/twitter-development-talk/web/api-documentation
6
6
  module Twitter
7
7
  class Base
8
-
9
8
  # Initializes the configuration for making requests to twitter
10
- def initialize(email, password, host='twitter.com', path='')
9
+ # Twitter example:
10
+ # Twitter.new('email/username', 'password')
11
+ #
12
+ # Identi.ca example:
13
+ # Twitter.new('email/username', 'password', :api_host => 'identi.ca/api')
14
+ def initialize(email, password, options={})
11
15
  @config, @config[:email], @config[:password] = {}, email, password
12
- @api_host = host
13
- @api_path = path
16
+ @api_host = options.delete(:api_host) || 'twitter.com'
14
17
  end
15
18
 
16
19
  # Returns an array of statuses for a timeline; Defaults to your friends timeline.
@@ -83,27 +86,22 @@ module Twitter
83
86
 
84
87
  # destroys a give direct message by id if the auth user is a recipient
85
88
  def destroy_direct_message(id)
86
- request("direct_messages/destroy/#{id}.xml", :auth => true)
89
+ DirectMessage.new_from_xml(request("direct_messages/destroy/#{id}.xml", :auth => true, :method => :post))
87
90
  end
88
91
 
89
92
  # Sends a direct message <code>text</code> to <code>user</code>
90
93
  def d(user, text)
91
- url = URI.parse("http://#{@api_host}#{@api_path}/direct_messages/new.xml")
92
- req = Net::HTTP::Post.new(url.path)
93
- req.basic_auth(@config[:email], @config[:password])
94
- req.set_form_data({'text' => text, 'user' => user})
95
- response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
96
- DirectMessage.new_from_xml(parse(response.body).at('direct_message'))
94
+ DirectMessage.new_from_xml(request('direct_messages/new.xml', :auth => true, :method => :post, :form_data => {'text' => text, 'user' => user}))
97
95
  end
98
96
 
99
97
  # Befriends id_or_screenname for the auth user
100
98
  def create_friendship(id_or_screenname)
101
- users(request("friendships/create/#{id_or_screenname}.xml", :auth => true)).first
99
+ users(request("friendships/create/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
102
100
  end
103
101
 
104
102
  # Defriends id_or_screenname for the auth user
105
103
  def destroy_friendship(id_or_screenname)
106
- users(request("friendships/destroy/#{id_or_screenname}.xml", :auth => true)).first
104
+ users(request("friendships/destroy/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
107
105
  end
108
106
 
109
107
  # Returns true if friendship exists, false if it doesn't.
@@ -114,22 +112,22 @@ module Twitter
114
112
 
115
113
  # Updates your location and returns Twitter::User object
116
114
  def update_location(location)
117
- users(request(build_path('account/update_location.xml', {'location' => location}), :auth => true)).first
115
+ users(request(build_path('account/update_location.xml', {'location' => location}), :auth => true, :method => :post)).first
118
116
  end
119
117
 
120
118
  # Updates your deliver device and returns Twitter::User object
121
119
  def update_delivery_device(device)
122
- users(request(build_path('account/update_delivery_device.xml', {'device' => device}), :auth => true)).first
120
+ users(request(build_path('account/update_delivery_device.xml', {'device' => device}), :auth => true, :method => :post)).first
123
121
  end
124
122
 
125
123
  # Turns notifications by id_or_screenname on for auth user.
126
124
  def follow(id_or_screenname)
127
- users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true)).first
125
+ users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
128
126
  end
129
127
 
130
128
  # Turns notifications by id_or_screenname off for auth user.
131
129
  def leave(id_or_screenname)
132
- users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
130
+ users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
133
131
  end
134
132
 
135
133
  # Returns the most recent favorite statuses for the autenticating user
@@ -139,41 +137,36 @@ module Twitter
139
137
 
140
138
  # Favorites the status specified by id for the auth user
141
139
  def create_favorite(id)
142
- statuses(request("favorites/create/#{id}.xml", :auth => true)).first
140
+ statuses(request("favorites/create/#{id}.xml", :auth => true, :method => :post)).first
143
141
  end
144
142
 
145
143
  # Un-favorites the status specified by id for the auth user
146
144
  def destroy_favorite(id)
147
- statuses(request("favorites/destroy/#{id}.xml", :auth => true)).first
145
+ statuses(request("favorites/destroy/#{id}.xml", :auth => true, :method => :post)).first
148
146
  end
149
147
 
150
148
  # Blocks the user specified by id for the auth user
151
149
  def block(id)
152
- users(request("blocks/create/#{id}.xml", :auth => true)).first
150
+ users(request("blocks/create/#{id}.xml", :auth => true, :method => :post)).first
153
151
  end
154
152
 
155
153
  # Unblocks the user specified by id for the auth user
156
154
  def unblock(id)
157
- users(request("blocks/destroy/#{id}.xml", :auth => true)).first
155
+ users(request("blocks/destroy/#{id}.xml", :auth => true, :method => :post)).first
158
156
  end
159
157
 
160
158
  # Posts a new update to twitter for auth user.
161
159
  def post(status, options={})
162
160
  form_data = {'status' => status}
163
- form_data.merge({'source' => options[:source]}) if options[:source]
164
- url = URI.parse("http://#{@api_host}#{@api_path}/statuses/update.xml")
165
- req = Net::HTTP::Post.new(url.path)
166
- req.basic_auth(@config[:email], @config[:password])
167
- req.set_form_data(form_data)
168
- response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
169
- Status.new_from_xml(parse(response.body).at('status'))
161
+ form_data.merge!({'source' => options[:source]}) if options[:source]
162
+ Status.new_from_xml(request('statuses/update.xml', :auth => true, :method => :post, :form_data => form_data))
170
163
  end
171
164
  alias :update :post
172
165
 
173
166
  # Verifies the credentials for the auth user.
174
167
  # raises Twitter::CantConnect on failure.
175
168
  def verify_credentials
176
- request('account/verify_credentials', :auth => true)
169
+ request('account/verify_credentials.xml', :auth => true)
177
170
  end
178
171
 
179
172
  private
@@ -200,16 +193,25 @@ module Twitter
200
193
 
201
194
  # Makes a request to twitter.
202
195
  def request(path, options={})
203
- options.reverse_merge!({:headers => { "User-Agent" => @config[:email] }})
196
+ options.reverse_merge!({
197
+ :headers => { "User-Agent" => @config[:email] },
198
+ :method => :get
199
+ })
204
200
  unless options[:since].blank?
205
201
  since = options[:since].kind_of?(Date) ? options[:since].strftime('%a, %d-%b-%y %T GMT') : options[:since].to_s
206
202
  options[:headers]["If-Modified-Since"] = since
207
203
  end
208
204
 
205
+ uri = URI.parse("http://#{@api_host}")
206
+
209
207
  begin
210
- response = Net::HTTP.start(@api_host, 80) do |http|
211
- req = Net::HTTP::Get.new('/' + path, options[:headers])
208
+ response = Net::HTTP.start(uri.host, 80) do |http|
209
+ klass = Net::HTTP.const_get options[:method].to_s.downcase.capitalize
210
+ req = klass.new("#{uri.path}/#{path}", options[:headers])
212
211
  req.basic_auth(@config[:email], @config[:password]) if options[:auth]
212
+ if options[:method].to_s == 'post' && options[:form_data]
213
+ req.set_form_data(options[:form_data])
214
+ end
213
215
  http.request(req)
214
216
  end
215
217
  rescue => error
data/lib/twitter/cli.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  gem 'main', '>= 2.8.2'
3
3
  gem 'highline', '>= 1.4.0'
4
4
  gem 'activerecord', '>= 2.1'
5
- gem 'sqlite3-ruby', '>= 1.2.2'
5
+ gem 'sqlite3-ruby', '>= 1.2.1'
6
6
  require 'main'
7
7
  require 'highline/import'
8
8
  require 'activerecord'
@@ -0,0 +1,94 @@
1
+ gem 'httparty'
2
+ require 'httparty'
3
+
4
+ module Twitter
5
+ class Search
6
+ include HTTParty
7
+ include Enumerable
8
+ base_uri 'search.twitter.com'
9
+
10
+ attr_reader :result, :query
11
+
12
+ def initialize(q=nil)
13
+ clear
14
+ containing(q) unless q.blank?
15
+ end
16
+
17
+ def from(user)
18
+ @query[:q] << "from:#{user}"
19
+ self
20
+ end
21
+
22
+ def to(user)
23
+ @query[:q] << "to:#{user}"
24
+ self
25
+ end
26
+
27
+ def referencing(user)
28
+ @query[:q] << "@#{user}"
29
+ self
30
+ end
31
+ alias :references :referencing
32
+ alias :ref :referencing
33
+
34
+ def containing(word)
35
+ @query[:q] << "#{word}"
36
+ self
37
+ end
38
+ alias :contains :containing
39
+
40
+ # adds filtering based on hash tag ie: #twitter
41
+ def hashed(tag)
42
+ @query[:q] << "##{tag}"
43
+ self
44
+ end
45
+
46
+ # lang must be ISO 639-1 code ie: en, fr, de, ja, etc.
47
+ #
48
+ # when I tried en it limited my results a lot and took
49
+ # out several tweets that were english so i'd avoid
50
+ # this unless you really want it
51
+ def lang(lang)
52
+ @query[:lang] = lang
53
+ self
54
+ end
55
+
56
+ # Limits the number of results per page
57
+ def per_page(num)
58
+ @query[:rpp] = num
59
+ self
60
+ end
61
+
62
+ # Only searches tweets since a given id.
63
+ # Recommended to use this when possible.
64
+ def since(since_id)
65
+ @query[:since_id] = since_id
66
+ self
67
+ end
68
+
69
+ # Search tweets by longitude, latitude and a given range.
70
+ # Ranges like 25km and 50mi work.
71
+ def geocode(long, lat, range)
72
+ @query[:geocode] = [long, lat, range].join(',')
73
+ self
74
+ end
75
+
76
+ # Clears all the query filters to make a new search
77
+ def clear
78
+ @query = {}
79
+ @query[:q] = []
80
+ self
81
+ end
82
+
83
+ # If you want to get results do something other than iterate over them.
84
+ def fetch
85
+ @query[:q] = @query[:q].join(' ')
86
+ self.class.get('/search.json', {:query => @query})
87
+ end
88
+
89
+ def each
90
+ @result = fetch()
91
+ @result['results'].each { |r| yield r }
92
+ end
93
+ end
94
+ end
@@ -2,7 +2,7 @@ module Twitter #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 2
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1 @@
1
+ {"max_id"=>876733347, "since_id"=>0, "results"=>[{"text"=>"post using httparty.", "from_user"=>"yuweijun", "to_user_id"=>nil, "id"=>876203197, "iso_language_code"=>"en", "from_user_id"=>1170048, "created_at"=>"Sun, 03 Aug 2008 06:40:42 +0000", "profile_image_url"=>"http://static.twitter.com/images/default_profile_normal.png"}, {"text"=>"HTTParty: Quick Web Service Consumption From Any Ruby Class: HTTParty is a new Ruby library by Joh.. http://tinyurl.com/5cb8e8", "from_user"=>"delicious_prog", "to_user_id"=>nil, "id"=>875881978, "iso_language_code"=>"en", "from_user_id"=>468104, "created_at"=>"Sat, 02 Aug 2008 20:47:02 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/54388004/delicious.42px_normal.gif"}, {"text"=>"[4Rails] HTTParty: Quick Web Service Consumption From Any Ruby Class: HTTParty: Quick Web Serv.. http://tinyurl.com/5uemxj", "from_user"=>"bumperbody", "to_user_id"=>nil, "id"=>875828918, "iso_language_code"=>"en", "from_user_id"=>476491, "created_at"=>"Sat, 02 Aug 2008 19:16:19 +0000", "profile_image_url"=>"http://static.twitter.com/images/default_profile_normal.png"}, {"text"=>"[ruby] HTTParty: Quick Web Service Consumption From Any Ruby Class", "from_user"=>"rubymentary", "to_user_id"=>nil, "id"=>875761343, "iso_language_code"=>"en", "from_user_id"=>474717, "created_at"=>"Sat, 02 Aug 2008 17:26:19 +0000", "profile_image_url"=>"http://static.twitter.com/images/default_profile_normal.png"}, {"text"=>"[ruby: RubyInside] HTTParty: Quick Web Service Consumption From Any Ruby Class http://tinyurl.com/5gryre", "from_user"=>"devfunnel", "to_user_id"=>nil, "id"=>875732752, "iso_language_code"=>"en", "from_user_id"=>465190, "created_at"=>"Sat, 02 Aug 2008 16:44:21 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/53748400/dev-funnel-logo-shiny-50x50_normal.png"}, {"text"=>"using the excellent OpenLibrary API, via HTTParty - i do like it that people have thought i'd want to do this in advance!", "from_user"=>"degsy", "to_user_id"=>nil, "id"=>875690354, "iso_language_code"=>"en", "from_user_id"=>164367, "created_at"=>"Sat, 02 Aug 2008 15:43:58 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/56185617/degsy_normal.jpg"}, {"text"=>"httparty gem rocks", "from_user"=>"shenie", "to_user_id"=>nil, "id"=>874139770, "iso_language_code"=>"en", "from_user_id"=>271831, "created_at"=>"Thu, 31 Jul 2008 22:58:19 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/42362902/Photo_28_normal.jpg"}, {"text"=>"httparty  yup.  that is what i was missing", "from_user"=>"bryanl", "to_user_id"=>nil, "id"=>873839285, "iso_language_code"=>"en", "from_user_id"=>5167, "created_at"=>"Thu, 31 Jul 2008 17:15:51 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/57603306/Photo_26_normal.jpg"}, {"text"=>"@timhaines thanks for the link to HTTParty, Xero api consumer for contacts (at least the get part) now only takes 18 lines of code.", "from_user"=>"buildmaster", "to_user"=>"timhaines", "to_user_id"=>159881, "id"=>873222820, "iso_language_code"=>"en", "from_user_id"=>26548, "created_at"=>"Thu, 31 Jul 2008 02:29:02 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/51894576/gold_o_normal.jpg"}, {"text"=>"refactoring code from yesterdays example to use HTTParty", "from_user"=>"buildmaster", "to_user_id"=>nil, "id"=>873020059, "iso_language_code"=>"en", "from_user_id"=>26548, "created_at"=>"Wed, 30 Jul 2008 21:55:19 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/51894576/gold_o_normal.jpg"}, {"text"=>"delicious: It's an HTTParty and Everyone Is Invited! // RailsTips.org by John Nunemaker http://tinyurl.com/6774gz", "from_user"=>"top_web", "to_user_id"=>nil, "id"=>872810034, "iso_language_code"=>"en", "from_user_id"=>780201, "created_at"=>"Wed, 30 Jul 2008 17:48:25 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/55853305/web_normal.jpg"}, {"text"=>"d: It's an HTTParty and Everyone Is Invited! // RailsTips.org by John Nunemaker http://tinyurl.com/6774gz", "from_user"=>"top_dedist", "to_user_id"=>nil, "id"=>872809988, "iso_language_code"=>"en", "from_user_id"=>760334, "created_at"=>"Wed, 30 Jul 2008 17:48:20 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/55845227/dedist_normal.jpg"}, {"text"=>"[4Rails] It's an HTTParty and Everyone Is Invited! // RailsTips.org by John Nunemaker: It's an.. http://tinyurl.com/57wjn4", "from_user"=>"bumperbody", "to_user_id"=>nil, "id"=>872549387, "iso_language_code"=>"en", "from_user_id"=>476491, "created_at"=>"Wed, 30 Jul 2008 13:16:57 +0000", "profile_image_url"=>"http://static.twitter.com/images/default_profile_normal.png"}, {"text"=>"New blog post: Sinatra, Passenger, HTTParty: Small, Fast, Now http://ruby.tie-rack.org/?p=70", "from_user"=>"tierack", "to_user_id"=>nil, "id"=>872275405, "iso_language_code"=>"no", "from_user_id"=>98800, "created_at"=>"Wed, 30 Jul 2008 04:55:40 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/52166714/mvb200_normal.jpg"}, {"text"=>"Tonight we're gonna HTTParty like it's 1999! - Time to boogie on down and consume some webservices! http://httparty.rubyforge.org/", "from_user"=>"hunternield", "to_user_id"=>nil, "id"=>872086627, "iso_language_code"=>"en", "from_user_id"=>47386, "created_at"=>"Wed, 30 Jul 2008 00:12:47 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/52133648/Photo_59_normal.jpg"}], "results_per_page"=>15, "next_page"=>"?page=2&max_id=876733347&q=httparty+", "query"=>"httparty ", "page"=>1}
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Twitter::Search do
4
+ before do
5
+ @search = Twitter::Search.new
6
+ end
7
+
8
+ it "should be able to initialize with a search term" do
9
+ Twitter::Search.new('httparty').query[:q].should include('httparty')
10
+ end
11
+
12
+ it "should be able to specify from" do
13
+ @search.from('jnunemaker').query[:q].should include('from:jnunemaker')
14
+ end
15
+
16
+ it "should be able to specify to" do
17
+ @search.to('jnunemaker').query[:q].should include('to:jnunemaker')
18
+ end
19
+
20
+ it "should be able to specify referencing" do
21
+ @search.referencing('jnunemaker').query[:q].should include('@jnunemaker')
22
+ end
23
+
24
+ it "should alias references to referencing" do
25
+ @search.references('jnunemaker').query[:q].should include('@jnunemaker')
26
+ end
27
+
28
+ it "should alias ref to referencing" do
29
+ @search.ref('jnunemaker').query[:q].should include('@jnunemaker')
30
+ end
31
+
32
+ it "should be able to specify containing" do
33
+ @search.containing('milk').query[:q].should include('milk')
34
+ end
35
+
36
+ it "should alias contains to containing" do
37
+ @search.contains('milk').query[:q].should include('milk')
38
+ end
39
+
40
+ it "should be able to specify hashed" do
41
+ @search.hashed('twitter').query[:q].should include('#twitter')
42
+ end
43
+
44
+ it "should be able to specify the language" do
45
+ @search.lang('en').query[:lang].should == 'en'
46
+ end
47
+
48
+ it "should be able to specify the number of results per page" do
49
+ @search.per_page(25).query[:rpp].should == 25
50
+ end
51
+
52
+ it "should be able to specify only returning results greater than an id" do
53
+ @search.since(1234).query[:since_id].should == 1234
54
+ end
55
+
56
+ it "should be able to specify geo coordinates" do
57
+ @search.geocode('40.757929', '-73.985506', '25mi').query[:geocode].should == '40.757929,-73.985506,25mi'
58
+ end
59
+
60
+ it "should be able to clear the filters set" do
61
+ @search.from('jnunemaker').to('oaknd1')
62
+ @search.clear.query.should == {:q => []}
63
+ end
64
+
65
+ it "should be able to chain methods together" do
66
+ @search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
67
+ @search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', '#twitter']
68
+ @search.query[:lang].should == 'en'
69
+ @search.query[:rpp].should == 20
70
+ @search.query[:since_id].should == 1234
71
+ @search.query[:geocode].should == '40.757929,-73.985506,25mi'
72
+ end
73
+
74
+ describe "fetching" do
75
+ before do
76
+ @response = open(File.dirname(__FILE__) + '/fixtures/friends_timeline.xml').read
77
+ @search.class.stub!(:get).and_return(@response)
78
+ end
79
+
80
+ it "should return results" do
81
+ @search.class.should_receive(:get).and_return(@response)
82
+ @search.from('jnunemaker').fetch().should == @response
83
+ end
84
+ end
85
+
86
+ it "should be able to iterate over results" do
87
+ @search.respond_to?(:each).should == true
88
+ end
89
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,10 @@
1
- require 'rubygems'
2
- gem 'rspec'
3
- require 'spec'
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
4
8
 
5
9
  dir = File.dirname(__FILE__)
6
10
 
@@ -1,3 +1,12 @@
1
+ desc 'Preps the gem for a new release'
2
+ task :prep_for_release do
3
+ require 'rio'
4
+ Rake::Task['manifest:refresh'].invoke
5
+ gemspec = %x[rake debug_gem]
6
+ lines = gemspec.split("\n")
7
+ rio('twitter.gemspec') < lines[1, lines.length-1].join("\n")
8
+ end
9
+
1
10
  desc 'Release the website and new gem version'
2
11
  task :deploy => [:check_version, :website, :release] do
3
12
  puts "Remember to create SVN tag:"
data/tasks/website.rake CHANGED
@@ -14,4 +14,4 @@ task :website_upload do
14
14
  end
15
15
 
16
16
  desc 'Generate and upload website files'
17
- task :website => [:website_generate, :website_upload, :publish_docs]
17
+ task :website => [:website_upload, :publish_docs]
data/twitter.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{twitter}
3
- s.version = "0.3.2.2"
3
+ s.version = "0.3.7"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["John Nunemaker"]
7
- s.date = %q{2008-07-28}
7
+ s.date = %q{2008-08-26}
8
8
  s.default_executable = %q{twitter}
9
9
  s.description = %q{a command line interface for twitter, also a library which wraps the twitter api}
10
10
  s.email = %q{nunemaker@gmail.com}
11
11
  s.executables = ["twitter"]
12
- s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "TODO.txt"]
13
- s.files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "TODO.txt", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/blocks.rb", "examples/direct_messages.rb", "examples/favorites.rb", "examples/friends_followers.rb", "examples/friendships.rb", "examples/location.rb", "examples/replies.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/cli.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/spec.opts", "spec/spec_helper.rb", "spec/status_spec.rb", "spec/user_spec.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "twitter.gemspec", "website/css/common.css", "website/images/terminal_output.png", "website/index.html"]
12
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
13
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/blocks.rb", "examples/direct_messages.rb", "examples/favorites.rb", "examples/friends_followers.rb", "examples/friendships.rb", "examples/identica_timeline.rb", "examples/location.rb", "examples/posting.rb", "examples/replies.rb", "examples/search.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/cli.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/search.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/search_results.json", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/search_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/status_spec.rb", "spec/user_spec.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "twitter.gemspec", "website/css/common.css", "website/images/terminal_output.png", "website/index.html"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://twitter.rubyforge.org}
16
16
  s.rdoc_options = ["--main", "README.txt"]
@@ -29,14 +29,14 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency(%q<main>, [">= 2.8.2"])
30
30
  s.add_runtime_dependency(%q<highline>, [">= 1.4.0"])
31
31
  s.add_runtime_dependency(%q<activerecord>, [">= 2.1"])
32
- s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.2.2"])
32
+ s.add_runtime_dependency(%q<httparty>, [">= 0.1.0"])
33
33
  else
34
34
  s.add_dependency(%q<hpricot>, [">= 0.6"])
35
35
  s.add_dependency(%q<activesupport>, [">= 2.1"])
36
36
  s.add_dependency(%q<main>, [">= 2.8.2"])
37
37
  s.add_dependency(%q<highline>, [">= 1.4.0"])
38
38
  s.add_dependency(%q<activerecord>, [">= 2.1"])
39
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.2"])
39
+ s.add_dependency(%q<httparty>, [">= 0.1.0"])
40
40
  end
41
41
  else
42
42
  s.add_dependency(%q<hpricot>, [">= 0.6"])
@@ -44,6 +44,6 @@ Gem::Specification.new do |s|
44
44
  s.add_dependency(%q<main>, [">= 2.8.2"])
45
45
  s.add_dependency(%q<highline>, [">= 1.4.0"])
46
46
  s.add_dependency(%q<activerecord>, [">= 2.1"])
47
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.2"])
47
+ s.add_dependency(%q<httparty>, [">= 0.1.0"])
48
48
  end
49
- end
49
+ end
data/website/index.html CHANGED
@@ -15,6 +15,7 @@
15
15
  <ul id="nav">
16
16
  <li><a href="rdoc/">Docs</a></li>
17
17
  <li><a href="http://github.com/jnunemaker/twitter">Github</a></li>
18
+ <li><a href="http://jnunemaker.lighthouseapp.com/projects/14843-twitter-gem/overview">Lighthouse</a></li>
18
19
  <li><a href="http://rubyforge.org/projects/twitter/">Rubyforge</a></li>
19
20
  </ul>
20
21
  </div>
@@ -67,10 +68,27 @@ twit.followers.each do |u|
67
68
  end
68
69
  </code></pre>
69
70
 
70
- <h2>Command Line</h2>
71
+ <h2>Search API Examples</h2>
72
+
73
+ <pre><code>#searches all tweets for httparty
74
+ Twitter::Search.new('httparty').each { |r| puts r.inspect }
75
+
76
+ # searches all of jnunemaker's tweets for httparty
77
+ Twitter::Search.new('httparty').from('jnunemaker').each { |r| puts r.inspect }
78
+
79
+ # searches all tweets from jnunemaker to oaknd1
80
+ Twitter::Search.new.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect }
71
81
 
82
+ # you can also use fetch to actually just get the parsed response
83
+ Twitter::Search.new.from('jnunemaker').to('oaknd1').fetch()
84
+ </code></pre>
85
+
86
+ <h2>Command Line</h2>
87
+
72
88
  <p><img src="images/terminal_output.png" alt="Terminal Output" style="width:560px;" /></p>
73
89
 
90
+ <p><strong>Note: If you want to use twitter from the command line be sure that sqlite3 and the sqlite3-ruby gem are installed.</strong> I removed the sqlite3-ruby gem as a dependency because you shouldn't need that to just use the API wrapper. Eventually I'll move the CLI interface into another gem.</p>
91
+
74
92
  <p>The first thing you'll want to do is install the database so your account(s) can be stored.</p>
75
93
 
76
94
  <pre><code>$ twitter install</code></pre>
@@ -108,7 +126,7 @@ Account List
108
126
 
109
127
 
110
128
  <h2>Support</h2>
111
- <p>Please leave all support requests and suggestions at the <a href="http://groups.google.com/group/ruby-twitter-gem">google group</a>.</p>
129
+ <p>Conversations welcome in the <a href="http://groups.google.com/group/ruby-twitter-gem">google group</a> and bugs/features over at <a href="http://jnunemaker.lighthouseapp.com/projects/14843-twitter-gem/overview">lighthouse</a></p>
112
130
 
113
131
  <h2>Uses</h2>
114
132
  <ul>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dustin-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-28 00:00:00 -07:00
12
+ date: 2008-08-26 00:00:00 -07:00
13
13
  default_executable: twitter
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -58,13 +58,13 @@ dependencies:
58
58
  version: "2.1"
59
59
  version:
60
60
  - !ruby/object:Gem::Dependency
61
- name: sqlite3-ruby
61
+ name: httparty
62
62
  version_requirement:
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 1.2.2
67
+ version: 0.1.0
68
68
  version:
69
69
  description: a command line interface for twitter, also a library which wraps the twitter api
70
70
  email: nunemaker@gmail.com
@@ -77,14 +77,12 @@ extra_rdoc_files:
77
77
  - License.txt
78
78
  - Manifest.txt
79
79
  - README.txt
80
- - TODO.txt
81
80
  files:
82
81
  - History.txt
83
82
  - License.txt
84
83
  - Manifest.txt
85
84
  - README.txt
86
85
  - Rakefile
87
- - TODO.txt
88
86
  - bin/twitter
89
87
  - config/hoe.rb
90
88
  - config/requirements.rb
@@ -93,8 +91,11 @@ files:
93
91
  - examples/favorites.rb
94
92
  - examples/friends_followers.rb
95
93
  - examples/friendships.rb
94
+ - examples/identica_timeline.rb
96
95
  - examples/location.rb
96
+ - examples/posting.rb
97
97
  - examples/replies.rb
98
+ - examples/search.rb
98
99
  - examples/sent_messages.rb
99
100
  - examples/timeline.rb
100
101
  - examples/twitter.rb
@@ -114,6 +115,7 @@ files:
114
115
  - lib/twitter/direct_message.rb
115
116
  - lib/twitter/easy_class_maker.rb
116
117
  - lib/twitter/rate_limit_status.rb
118
+ - lib/twitter/search.rb
117
119
  - lib/twitter/status.rb
118
120
  - lib/twitter/user.rb
119
121
  - lib/twitter/version.rb
@@ -131,9 +133,11 @@ files:
131
133
  - spec/fixtures/friends_timeline.xml
132
134
  - spec/fixtures/public_timeline.xml
133
135
  - spec/fixtures/rate_limit_status.xml
136
+ - spec/fixtures/search_results.json
134
137
  - spec/fixtures/status.xml
135
138
  - spec/fixtures/user.xml
136
139
  - spec/fixtures/user_timeline.xml
140
+ - spec/search_spec.rb
137
141
  - spec/spec.opts
138
142
  - spec/spec_helper.rb
139
143
  - spec/status_spec.rb
data/TODO.txt DELETED
@@ -1,2 +0,0 @@
1
- * add timeout so it doesn't hang forever like it does now if twitter is down
2
- * add progress indicator for timeline and replies as posting has for more visual indication that work is happening