rubytter 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,9 +12,3 @@ client = Rubytter.new(ARGV[0], ARGV[1])
12
12
  client.friends_timeline.each do |status|
13
13
  puts "#{status.user.screen_name}: #{status.text}"
14
14
  end
15
-
16
- puts
17
-
18
- client.friends_timeline(:page => 2).each do |status|
19
- puts "#{status.user.screen_name}: #{status.text}"
20
- end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rubytter'
5
+
6
+ if ARGV.size < 2
7
+ puts "Usage: ruby #{File.basename(__FILE__)} user_id password"
8
+ exit
9
+ end
10
+
11
+ client = Rubytter.new(ARGV[0], ARGV[1])
12
+ client.search('ruby').results.each do |status|
13
+ puts "#{status.from_user}: #{status.text}"
14
+ end
data/lib/rubytter.rb CHANGED
@@ -10,7 +10,7 @@ class Rubytter
10
10
  class APIError < StandardError; end
11
11
 
12
12
  APP_NAME = 'Rubytter'
13
- VERSION = '0.4.2'
13
+ VERSION = '0.4.3'
14
14
  HOMEPAGE = 'http://github.com/jugyo/rubytter'
15
15
 
16
16
  def initialize(login, password, options = {})
@@ -84,6 +84,13 @@ class Rubytter
84
84
  send_direct_message(params.merge({:user => user, :text => text}))
85
85
  end
86
86
 
87
+ def search(query = '', params = {})
88
+ params = params.merge({:q => query}) unless query.empty?
89
+ path = '/search.json?' + to_param_str(params)
90
+ req = create_request(Net::HTTP::Post.new(path))
91
+ http_request(req, nil, "search.#{@host}")
92
+ end
93
+
87
94
  def get(path, params = {})
88
95
  path += '.json'
89
96
  param_str = '?' + to_param_str(params)
@@ -104,6 +104,20 @@ class Rubytter
104
104
  @rubytter.followers_ids('test')
105
105
  end
106
106
 
107
+ it 'should respond to http_request' do
108
+ @rubytter.should_receive(:http_request) {|req, param_str| param_str.should == 'status=test'}
109
+ @rubytter.update_status(:status => 'test')
110
+ end
111
+
112
+ it 'should respond to search' do
113
+ @rubytter.should_receive(:http_request) {|req, param_str, host| host.should == 'search.twitter.com'}
114
+ @rubytter.search('test')
115
+ end
116
+
117
+ it 'should respond to to_param_str' do
118
+ @rubytter.to_param_str(:page => 2, :foo => 'bar').should == 'foo=bar&page=2'
119
+ end
120
+
107
121
  it 'should create struct from json' do
108
122
  hash = {
109
123
  :a => 'a',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -42,6 +42,7 @@ files:
42
42
  - examples/friends_timeline.rb
43
43
  - examples/limit.rb
44
44
  - examples/replies.rb
45
+ - examples/search.rb
45
46
  - examples/update_status.rb
46
47
  - examples/user.rb
47
48
  - README.rdoc