twitter4r 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/twitter/client/messaging.rb +7 -2
- data/lib/twitter/client/user.rb +11 -3
- data/lib/twitter/model.rb +2 -2
- data/lib/twitter/version.rb +1 -1
- data/spec/twitter/client/messaging_spec.rb +12 -0
- data/spec/twitter/client/user_spec.rb +51 -5
- data/spec/twitter/model_spec.rb +32 -2
- metadata +2 -3
- data/spec/twitter/deprecated_spec.rb +0 -177
@@ -36,7 +36,7 @@ class Twitter::Client
|
|
36
36
|
# * <tt>Integer</tt> or <tt>Twitter::Message</tt> object when action is <tt>:delete</tt>. Will refer to the unique message ID to delete. When passing in an instance of <tt>Twitter::Message</tt> that Status will be
|
37
37
|
#
|
38
38
|
# <tt>user</tt> should be:
|
39
|
-
# * <tt>Twitter::User</tt> or <tt>
|
39
|
+
# * <tt>Twitter::User</tt>, <tt>Integer</tt> or <tt>String</tt> object when <tt>action</tt> is <tt>:post</tt>. The <tt>Integer</tt> must be the unique ID of the Twitter user you wish to send the direct message to and any <tt>String</tt>s passed in must be the screen name of the user you wish to send the direct message to.
|
40
40
|
# * totally ignore when <tt>action</tt> is <tt>:delete</tt>. It has no purpose in this use case scenario.
|
41
41
|
#
|
42
42
|
# Examples:
|
@@ -59,12 +59,17 @@ class Twitter::Client
|
|
59
59
|
# is given. Valid actions are:
|
60
60
|
# * +:post+
|
61
61
|
# * +:delete+
|
62
|
+
#
|
63
|
+
# An <tt>ArgumentError</tt> is also raised when no user argument is
|
64
|
+
# supplied when <tt>action</tt> is +:post+.
|
62
65
|
def message(action, value, user = nil)
|
63
66
|
raise ArgumentError, "Invalid messaging action: #{action}" unless [:post, :delete].member?(action)
|
67
|
+
raise ArgumentError, "User argument must be supplied for :post case" if action.eql?(:post) and user.nil?
|
64
68
|
uri = @@MESSAGING_URIS[action]
|
69
|
+
user = user.to_i if user and user.is_a?(Twitter::User)
|
65
70
|
case action
|
66
71
|
when :post
|
67
|
-
response = http_connect({:text => value, :user => user
|
72
|
+
response = http_connect({:text => value, :user => user, :source => @@config.source}.to_http_str) {|conn| create_http_post_request(uri) }
|
68
73
|
when :delete
|
69
74
|
response = http_connect {|conn| create_http_delete_request(uri, :id => value.to_i) }
|
70
75
|
end
|
data/lib/twitter/client/user.rb
CHANGED
@@ -18,8 +18,17 @@ class Twitter::Client
|
|
18
18
|
# is given. Valid actions are:
|
19
19
|
# * +:info+
|
20
20
|
# * +:friends+
|
21
|
+
#
|
22
|
+
# +Note:+ You should not use this method to attempt to retrieve the
|
23
|
+
# authenticated user's followers. Please use any of the following
|
24
|
+
# ways of accessing this list:
|
25
|
+
# followers = client.my(:followers)
|
26
|
+
# OR
|
27
|
+
# followers = client.my(:info).followers
|
21
28
|
def user(id, action = :info)
|
22
|
-
raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.member?(action)
|
29
|
+
raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
|
30
|
+
raise ArgumentError, "Unable to retrieve followers for user: #{id}" if action.eql?(:followers) and not id.eql?(@login)
|
31
|
+
id = id.to_i if id.is_a?(Twitter::User)
|
23
32
|
response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], :id => id) }
|
24
33
|
bless_models(Twitter::User.unmarshal(response.body))
|
25
34
|
end
|
@@ -39,8 +48,7 @@ class Twitter::Client
|
|
39
48
|
def my(action)
|
40
49
|
raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
|
41
50
|
response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], :id => @login) }
|
42
|
-
|
43
|
-
users = Twitter::User.unmarshal(json)
|
51
|
+
users = Twitter::User.unmarshal(response.body)
|
44
52
|
bless_models(users)
|
45
53
|
end
|
46
54
|
end
|
data/lib/twitter/model.rb
CHANGED
@@ -83,7 +83,7 @@ module Twitter
|
|
83
83
|
# If a model class doesn't have a @text attribute defined
|
84
84
|
# the default Object#to_s will be returned as the result.
|
85
85
|
def to_s
|
86
|
-
self.respond_to(:text) ? @text : super.to_s
|
86
|
+
self.respond_to?(:text) ? @text : super.to_s
|
87
87
|
end
|
88
88
|
|
89
89
|
# Returns hash representation of model object instance.
|
@@ -132,7 +132,7 @@ module Twitter
|
|
132
132
|
# Returns an Array of user objects that represents the authenticated
|
133
133
|
# user's friends on Twitter.
|
134
134
|
def followers
|
135
|
-
@client.
|
135
|
+
@client.my(:followers)
|
136
136
|
end
|
137
137
|
|
138
138
|
# Adds given user as a friend. Returns user object as given by
|
data/lib/twitter/version.rb
CHANGED
@@ -100,6 +100,18 @@ describe Twitter::Client, "#message" do
|
|
100
100
|
}.should raise_error(ArgumentError)
|
101
101
|
end
|
102
102
|
|
103
|
+
it "should raise an ArgumentError for :post case if user argument is not supplied" do
|
104
|
+
lambda {
|
105
|
+
@twitter.message(:post, @message)
|
106
|
+
}.should raise_error(ArgumentError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise an ArgumentError for :post case if user argument is nil" do
|
110
|
+
lambda {
|
111
|
+
@twitter.message(:post, @message, nil)
|
112
|
+
}.should raise_error(ArgumentError)
|
113
|
+
end
|
114
|
+
|
103
115
|
after(:each) do
|
104
116
|
nilize(@twitter, @uris, @request, @response, @connection, @sender, @recipient, @message, @attributes)
|
105
117
|
end
|
@@ -48,12 +48,12 @@ describe Twitter::Client, "#user(id, :info)" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should bless model returned when giving numeric user id" do
|
51
|
-
@twitter.should_receive(:bless_model).with(@user).and_return(@
|
51
|
+
@twitter.should_receive(:bless_model).with(@user).and_return(@user)
|
52
52
|
@twitter.user(@id)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should bless model returned when giving screen name" do
|
56
|
-
@twitter.should_receive(:bless_model).with(@user).and_return(@
|
56
|
+
@twitter.should_receive(:bless_model).with(@user).and_return(@user)
|
57
57
|
@twitter.user(@screen_name)
|
58
58
|
end
|
59
59
|
|
@@ -67,14 +67,60 @@ end
|
|
67
67
|
describe Twitter::Client, "#user(id, :friends)" do
|
68
68
|
before(:each) do
|
69
69
|
@twitter = client_context
|
70
|
+
@id = 395784
|
71
|
+
@screen_name = 'cafe_paradiso'
|
72
|
+
@user = Twitter::User.new(
|
73
|
+
:id => @id,
|
74
|
+
:screen_name => @screen_name,
|
75
|
+
:location => 'Urbana, IL'
|
76
|
+
)
|
77
|
+
@json = JSON.unparse(@user.to_hash)
|
78
|
+
@request = mas_net_http_get(:basic_auth => nil)
|
79
|
+
@response = mas_net_http_response(:success, @json)
|
80
|
+
@connection = mas_net_http(@response)
|
81
|
+
@uris = Twitter::Client.class_eval("@@USER_URIS")
|
82
|
+
@twitter.stub!(:create_http_get_request).and_return(@request)
|
83
|
+
Twitter::User.stub!(:unmarshal).and_return(@user)
|
84
|
+
Net::HTTP.stub!(:new).and_return(@connection)
|
70
85
|
end
|
71
86
|
|
72
|
-
it "should " do
|
73
|
-
|
87
|
+
it "should create expected HTTP GET request when giving numeric user id" do
|
88
|
+
@twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @id}).and_return(@request)
|
89
|
+
@twitter.user(@id, :friends)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should invoke #to_i on Twitter::User objecct given" do
|
93
|
+
@user.should_receive(:to_i).and_return(@id)
|
94
|
+
@twitter.user(@user, :friends)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should create expected HTTP GET request when giving Twitter::User object" do
|
98
|
+
@twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @user.to_i}).and_return(@request)
|
99
|
+
@twitter.user(@user, :friends)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should create expected HTTP GET request when giving screen name" do
|
103
|
+
@twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @screen_name}).and_return(@request)
|
104
|
+
@twitter.user(@screen_name, :friends)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should bless model returned when giving numeric id" do
|
108
|
+
@twitter.should_receive(:bless_model).with(@user).and_return(@user)
|
109
|
+
@twitter.user(@id, :friends)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should bless model returned when giving Twitter::User object" do
|
113
|
+
@twitter.should_receive(:bless_model).with(@user).and_return(@user)
|
114
|
+
@twitter.user(@user, :friends)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should bless model returned when giving screen name" do
|
118
|
+
@twitter.should_receive(:bless_model).with(@user).and_return(@user)
|
119
|
+
@twitter.user(@screen_name, :friends)
|
74
120
|
end
|
75
121
|
|
76
122
|
after(:each) do
|
77
|
-
|
123
|
+
nilize(@request, @response, @connection, @twitter, @id, @screen_name, @user)
|
78
124
|
end
|
79
125
|
end
|
80
126
|
|
data/spec/twitter/model_spec.rb
CHANGED
@@ -244,8 +244,8 @@ describe Twitter::User, "#followers" do
|
|
244
244
|
@user.bless(@twitter)
|
245
245
|
end
|
246
246
|
|
247
|
-
it "should delegate to @client.
|
248
|
-
@twitter.should_receive(:
|
247
|
+
it "should delegate to @client.my(:followers)" do
|
248
|
+
@twitter.should_receive(:my).with(:followers)
|
249
249
|
@user.followers
|
250
250
|
end
|
251
251
|
|
@@ -456,3 +456,33 @@ describe Twitter::User, "#defriend" do
|
|
456
456
|
nilize(@twitter, @user, @friend)
|
457
457
|
end
|
458
458
|
end
|
459
|
+
|
460
|
+
describe Twitter::Status, "#to_s" do
|
461
|
+
before(:each) do
|
462
|
+
@text = 'Aloha'
|
463
|
+
@status = Twitter::Status.new(:text => @text)
|
464
|
+
end
|
465
|
+
|
466
|
+
it "should render text attribute" do
|
467
|
+
@status.to_s.should be(@text)
|
468
|
+
end
|
469
|
+
|
470
|
+
after(:each) do
|
471
|
+
nilize(@text, @status)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
describe Twitter::Message, "#to_s" do
|
476
|
+
before(:each) do
|
477
|
+
@text = 'Aloha'
|
478
|
+
@message = Twitter::Message.new(:text => @text)
|
479
|
+
end
|
480
|
+
|
481
|
+
it "should render text attribute" do
|
482
|
+
@message.to_s.should be(@text)
|
483
|
+
end
|
484
|
+
|
485
|
+
after(:each) do
|
486
|
+
nilize(@text, @message)
|
487
|
+
end
|
488
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: twitter4r
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.2.3
|
7
|
+
date: 2007-07-22 00:00:00 -05:00
|
8
8
|
summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- spec/twitter/console_spec.rb
|
56
56
|
- spec/twitter/meta_spec.rb
|
57
57
|
- spec/twitter/config_spec.rb
|
58
|
-
- spec/twitter/deprecated_spec.rb
|
59
58
|
- spec/twitter/client/timeline_spec.rb
|
60
59
|
- spec/twitter/client/base_spec.rb
|
61
60
|
- spec/twitter/client/status_spec.rb
|
@@ -1,177 +0,0 @@
|
|
1
|
-
#describe "Twitter::Client#public_timeline" do
|
2
|
-
# before(:each) do
|
3
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
4
|
-
# @response = mas_net_http_response
|
5
|
-
#
|
6
|
-
# @http = mas_net_http(@response)
|
7
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# it "should delegate work to Twitter::Client#public(:public)" do
|
11
|
-
# @client.should_receive(:timeline).with(:public).once
|
12
|
-
# @client.public_timeline
|
13
|
-
# end
|
14
|
-
#end
|
15
|
-
|
16
|
-
#describe "Twitter::Client#friend_timeline" do
|
17
|
-
# before(:each) do
|
18
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
19
|
-
# @response = mas_net_http_response
|
20
|
-
#
|
21
|
-
# @http = mas_net_http(@response)
|
22
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# it "should delegate work to Twitter::Client#public(:friends)" do
|
26
|
-
# @client.should_receive(:timeline).with(:friends).once
|
27
|
-
# @client.friend_timeline
|
28
|
-
# end
|
29
|
-
#end
|
30
|
-
|
31
|
-
#describe "Twitter::Client#friend_statuses" do
|
32
|
-
# before(:each) do
|
33
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
34
|
-
# @response = mas_net_http_response
|
35
|
-
#
|
36
|
-
# @http = mas_net_http(@response)
|
37
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# it "should delegate work to Twitter::Client#public(:friends_statuses)" do
|
41
|
-
# @client.should_receive(:timeline).with(:friends_statuses).once
|
42
|
-
# @client.friend_statuses
|
43
|
-
# end
|
44
|
-
#end
|
45
|
-
|
46
|
-
#describe "Twitter::Client#follower_statuses" do
|
47
|
-
# before(:each) do
|
48
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
49
|
-
# @response = mas_net_http_response
|
50
|
-
# @http = mas_net_http(@response)
|
51
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# it "should delegate work to Twitter::Client#public(:followers)" do
|
55
|
-
# @client.should_receive(:timeline).with(:followers).once
|
56
|
-
# @client.follower_statuses
|
57
|
-
# end
|
58
|
-
#end
|
59
|
-
|
60
|
-
#describe "Twitter::Client#timeline_request upon 200 HTTP response" do
|
61
|
-
# before(:each) do
|
62
|
-
# @request = mas_net_http_get :basic_auth => nil
|
63
|
-
# @response = mas_net_http_response # defaults to :success
|
64
|
-
#
|
65
|
-
# @http = mas_net_http(@response)
|
66
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
67
|
-
# @header = @client.send(:http_header)
|
68
|
-
# @uris = Twitter::Client.class_eval("@@URIS")
|
69
|
-
#
|
70
|
-
# JSON.stub!(:parse).and_return({})
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
# it "should make GET HTTP request to appropriate URL" do
|
74
|
-
# @uris.keys.each do |type|
|
75
|
-
# Net::HTTP::Get.should_receive(:new).with(@uris[type], @header).and_return(@request)
|
76
|
-
# @client.send(:timeline, type)
|
77
|
-
# end
|
78
|
-
# end
|
79
|
-
#end
|
80
|
-
|
81
|
-
#describe "Twitter::Client#timeline_request upon 403 HTTP response" do
|
82
|
-
# before(:each) do
|
83
|
-
# @request = mas_net_http_get :basic_auth => nil
|
84
|
-
# @response = mas_net_http_response :not_authorized
|
85
|
-
#
|
86
|
-
# @http = mas_net_http(@response)
|
87
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
88
|
-
# @header = @client.send(:http_header)
|
89
|
-
# @uris = Twitter::Client.class_eval("@@URIS")
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# it "should make GET HTTP request to appropriate URL" do
|
93
|
-
# @uris.keys.each do |type|
|
94
|
-
# lambda {
|
95
|
-
# Net::HTTP::Get.should_receive(:new).with(@uris[type], @header).and_return(@request)
|
96
|
-
# @client.send(:timeline, type)
|
97
|
-
# }.should raise_error(Twitter::RESTError)
|
98
|
-
# end
|
99
|
-
# end
|
100
|
-
#end
|
101
|
-
|
102
|
-
#describe "Twitter::Client#timeline_request upon 500 HTTP response" do
|
103
|
-
# before(:each) do
|
104
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
105
|
-
# @response = mas_net_http_response(:server_error)
|
106
|
-
#
|
107
|
-
# @http = mas_net_http(@response)
|
108
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
109
|
-
# @header = @client.send(:http_header)
|
110
|
-
# @uris = Twitter::Client.class_eval("@@URIS")
|
111
|
-
# end
|
112
|
-
|
113
|
-
# it "should make GET HTTP request to appropriate URL" do
|
114
|
-
# @uris.keys.each do |type|
|
115
|
-
# lambda do
|
116
|
-
# Net::HTTP::Get.should_receive(:new).with(@uris[type], @header).and_return(@request)
|
117
|
-
# @client.send(:timeline, type)
|
118
|
-
# end.should raise_error(Twitter::RESTError)
|
119
|
-
# end
|
120
|
-
# end
|
121
|
-
#end
|
122
|
-
|
123
|
-
#describe "Twitter::Client#timeline_request upon 404 HTTP response" do
|
124
|
-
# before(:each) do
|
125
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
126
|
-
# @response = mas_net_http_response(:file_not_found)
|
127
|
-
# @http = mas_net_http(@response)
|
128
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
129
|
-
# @header = @client.send(:http_header)
|
130
|
-
# @uris = Twitter::Client.class_eval("@@URIS")
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# it "should make GET HTTP request to appropriate URL" do
|
134
|
-
# @uris.keys.each do |type|
|
135
|
-
# lambda {
|
136
|
-
# Net::HTTP::Get.should_receive(:new).with(@uris[type], @header).and_return(@request)
|
137
|
-
# @client.send(:timeline, type)
|
138
|
-
# }.should raise_error(Twitter::RESTError)
|
139
|
-
# end
|
140
|
-
# end
|
141
|
-
#end
|
142
|
-
|
143
|
-
#describe "Twitter::Client#timeline(:public)" do
|
144
|
-
# before(:each) do
|
145
|
-
# @host = 'twitter.com'
|
146
|
-
# @port = 443
|
147
|
-
# @protocol = :http
|
148
|
-
# @proxy_host = 'myproxy.host'
|
149
|
-
# @proxy_port = 8080
|
150
|
-
#
|
151
|
-
# Twitter::Client.configure do |conf|
|
152
|
-
# conf.host = @host
|
153
|
-
# conf.port = @port
|
154
|
-
# conf.protocol = @protocol
|
155
|
-
# conf.proxy_host = @proxy_host
|
156
|
-
# conf.proxy_port = @proxy_port
|
157
|
-
# end
|
158
|
-
#
|
159
|
-
# @request = mas_net_http_get(:basic_auth => nil)
|
160
|
-
# @response = mas_net_http_response(:success, '[]')
|
161
|
-
#
|
162
|
-
# @http = mas_net_http(@response)
|
163
|
-
# @client = Twitter::Client.from_config 'config/twitter.yml'
|
164
|
-
# @login = @client.instance_eval("@login")
|
165
|
-
# @password = @client.instance_eval("@password")
|
166
|
-
# end
|
167
|
-
#
|
168
|
-
# it "should connect to the Twitter service via HTTP connection" do
|
169
|
-
# Net::HTTP.should_receive(:new).with(@host, @port, @proxy_host, @proxy_port).once.and_return(@http)
|
170
|
-
# @client.timeline(:public)
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# it " should send HTTP Basic Authentication credentials" do
|
174
|
-
# @request.should_receive(:basic_auth).with(@login, @password).once
|
175
|
-
# @client.timeline(:public)
|
176
|
-
# end
|
177
|
-
#end
|