rubytter 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rubytter.rb +9 -7
- data/spec/rubytter_spec.rb +27 -27
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.2
|
data/lib/rubytter.rb
CHANGED
@@ -13,6 +13,9 @@ require 'rubytter/oauth_rubytter'
|
|
13
13
|
class Rubytter
|
14
14
|
VERSION = File.read(File.join(File.dirname(__FILE__), '../VERSION')).strip
|
15
15
|
|
16
|
+
HOST = 'api.twitter.com'
|
17
|
+
SEARCH_HOST = 'search.twitter.com'
|
18
|
+
|
16
19
|
class APIError < StandardError
|
17
20
|
attr_reader :response
|
18
21
|
def initialize(msg, response = nil)
|
@@ -22,7 +25,7 @@ class Rubytter
|
|
22
25
|
end
|
23
26
|
|
24
27
|
attr_reader :login
|
25
|
-
attr_accessor :
|
28
|
+
attr_accessor :header
|
26
29
|
|
27
30
|
def initialize(login = nil, password = nil, options = {})
|
28
31
|
@login = login
|
@@ -31,7 +34,6 @@ class Rubytter
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def setup(options)
|
34
|
-
@host = options[:host] || 'api.twitter.com'
|
35
37
|
@header = {'User-Agent' => "Rubytter/#{VERSION} (http://github.com/jugyo/rubytter)"}
|
36
38
|
@header.merge!(options[:header]) if options[:header]
|
37
39
|
@app_name = options[:app_name]
|
@@ -167,21 +169,21 @@ class Rubytter
|
|
167
169
|
param_str = '?' + to_param_str(params)
|
168
170
|
path = path + param_str unless param_str.empty?
|
169
171
|
req = create_request(Net::HTTP::Get.new(path))
|
170
|
-
structize(http_request(
|
172
|
+
structize(http_request(HOST, req))
|
171
173
|
end
|
172
174
|
|
173
175
|
def post(path, params = {})
|
174
176
|
path += '.json'
|
175
177
|
param_str = to_param_str(params)
|
176
178
|
req = create_request(Net::HTTP::Post.new(path))
|
177
|
-
structize(http_request(
|
179
|
+
structize(http_request(HOST, req, param_str))
|
178
180
|
end
|
179
181
|
|
180
182
|
def delete(path, params = {})
|
181
183
|
path += '.json'
|
182
184
|
param_str = to_param_str(params)
|
183
185
|
req = create_request(Net::HTTP::Delete.new(path))
|
184
|
-
structize(http_request(
|
186
|
+
structize(http_request(HOST, req, param_str))
|
185
187
|
end
|
186
188
|
|
187
189
|
def search(query, params = {})
|
@@ -190,7 +192,7 @@ class Rubytter
|
|
190
192
|
path = path + param_str unless param_str.empty?
|
191
193
|
req = create_request(Net::HTTP::Get.new(path), false)
|
192
194
|
|
193
|
-
json_data = http_request(
|
195
|
+
json_data = http_request(SEARCH_HOST, req, nil, @connection_for_search)
|
194
196
|
structize(
|
195
197
|
json_data['results'].map do |result|
|
196
198
|
search_result_to_hash(result)
|
@@ -203,7 +205,7 @@ class Rubytter
|
|
203
205
|
param_str = '?' + to_param_str(params.merge({:q => query}))
|
204
206
|
path = path + param_str unless param_str.empty?
|
205
207
|
req = create_request(Net::HTTP::Get.new(path))
|
206
|
-
structize(http_request(
|
208
|
+
structize(http_request(HOST, req))
|
207
209
|
end
|
208
210
|
|
209
211
|
def search_result_to_hash(json)
|
data/spec/rubytter_spec.rb
CHANGED
@@ -20,87 +20,87 @@ class Rubytter
|
|
20
20
|
|
21
21
|
it 'should get or post' do
|
22
22
|
# TODO: split specs
|
23
|
-
@rubytter.should_receive(:get).with('/statuses/replies', {})
|
23
|
+
@rubytter.should_receive(:get).with('/1/statuses/replies', {})
|
24
24
|
@rubytter.replies
|
25
25
|
|
26
|
-
@rubytter.should_receive(:get).with('/statuses/replies', {:page => 2})
|
26
|
+
@rubytter.should_receive(:get).with('/1/statuses/replies', {:page => 2})
|
27
27
|
@rubytter.replies(:page => 2)
|
28
28
|
|
29
|
-
@rubytter.should_receive(:get).with('/statuses/user_timeline/1', {})
|
29
|
+
@rubytter.should_receive(:get).with('/1/statuses/user_timeline/1', {})
|
30
30
|
@rubytter.user_timeline(1)
|
31
31
|
|
32
|
-
@rubytter.should_receive(:get).with('/users/show/1', {})
|
32
|
+
@rubytter.should_receive(:get).with('/1/users/show/1', {})
|
33
33
|
@rubytter.user(1)
|
34
34
|
|
35
|
-
@rubytter.should_receive(:delete).with('/statuses/destroy/1', {})
|
35
|
+
@rubytter.should_receive(:delete).with('/1/statuses/destroy/1', {})
|
36
36
|
@rubytter.remove_status(1)
|
37
37
|
end
|
38
38
|
|
39
39
|
# direct_messages
|
40
40
|
|
41
41
|
it 'should respond to direct_messages' do
|
42
|
-
@rubytter.should_receive(:get).with('/direct_messages', {})
|
42
|
+
@rubytter.should_receive(:get).with('/1/direct_messages', {})
|
43
43
|
@rubytter.direct_messages()
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should respond to sent_direct_messages' do
|
47
|
-
@rubytter.should_receive(:get).with('/direct_messages/sent', {})
|
47
|
+
@rubytter.should_receive(:get).with('/1/direct_messages/sent', {})
|
48
48
|
@rubytter.sent_direct_messages()
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should respond to send_direct_message' do
|
52
|
-
@rubytter.should_receive(:post).with('/direct_messages/new', {})
|
52
|
+
@rubytter.should_receive(:post).with('/1/direct_messages/new', {})
|
53
53
|
@rubytter.send_direct_message()
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should respond to destroy_direct_message' do
|
57
|
-
@rubytter.should_receive(:delete).with('/direct_messages/destroy/1', {})
|
57
|
+
@rubytter.should_receive(:delete).with('/1/direct_messages/destroy/1', {})
|
58
58
|
@rubytter.remove_direct_message(1)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should respond to direct_message' do
|
62
|
-
@rubytter.should_receive(:post).with('/direct_messages/new', {:user => 'test', :text => 'aaaaaaaaaaaaa'})
|
62
|
+
@rubytter.should_receive(:post).with('/1/direct_messages/new', {:user => 'test', :text => 'aaaaaaaaaaaaa'})
|
63
63
|
@rubytter.direct_message('test', 'aaaaaaaaaaaaa')
|
64
64
|
end
|
65
65
|
|
66
66
|
# statuses
|
67
67
|
|
68
68
|
it 'should respond to update' do
|
69
|
-
@rubytter.should_receive(:post).with('/statuses/update', {:status => 'test'})
|
69
|
+
@rubytter.should_receive(:post).with('/1/statuses/update', {:status => 'test'})
|
70
70
|
@rubytter.update('test')
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should respond to update_status' do
|
74
|
-
@rubytter.should_receive(:post).with('/statuses/update', {:status => 'test'})
|
74
|
+
@rubytter.should_receive(:post).with('/1/statuses/update', {:status => 'test'})
|
75
75
|
@rubytter.update_status(:status => 'test')
|
76
76
|
end
|
77
77
|
|
78
78
|
# friendship
|
79
79
|
|
80
80
|
it 'should respond to follow' do
|
81
|
-
@rubytter.should_receive(:post).with('/friendships/create/test', {})
|
81
|
+
@rubytter.should_receive(:post).with('/1/friendships/create/test', {})
|
82
82
|
@rubytter.follow('test')
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should respond to leave' do
|
86
|
-
@rubytter.should_receive(:delete).with('/friendships/destroy/test', {})
|
86
|
+
@rubytter.should_receive(:delete).with('/1/friendships/destroy/test', {})
|
87
87
|
@rubytter.leave('test')
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'should respond to friendship_exists' do
|
91
|
-
@rubytter.should_receive(:get).with('/friendships/exists', {:user_a => 'a', :user_b => 'b'})
|
91
|
+
@rubytter.should_receive(:get).with('/1/friendships/exists', {:user_a => 'a', :user_b => 'b'})
|
92
92
|
@rubytter.friendship_exists(:user_a => 'a', :user_b => 'b')
|
93
93
|
end
|
94
94
|
|
95
95
|
# Social Graph Methods
|
96
96
|
|
97
97
|
it 'should respond to followers_ids' do
|
98
|
-
@rubytter.should_receive(:get).with('/friends/ids/test', {})
|
98
|
+
@rubytter.should_receive(:get).with('/1/friends/ids/test', {})
|
99
99
|
@rubytter.friends_ids('test')
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'should respond to followers_ids' do
|
103
|
-
@rubytter.should_receive(:get).with('/followers/ids/test', {})
|
103
|
+
@rubytter.should_receive(:get).with('/1/followers/ids/test', {})
|
104
104
|
@rubytter.followers_ids('test')
|
105
105
|
end
|
106
106
|
|
@@ -143,7 +143,7 @@ class Rubytter
|
|
143
143
|
|
144
144
|
it 'should set default header' do
|
145
145
|
rubytter = Rubytter.new('test', 'test')
|
146
|
-
rubytter.header.should == {'User-Agent'
|
146
|
+
rubytter.header.should == {'User-Agent' => "Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should able to set custom header 1' do
|
@@ -316,32 +316,32 @@ class Rubytter
|
|
316
316
|
end
|
317
317
|
|
318
318
|
it 'should POST /:user/list to create list' do
|
319
|
-
@rubytter.should_receive(:post).with("/test/lists", {:name=>"foo"})
|
319
|
+
@rubytter.should_receive(:post).with("/1/test/lists", {:name=>"foo"})
|
320
320
|
@rubytter.create_list('foo')
|
321
321
|
end
|
322
322
|
|
323
323
|
it 'should PUT /:user/list to update list' do
|
324
|
-
@rubytter.should_receive(:put).with("/test/lists/foo", {})
|
324
|
+
@rubytter.should_receive(:put).with("/1/test/lists/foo", {})
|
325
325
|
@rubytter.update_list('foo')
|
326
326
|
end
|
327
327
|
|
328
328
|
it 'should DELETE /:user/list to delete list' do
|
329
|
-
@rubytter.should_receive(:delete).with("/test/lists/foo", {})
|
329
|
+
@rubytter.should_receive(:delete).with("/1/test/lists/foo", {})
|
330
330
|
@rubytter.delete_list('foo')
|
331
331
|
end
|
332
332
|
|
333
333
|
it 'should GET lists for specified user' do
|
334
|
-
@rubytter.should_receive(:get).with("/jugyo/lists", {})
|
334
|
+
@rubytter.should_receive(:get).with("/1/jugyo/lists", {})
|
335
335
|
@rubytter.lists('jugyo')
|
336
336
|
end
|
337
337
|
|
338
338
|
it 'should add member to list' do
|
339
|
-
@rubytter.should_receive(:post).with("/test/foo/members", {:id=>"jugyo"})
|
339
|
+
@rubytter.should_receive(:post).with("/1/test/foo/members", {:id=>"jugyo"})
|
340
340
|
@rubytter.add_member_to_list('foo', 'jugyo')
|
341
341
|
end
|
342
342
|
|
343
343
|
it 'should remove member to list' do
|
344
|
-
@rubytter.should_receive(:delete).with("/test/foo/members", {:id=>"jugyo"})
|
344
|
+
@rubytter.should_receive(:delete).with("/1/test/foo/members", {:id=>"jugyo"})
|
345
345
|
@rubytter.remove_member_from_list('foo', 'jugyo')
|
346
346
|
end
|
347
347
|
|
@@ -352,7 +352,7 @@ class Rubytter
|
|
352
352
|
rubytter = OAuthRubytter.new(access_token)
|
353
353
|
response = simple_mock(:body => '{}', :code => '200')
|
354
354
|
access_token.should_receive(:post).with(
|
355
|
-
"/statuses/update.json",
|
355
|
+
"/1/statuses/update.json",
|
356
356
|
{'status' => 'test'},
|
357
357
|
{"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
|
358
358
|
).and_return(response)
|
@@ -364,7 +364,7 @@ class Rubytter
|
|
364
364
|
rubytter = OAuthRubytter.new(access_token)
|
365
365
|
response = simple_mock(:body => '{}', :code => '200')
|
366
366
|
access_token.should_receive(:get).with(
|
367
|
-
'/statuses/friends_timeline.json',
|
367
|
+
'/1/statuses/friends_timeline.json',
|
368
368
|
{"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
|
369
369
|
).and_return(response)
|
370
370
|
rubytter.friends_timeline
|
@@ -375,7 +375,7 @@ class Rubytter
|
|
375
375
|
rubytter = OAuthRubytter.new(access_token)
|
376
376
|
response = simple_mock(:body => '{}', :code => '200')
|
377
377
|
access_token.should_receive(:get).with(
|
378
|
-
'/statuses/friends_timeline.json?page=2',
|
378
|
+
'/1/statuses/friends_timeline.json?page=2',
|
379
379
|
{"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
|
380
380
|
).and_return(response)
|
381
381
|
rubytter.friends_timeline(:page => 2)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 1.3.
|
8
|
+
- 2
|
9
|
+
version: 1.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jugyo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-13 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|