twitter4r 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/twitter/client/friendship.rb +3 -2
- data/lib/twitter/client/messaging.rb +17 -4
- data/lib/twitter/client/status.rb +6 -0
- data/lib/twitter/client/timeline.rb +10 -1
- data/lib/twitter/client/user.rb +16 -3
- data/lib/twitter/config.rb +1 -1
- data/lib/twitter/model.rb +2 -2
- data/lib/twitter/version.rb +1 -1
- data/spec/twitter/client/friendship_spec.rb +6 -0
- data/spec/twitter/client/messaging_spec.rb +12 -0
- data/spec/twitter/client/status_spec.rb +6 -0
- data/spec/twitter/client/timeline_spec.rb +10 -0
- data/spec/twitter/client/user_spec.rb +33 -0
- metadata +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Twitter::Client
|
|
2
2
|
@@FRIENDSHIP_URIS = {
|
|
3
|
-
:add => '
|
|
4
|
-
:remove => '
|
|
3
|
+
:add => '/friendships/create',
|
|
4
|
+
:remove => '/friendships/destroy',
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
# Provides access to the Twitter Friendship API.
|
|
@@ -26,6 +26,7 @@ class Twitter::Client
|
|
|
26
26
|
# client.friend(:add, user)
|
|
27
27
|
# client.friend(:remove, user)
|
|
28
28
|
def friend(action, value)
|
|
29
|
+
raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
|
|
29
30
|
value = value.to_i unless value.is_a?(String)
|
|
30
31
|
uri = "#{@@FRIENDSHIP_URIS[action]}/#{value}.json"
|
|
31
32
|
response = http_connect {|conn| create_http_get_request(uri) }
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
class Twitter::Client
|
|
2
2
|
|
|
3
3
|
@@MESSAGING_URIS = {
|
|
4
|
-
:received => '
|
|
5
|
-
:sent => '
|
|
6
|
-
:post => '
|
|
7
|
-
:delete => '
|
|
4
|
+
:received => '/direct_messages.json',
|
|
5
|
+
:sent => '/direct_messages/sent.json',
|
|
6
|
+
:post => '/direct_messages/new.json',
|
|
7
|
+
:delete => '/direct_messages/destroy',
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
# Provides access to Twitter's Messaging API for received and
|
|
11
11
|
# sent direct messages.
|
|
12
12
|
#
|
|
13
|
+
# Example:
|
|
14
|
+
# received_messages = @twitter.messages(:received)
|
|
13
15
|
#
|
|
16
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
|
17
|
+
# is given. Valid actions are:
|
|
18
|
+
# * +:received+
|
|
19
|
+
# * +:sent+
|
|
14
20
|
def messages(action)
|
|
21
|
+
raise ArgumentError, "Invalid messaging action: #{action}" unless [:sent, :received].member?(action)
|
|
15
22
|
uri = @@MESSAGING_URIS[action]
|
|
16
23
|
response = http_connect {|conn| create_http_get_request(uri) }
|
|
17
24
|
bless_models(Twitter::Message.unmarshal(response.body))
|
|
@@ -47,7 +54,13 @@ class Twitter::Client
|
|
|
47
54
|
# In both scenarios (<tt>action</tt> is <tt>:post</tt> or
|
|
48
55
|
# <tt>:delete</tt>) a blessed <tt>Twitter::Message</tt> object is
|
|
49
56
|
# returned that represents the newly posted or newly deleted message.
|
|
57
|
+
#
|
|
58
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
|
59
|
+
# is given. Valid actions are:
|
|
60
|
+
# * +:post+
|
|
61
|
+
# * +:delete+
|
|
50
62
|
def message(action, value, user = nil)
|
|
63
|
+
raise ArgumentError, "Invalid messaging action: #{action}" unless [:post, :delete].member?(action)
|
|
51
64
|
uri = @@MESSAGING_URIS[action]
|
|
52
65
|
case action
|
|
53
66
|
when :post
|
|
@@ -22,7 +22,13 @@ class Twitter::Client
|
|
|
22
22
|
# twitter.status(:post, "New Ruby open source project Twitter4R version 0.2.0 released.")
|
|
23
23
|
# twitter.status(:delete, 107790712)
|
|
24
24
|
#
|
|
25
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
|
26
|
+
# is given. Valid actions are:
|
|
27
|
+
# * +:get+
|
|
28
|
+
# * +:post+
|
|
29
|
+
# * +:delete+
|
|
25
30
|
def status(action, value)
|
|
31
|
+
raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action)
|
|
26
32
|
return nil unless value
|
|
27
33
|
uri = @@STATUS_URIS[action]
|
|
28
34
|
response = nil
|
|
@@ -5,7 +5,7 @@ class Twitter::Client
|
|
|
5
5
|
:friend => '/statuses/friends_timeline.json',
|
|
6
6
|
:user => '/statuses/user_timeline.json',
|
|
7
7
|
:me => '/statuses/user_timeline.json',
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
|
|
10
10
|
# Provides access to Twitter's Timeline APIs
|
|
11
11
|
#
|
|
@@ -52,7 +52,16 @@ class Twitter::Client
|
|
|
52
52
|
# timeline = twitter.timeline_for(:me) do |status|
|
|
53
53
|
# puts status.text
|
|
54
54
|
# end
|
|
55
|
+
#
|
|
56
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>type</tt>
|
|
57
|
+
# is given. Valid types are:
|
|
58
|
+
# * +:public+
|
|
59
|
+
# * +:friends+
|
|
60
|
+
# * +:friend+
|
|
61
|
+
# * +:user+
|
|
62
|
+
# * +:me+
|
|
55
63
|
def timeline_for(type, options = {}, &block)
|
|
64
|
+
raise ArgumentError, "Invalid timeline type: #{type}" unless @@TIMELINE_URIS.keys.member?(type)
|
|
56
65
|
uri = @@TIMELINE_URIS[type]
|
|
57
66
|
response = http_connect {|conn| create_http_get_request(uri, options) }
|
|
58
67
|
timeline = Twitter::Status.unmarshal(response.body)
|
data/lib/twitter/client/user.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class Twitter::Client
|
|
2
2
|
@@USER_URIS = {
|
|
3
|
-
:info => '
|
|
4
|
-
:friends => '
|
|
5
|
-
:followers => '
|
|
3
|
+
:info => '/users/show',
|
|
4
|
+
:friends => '/statuses/friends.json',
|
|
5
|
+
:followers => '/statuses/followers.json',
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
# Provides access to Twitter's User APIs
|
|
@@ -13,7 +13,13 @@ class Twitter::Client
|
|
|
13
13
|
# For example,
|
|
14
14
|
# @twitter.user(234943) #=> Twitter::User object instance for user with numeric id of 234943
|
|
15
15
|
# @twitter.user('mylogin') #=> Twitter::User object instance for user with screen name 'mylogin'
|
|
16
|
+
#
|
|
17
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
|
18
|
+
# is given. Valid actions are:
|
|
19
|
+
# * +:info+
|
|
20
|
+
# * +:friends+
|
|
16
21
|
def user(id, action = :info)
|
|
22
|
+
raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.member?(action)
|
|
17
23
|
response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], :id => id) }
|
|
18
24
|
bless_models(Twitter::User.unmarshal(response.body))
|
|
19
25
|
end
|
|
@@ -24,7 +30,14 @@ class Twitter::Client
|
|
|
24
30
|
# * <tt>:info</tt> - Returns user instance for the authenticated user.
|
|
25
31
|
# * <tt>:friends</tt> - Returns Array of users that are authenticated user's friends
|
|
26
32
|
# * <tt>:followers</tt> - Returns Array of users that are authenticated user's followers
|
|
33
|
+
#
|
|
34
|
+
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
|
35
|
+
# is given. Valid actions are:
|
|
36
|
+
# * +:info+
|
|
37
|
+
# * +:friends+
|
|
38
|
+
# * +:followers+
|
|
27
39
|
def my(action)
|
|
40
|
+
raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
|
|
28
41
|
response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], :id => @login) }
|
|
29
42
|
json = response.body
|
|
30
43
|
users = Twitter::User.unmarshal(json)
|
data/lib/twitter/config.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Twitter
|
|
|
15
15
|
# * <tt>application_name</tt> - name of your client application. Defaults to 'Twitter4R'
|
|
16
16
|
# * <tt>application_version</tt> - version of your client application. Defaults to current <tt>Twitter::Version.to_version</tt>.
|
|
17
17
|
# * <tt>application_url</tt> - URL of your client application. Defaults to http://twitter4r.rubyforge.org.
|
|
18
|
-
|
|
18
|
+
# * <tt>source</tt> - the source id given to you by Twitter to identify your application in their web interface. Note: you must contact Twitter.com developer directly so they can configure their servers appropriately.
|
|
19
19
|
class Config
|
|
20
20
|
include ClassUtilMixin
|
|
21
21
|
@@ATTRIBUTES = [
|
data/lib/twitter/model.rb
CHANGED
|
@@ -158,7 +158,7 @@ module Twitter
|
|
|
158
158
|
# Represents a <tt>Twitter</tt> user
|
|
159
159
|
class User
|
|
160
160
|
include ModelMixin
|
|
161
|
-
@@ATTRIBUTES = [:id, :name, :description, :location, :screen_name, :url]
|
|
161
|
+
@@ATTRIBUTES = [:id, :name, :description, :location, :screen_name, :url, :profile_image_url, :protected]
|
|
162
162
|
attr_accessor *@@ATTRIBUTES
|
|
163
163
|
|
|
164
164
|
class << self
|
|
@@ -213,7 +213,7 @@ module Twitter
|
|
|
213
213
|
# user's friends on Twitter.
|
|
214
214
|
def friends
|
|
215
215
|
@client.user(@id, :friends)
|
|
216
|
-
end
|
|
216
|
+
end
|
|
217
217
|
end # User
|
|
218
218
|
|
|
219
219
|
# Represents a status posted to <tt>Twitter</tt> by a <tt>Twitter</tt> user.
|
data/lib/twitter/version.rb
CHANGED
|
@@ -64,6 +64,12 @@ describe Twitter::Client, "#friend" do
|
|
|
64
64
|
@twitter.friend(:remove, @friend)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
it "should raise ArgumentError if action given is not valid" do
|
|
68
|
+
lambda {
|
|
69
|
+
@twitter.friend(:crap, @friend)
|
|
70
|
+
}.should raise_error(ArgumentError)
|
|
71
|
+
end
|
|
72
|
+
|
|
67
73
|
after(:each) do
|
|
68
74
|
nilize(@twitter, @id, @uris, @request, @response, @connection)
|
|
69
75
|
end
|
|
@@ -32,6 +32,12 @@ describe Twitter::Client, "#messages" do
|
|
|
32
32
|
@twitter.messages(:sent)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
it "should raise an ArgumentError when giving an invalid messaging action" do
|
|
36
|
+
lambda {
|
|
37
|
+
@twitter.messages(:crap)
|
|
38
|
+
}.should raise_error(ArgumentError)
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
after(:each) do
|
|
36
42
|
nilize(@twitter, @uris, @request, @response, @connection, @messages)
|
|
37
43
|
end
|
|
@@ -88,6 +94,12 @@ describe Twitter::Client, "#message" do
|
|
|
88
94
|
@twitter.message(:delete, @message)
|
|
89
95
|
end
|
|
90
96
|
|
|
97
|
+
it "should raise an ArgumentError when giving an invalid messaging action" do
|
|
98
|
+
lambda {
|
|
99
|
+
@twitter.message(:crap, @message)
|
|
100
|
+
}.should raise_error(ArgumentError)
|
|
101
|
+
end
|
|
102
|
+
|
|
91
103
|
after(:each) do
|
|
92
104
|
nilize(@twitter, @uris, @request, @response, @connection, @sender, @recipient, @message, @attributes)
|
|
93
105
|
end
|
|
@@ -79,6 +79,12 @@ describe Twitter::Client, "#status" do
|
|
|
79
79
|
@twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @status.to_i}).and_return(@request)
|
|
80
80
|
@twitter.status(:delete, @status)
|
|
81
81
|
end
|
|
82
|
+
|
|
83
|
+
it "should raise an ArgumentError when given an invalid status action" do
|
|
84
|
+
lambda {
|
|
85
|
+
@twitter.status(:crap, nil)
|
|
86
|
+
}.should raise_error(ArgumentError)
|
|
87
|
+
end
|
|
82
88
|
|
|
83
89
|
after(:each) do
|
|
84
90
|
nilize(@twitter)
|
|
@@ -63,6 +63,16 @@ describe Twitter::Client, "Timeline API" do
|
|
|
63
63
|
timeline.should eql(@timeline)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
it "should raise an ArgumentError if type given is not valid" do
|
|
67
|
+
lambda {
|
|
68
|
+
@client.timeline_for(:crap)
|
|
69
|
+
}.should raise_error(ArgumentError)
|
|
70
|
+
|
|
71
|
+
lambda {
|
|
72
|
+
@client.timeline_for(:crap, @params[:friends])
|
|
73
|
+
}.should raise_error(ArgumentError)
|
|
74
|
+
end
|
|
75
|
+
|
|
66
76
|
after(:each) do
|
|
67
77
|
nilize(@client)
|
|
68
78
|
end
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
|
2
2
|
|
|
3
|
+
describe Twitter::Client, "#user(id, :followers)" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@twitter = client_context
|
|
6
|
+
@id = 395783
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should raise ArgumentError" do
|
|
10
|
+
lambda {
|
|
11
|
+
@twitter.user(@id, :followers)
|
|
12
|
+
}.should raise_error(ArgumentError)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after(:each) do
|
|
16
|
+
nilize(@twitter, @id)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
3
20
|
describe Twitter::Client, "#user(id, :info)" do
|
|
4
21
|
before(:each) do
|
|
5
22
|
@twitter = client_context
|
|
@@ -139,3 +156,19 @@ describe Twitter::Client, "#my(:friends)" do
|
|
|
139
156
|
nilize(@request, @response, @connection, @twitter, @friends, @screen_name)
|
|
140
157
|
end
|
|
141
158
|
end
|
|
159
|
+
|
|
160
|
+
describe Twitter::Client, "#my(:invalid_action)" do
|
|
161
|
+
before(:each) do
|
|
162
|
+
@twitter = client_context
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "should raise ArgumentError for invalid user action" do
|
|
166
|
+
lambda {
|
|
167
|
+
@twitter.my(:crap)
|
|
168
|
+
}.should raise_error(ArgumentError)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
after(:each) do
|
|
172
|
+
nilize(@twitter)
|
|
173
|
+
end
|
|
174
|
+
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.2
|
|
7
|
+
date: 2007-07-18 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
|