twitter4r 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGES +129 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +37 -0
  4. data/TODO +7 -0
  5. data/lib/twitter/client/account.rb +24 -0
  6. data/lib/twitter/client/base.rb +16 -5
  7. data/lib/twitter/client/blocks.rb +35 -0
  8. data/lib/twitter/client/favorites.rb +37 -37
  9. data/lib/twitter/client/friendship.rb +32 -32
  10. data/lib/twitter/client/graph.rb +37 -0
  11. data/lib/twitter/client/messaging.rb +3 -4
  12. data/lib/twitter/client/profile.rb +29 -0
  13. data/lib/twitter/client/search.rb +27 -0
  14. data/lib/twitter/client/status.rb +9 -3
  15. data/lib/twitter/client/timeline.rb +1 -0
  16. data/lib/twitter/client/user.rb +20 -9
  17. data/lib/twitter/client.rb +13 -9
  18. data/lib/twitter/config.rb +6 -0
  19. data/lib/twitter/console.rb +3 -0
  20. data/lib/twitter/core.rb +1 -1
  21. data/lib/twitter/ext/stdlib.rb +17 -1
  22. data/lib/twitter/model.rb +39 -10
  23. data/lib/twitter/version.rb +1 -1
  24. data/lib/twitter.rb +13 -4
  25. data/spec/twitter/client/account_spec.rb +28 -0
  26. data/spec/twitter/client/base_spec.rb +10 -0
  27. data/spec/twitter/client/blocks_spec.rb +76 -0
  28. data/spec/twitter/client/friendship_spec.rb +7 -7
  29. data/spec/twitter/client/graph_spec.rb +67 -0
  30. data/spec/twitter/client/messaging_spec.rb +3 -3
  31. data/spec/twitter/client/profile_spec.rb +91 -0
  32. data/spec/twitter/client/search_spec.rb +68 -0
  33. data/spec/twitter/client/status_spec.rb +27 -0
  34. data/spec/twitter/client/user_spec.rb +0 -17
  35. data/spec/twitter/ext/stdlib_spec.rb +20 -3
  36. data/spec/twitter/model_spec.rb +46 -26
  37. metadata +92 -67
  38. data/lib/twitter/rails.rb +0 -89
  39. data/spec/twitter/rails_spec.rb +0 -110
data/CHANGES ADDED
@@ -0,0 +1,129 @@
1
+ = CHANGES
2
+
3
+ Catalog(ue) of changes for Twitter4R 0.1.x releases including Retrospectiva ticket cross-reference numbers. Refer to http://retro.tautology.net/projects/twitter4r/tickets for more information.
4
+
5
+ == 0.3.1 Changes
6
+ *
7
+ * Added specs for Twitter::Client#profile (:info, :colors and :device cases)
8
+ * Added Twitter4R shell
9
+ * Improved code coverage for twitter/ext/stdlib code and removed hard coded extension in GET request path for retrieving account information
10
+ * Changed Twitter::RESTError super class to be RuntimeError instead of Exception
11
+ * Added URI.encode => CGI.escape fix
12
+ * Added block methods
13
+ * Added Twitter::Client#inspect method to XXXX out passwords
14
+ * Minor refactoring of spec/spec_helper.rb
15
+ * Added support for :page, :lite and :since options for Twitter::User#followers, Twitter::Client#my([:friends|:followers]...) and Twitter::Client#user([:friends|:followers]...)calls
16
+ * Added Twitter::Client.status(:replies) support
17
+
18
+
19
+ == 0.3.0 Changes
20
+ * Bunch of changes, but forgot to track them and too lazy to look through the SVN/Git logs. Sorry.
21
+
22
+ == 0.2.5 Changes
23
+
24
+ === 2007-09-23
25
+ * Added paging support as per Sergio Santos' request (#36).
26
+
27
+ == 0.2.4 Changes
28
+
29
+ === 2007-07-24
30
+ * Fixed ActiveSupport +Time#to_s+ conflict such that integration with Rails is much less painful (#34)
31
+
32
+ == 0.2.3 Changes
33
+
34
+ === 2007-07-22
35
+ * Fixed defect #31 such that passing string screen name as for user argument is handled correctly.
36
+ * Fixed #30 typo: respond_to -> respond_to?
37
+ * Added relevant exception handling for #message(:post, ...) case (#32)
38
+ * Add ability to pass in Twitter::User object to Twitter::Client#user(...) #33
39
+ * Added stats Rake task
40
+ * Updated RDoc for Twitter::Client#user to warn against using it to get followers of authenticated user and updated ArgumentError raising logic as per #29.
41
+
42
+ == 0.2.2 Changes
43
+
44
+ === 2007-07-18
45
+ * Fixed URI paths for user, messaging and friendship APIs (#25)
46
+ * Added action checks for Twitter::Client methods: #user, #my, #message, #messages, #status, #timeline, #friend (#26)
47
+ * Added 'source' configuration documentation.
48
+ * Added missing attributes for Twitter::User (#28)
49
+
50
+ == 0.2.1 Changes
51
+
52
+ === 2007-07-17
53
+ * Added 'source' feature and configurability.
54
+
55
+ == 0.2.0 Changes
56
+
57
+ === 2007-07-08
58
+ * Added featured users API as an "extra" (#19).
59
+ * Productionized website for publishing.
60
+ * Published Ruby Gem on Rubyforge.
61
+
62
+ === 2007-07-07
63
+ * Refactored Twitter4R API to be more consistent, by grouping APIs (#6):
64
+ - Messaging APIs: direct_messages, new, destroy, replies
65
+ - Friendship APIs: create, destroy
66
+ * Added following features (#7):
67
+ - Retrieving direct messages
68
+ - User APIs: friends, followers, show
69
+ * Updated documentation and example code.
70
+
71
+ === 2007-07-06
72
+ * Refactored Twitter4R API to be more consistent, by grouping APIs (#6):
73
+ - Status APIs: show, update, destroy
74
+ - User APIs: friends, followers, show
75
+ * Added X-Twitter-Client HTTP headers and Twitter::Config options (#16)
76
+ * Removed redundant feature (#8):
77
+ - Followers timeline
78
+ * Refactored HTTP request/response code to DRY up code.
79
+ * Fix REST error handling to use #is_a?(HTTPSuccess) instead of code in ['200', '201'] to determine REST error (#15).
80
+
81
+ === 2007-06-25
82
+ * Updated example documentation (#14)
83
+ * Refactored marshaling unmarshaling code (#13)
84
+
85
+ === 2007-06-20
86
+ * Added proxy user/pass support. Tested only via endo-testing. (No system/integration testing behind real proxy as I do not have that environment).
87
+
88
+
89
+ === 2007-06-17
90
+ * Refactored Twitter4R API to be more consistent, by grouping APIs (#6):
91
+ - Timeline APIs: public, friends, user
92
+
93
+ === 2007-06-13
94
+ * Added RSpec Autotest integration
95
+ * Fixed Twitter::Meta generation of spec for hash values
96
+ * Added HTTP header to each request including generated User-Agent header
97
+ * Added RCovMorpher and template to restyle RCov output upon release
98
+ * Added Gemspec dependencies and requirements
99
+ * Added default tidy YAML configuration file for RCovMorpher
100
+ * Added Contributors list and updated external dependencies list to README
101
+ * Removed shebang from examples
102
+
103
+ === 2007-06-12
104
+ * Added proxy support as per Kaiichi Matsunaga submitted patch (#11).
105
+ * Added SSL support (#12)
106
+
107
+ === 2007-05-19
108
+ * Translated RSpec specifications from 0.8.2 compliant to 1.0.0 (#10)
109
+
110
+ == 0.1.1 Changes
111
+
112
+ === 2007-06-25
113
+ * Added SSL support (#12)
114
+ * Added Proxy support (#11)
115
+
116
+ == 0.1.0 Changes
117
+
118
+ === 2007-05-08
119
+ * Added Google Analytics Javascript code to website pages (#5)
120
+
121
+ === 2007-05-07
122
+ * Fixed errors in online sample code documentation and redeployed website (#2 and #3)
123
+ * Created more consistent RDoc theme to go more with website home page (#4)
124
+
125
+ === 2007-05-06
126
+ * Initial revision of codebase commited; includes:
127
+ - Achieved 80% Twitter API feature-completeness
128
+ - Attained 100% RSpec C0 code coverage
129
+ - Rake tasks for: RSpec, RCov, RDoc, Gem, Rubyforge Publishing, etc.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2007 Susan Potter <me _at_ susanpotter _dot_ net>.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,37 @@
1
+ = Twitter4R
2
+
3
+ * Project Website - http://twitter4r.rubyforge.org
4
+ * Mailing List - http://groups.google.com/group/twitter4r-users
5
+
6
+ == Developers
7
+ * {Susan Potter}[http://SusanPotter.NET] <me at susanpotter dot net>
8
+
9
+ == Contributors
10
+ Code:
11
+ * Kaiichi Matsunaga <ma2 at lifemedia dot co dot jp> - proxy code suggestion
12
+ * Sergio Santos <> - message paging code suggestion
13
+ * Adam Stiles <adam at stilesoft dot com> - URI.encode => CGI.escape fix
14
+ * Carl Crawley <cwcrawley at gmail dot com> - Friendship get => post fix
15
+ * Christian Johansen <christian at cjohansen dot no> - in_reply_to attributes in Twitter::Status
16
+
17
+ Design Suggestions:
18
+ * Bosco So <rubymeetup at boscoso dot com> - making Twitter::Error a RuntimeError instead of an Exception to prevent irb from crashing out.
19
+
20
+ == Description
21
+ Twitter4R provides an object based API to query or update your Twitter account via pure Ruby. It hides the ugly HTTP/REST code from your code.
22
+
23
+ == External Dependencies
24
+ * Ruby 1.8 (tested with 1.8.6)
25
+ * RSpec gem 1.0.0+ (tested with 1.1.3)
26
+ * JSON gem 0.4.3+ (tested with versions: 1.1.1 and 1.1.2)
27
+ * jcode (for unicode support)
28
+
29
+ == Usage Examples
30
+ Twitter4R starting with version 0.1.1 and above is organized into seven parts:
31
+ * {Configuration API}[link:files/examples/configure_rb.html]
32
+ * {Friendship API}[link:files/examples/friendship_rb.html]
33
+ * {Messaging API}[link:files/examples/messaging_rb.html]
34
+ * {Model API}[link:files/examples/model_rb.html]
35
+ * {Status API}[link:files/examples/status_rb.html]
36
+ * {Timeline API}[link:files/examples/timeline_rb.html]
37
+ * {User API}[link:files/examples/user_rb.html]
data/TODO ADDED
@@ -0,0 +1,7 @@
1
+
2
+ 0.3.1 TODO:
3
+ * Add specs for :page, :lite and :since options support in Twitter::Client#my(...), Twitter::Client#user(....) and Twitter::User#followers calls
4
+ * Add specs for :replies support in Twitter::Client#status(...) and Twitter::Client#timeline_for(...)
5
+ * Add RDoc for :replies support
6
+ * Add better RDoc for Twitter::Client.account_info(:rate_limit_status)
7
+ * Add specs for Twitter::Client.account_info(:rate_limit_status)
@@ -0,0 +1,24 @@
1
+ class Twitter::Client
2
+ @@ACCOUNT_URIS = {
3
+ :rate_limit_status => '/account/rate_limit_status',
4
+ }
5
+
6
+ # Provides access to the Twitter rate limit status API.
7
+ #
8
+ # You can find out information about your account status. Currently the only
9
+ # supported type of account status is the <tt>:rate_limit_status</tt> which
10
+ # returns a <tt>Twitter::RateLimitStatus</tt> object.
11
+ #
12
+ # Example:
13
+ # account_status = client.account_info
14
+ # puts account_status.remaining_hits
15
+ def account_info(type = :rate_limit_status)
16
+ connection = create_http_connection
17
+ connection.start do |connection|
18
+ response = http_connect do |conn|
19
+ create_http_get_request(@@ACCOUNT_URIS[type])
20
+ end
21
+ bless_models(Twitter::RateLimitStatus.unmarshal(response.body))
22
+ end
23
+ end
24
+ end
@@ -1,11 +1,16 @@
1
1
  class Twitter::Client
2
+ alias :old_inspect :inspect
3
+ def inspect
4
+ s = old_inspect
5
+ s.gsub!(/@password=".*?"/, '@password="XXXX"')
6
+ end
2
7
  protected
3
8
  attr_accessor :login, :password
4
9
 
5
10
  # Returns the response of the HTTP connection.
6
- def http_connect(body = nil, require_auth = true, &block)
11
+ def http_connect(body = nil, require_auth = true, service = :rest, &block)
7
12
  require_block(block_given?)
8
- connection = create_http_connection
13
+ connection = create_http_connection(service)
9
14
  connection.start do |connection|
10
15
  request = yield connection if block_given?
11
16
  request.basic_auth(@login, @password) if require_auth
@@ -40,11 +45,17 @@ class Twitter::Client
40
45
  end
41
46
  end
42
47
 
43
- def create_http_connection
44
- conn = Net::HTTP.new(@@config.host, @@config.port,
48
+ def create_http_connection(service = :rest)
49
+ case service
50
+ when :rest
51
+ protocol, host, port = @@config.protocol, @@config.host, @@config.port
52
+ when :search
53
+ protocol, host, port = @@config.search_protocol, @@config.search_host, @@config.search_port
54
+ end
55
+ conn = Net::HTTP.new(host, port,
45
56
  @@config.proxy_host, @@config.proxy_port,
46
57
  @@config.proxy_user, @@config.proxy_pass)
47
- if @@config.protocol == :ssl
58
+ if protocol == :ssl
48
59
  conn.use_ssl = true
49
60
  conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
61
  end
@@ -0,0 +1,35 @@
1
+ class Twitter::Client
2
+ @@BLOCK_URIS = {
3
+ :add => '/blocks/create',
4
+ :remove => '/blocks/destroy',
5
+ }
6
+
7
+ # Provides access to the Twitter Block API.
8
+ #
9
+ # You can add and remove blocks to users using this method.
10
+ #
11
+ # <tt>action</tt> can be any of the following values:
12
+ # * <tt>:add</tt> - to add a block, you would use this <tt>action</tt> value
13
+ # * <tt>:remove</tt> - to remove a block use this.
14
+ #
15
+ # The <tt>value</tt> must be either the user screen name, integer unique user ID or Twitter::User
16
+ # object representation.
17
+ #
18
+ # Examples:
19
+ # screen_name = 'dictionary'
20
+ # client.block(:add, 'dictionary')
21
+ # client.block(:remove, 'dictionary')
22
+ # id = 1260061
23
+ # client.block(:add, id)
24
+ # client.block(:remove, id)
25
+ # user = Twitter::User.find(id, client)
26
+ # client.block(:add, user)
27
+ # client.block(:remove, user)
28
+ def block(action, value)
29
+ raise ArgumentError, "Invalid friend action provided: #{action}" unless @@BLOCK_URIS.keys.member?(action)
30
+ value = value.to_i unless value.is_a?(String)
31
+ uri = "#{@@BLOCK_URIS[action]}/#{value}.json"
32
+ response = http_connect {|conn| create_http_get_request(uri) }
33
+ bless_model(Twitter::User.unmarshal(response.body))
34
+ end
35
+ end
@@ -1,9 +1,9 @@
1
1
  class Twitter::Client
2
2
  # Why Twitter.com developers can't correctly document their API, I do not know!
3
- @@FAVORITES_URIS = {
4
- :add => '/favourings/create',
5
- :remove => '/favourings/destroy',
6
- }
3
+ @@FAVORITES_URIS = {
4
+ :add => '/favourings/create',
5
+ :remove => '/favourings/destroy',
6
+ }
7
7
 
8
8
  # Provides access to the Twitter list favorites API.
9
9
  #
@@ -13,41 +13,41 @@ class Twitter::Client
13
13
  # To get a previous page you can provide options to this method. For example,
14
14
  # statuses = client.favorites(:page => 2)
15
15
  # The above one-liner will get the second page of favorites for the authenticated user.
16
- def favorites(options = nil)
17
- def uri_suffix(opts); opts && opts[:page] ? "?page=#{opts[:page]}" : ""; end
16
+ def favorites(options = nil)
17
+ def uri_suffix(opts); opts && opts[:page] ? "?page=#{opts[:page]}" : ""; end
18
18
  uri = '/favorites.json' + uri_suffix(options)
19
19
  response = http_connect {|conn| create_http_get_request(uri) }
20
20
  bless_models(Twitter::Status.unmarshal(response.body))
21
- end
21
+ end
22
22
 
23
- # Provides access to the Twitter add/remove favorite API.
24
- #
25
- # You can add and remove favorite status using this method.
26
- #
27
- # <tt>action</tt> can be any of the following values:
28
- # * <tt>:add</tt> - to add a status to your favorites, you would use this <tt>action</tt> value
29
- # * <tt>:remove</tt> - to remove an status from your existing favorites list use this.
30
- #
31
- # The <tt>value</tt> must be either the status object to add or remove or
32
- # the integer unique status ID.
33
- #
34
- # Examples:
35
- # id = 126006103423
36
- # client.favorite(:add, id)
37
- # client.favorite(:remove, id)
38
- # status = Twitter::Status.find(id, client)
39
- # client.favorite(:add, status)
40
- # client.favorite(:remove, status)
41
- def favorite(action, value)
42
- raise ArgumentError, "Invalid favorite action provided: #{action}" unless @@FAVORITES_URIS.keys.member?(action)
43
- value = value.to_i.to_s unless value.is_a?(String)
44
- uri = "#{@@FAVORITES_URIS[action]}/#{value}.json"
45
- case action
46
- when :add
47
- response = http_connect {|conn| create_http_post_request(uri) }
48
- when :remove
49
- response = http_connect {|conn| create_http_delete_request(uri) }
50
- end
51
- bless_model(Twitter::Status.unmarshal(response.body))
52
- end
23
+ # Provides access to the Twitter add/remove favorite API.
24
+ #
25
+ # You can add and remove favorite status using this method.
26
+ #
27
+ # <tt>action</tt> can be any of the following values:
28
+ # * <tt>:add</tt> - to add a status to your favorites, you would use this <tt>action</tt> value
29
+ # * <tt>:remove</tt> - to remove an status from your existing favorites list use this.
30
+ #
31
+ # The <tt>value</tt> must be either the status object to add or remove or
32
+ # the integer unique status ID.
33
+ #
34
+ # Examples:
35
+ # id = 126006103423
36
+ # client.favorite(:add, id)
37
+ # client.favorite(:remove, id)
38
+ # status = Twitter::Status.find(id, client)
39
+ # client.favorite(:add, status)
40
+ # client.favorite(:remove, status)
41
+ def favorite(action, value)
42
+ raise ArgumentError, "Invalid favorite action provided: #{action}" unless @@FAVORITES_URIS.keys.member?(action)
43
+ value = value.to_i.to_s unless value.is_a?(String)
44
+ uri = "#{@@FAVORITES_URIS[action]}/#{value}.json"
45
+ case action
46
+ when :add
47
+ response = http_connect {|conn| create_http_post_request(uri) }
48
+ when :remove
49
+ response = http_connect {|conn| create_http_delete_request(uri) }
50
+ end
51
+ bless_model(Twitter::Status.unmarshal(response.body))
52
+ end
53
53
  end
@@ -1,35 +1,35 @@
1
1
  class Twitter::Client
2
- @@FRIENDSHIP_URIS = {
3
- :add => '/friendships/create',
4
- :remove => '/friendships/destroy',
5
- }
2
+ @@FRIENDSHIP_URIS = {
3
+ :add => '/friendships/create',
4
+ :remove => '/friendships/destroy',
5
+ }
6
6
 
7
- # Provides access to the Twitter Friendship API.
8
- #
9
- # You can add and remove friends using this method.
10
- #
11
- # <tt>action</tt> can be any of the following values:
12
- # * <tt>:add</tt> - to add a friend, you would use this <tt>action</tt> value
13
- # * <tt>:remove</tt> - to remove an existing friend from your friends list use this.
14
- #
15
- # The <tt>value</tt> must be either the user to befriend or defriend's
16
- # screen name, integer unique user ID or Twitter::User object representation.
17
- #
18
- # Examples:
19
- # screen_name = 'dictionary'
20
- # client.friend(:add, 'dictionary')
21
- # client.friend(:remove, 'dictionary')
22
- # id = 1260061
23
- # client.friend(:add, id)
24
- # client.friend(:remove, id)
25
- # user = Twitter::User.find(id, client)
26
- # client.friend(:add, user)
27
- # client.friend(:remove, user)
28
- def friend(action, value)
29
- raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
30
- value = value.to_i unless value.is_a?(String)
31
- uri = "#{@@FRIENDSHIP_URIS[action]}/#{value}.json"
32
- response = http_connect {|conn| create_http_get_request(uri) }
33
- bless_model(Twitter::User.unmarshal(response.body))
34
- end
7
+ # Provides access to the Twitter Friendship API.
8
+ #
9
+ # You can add and remove friends using this method.
10
+ #
11
+ # <tt>action</tt> can be any of the following values:
12
+ # * <tt>:add</tt> - to add a friend, you would use this <tt>action</tt> value
13
+ # * <tt>:remove</tt> - to remove an existing friend from your friends list use this.
14
+ #
15
+ # The <tt>value</tt> must be either the user to befriend or defriend's
16
+ # screen name, integer unique user ID or Twitter::User object representation.
17
+ #
18
+ # Examples:
19
+ # screen_name = 'dictionary'
20
+ # client.friend(:add, 'dictionary')
21
+ # client.friend(:remove, 'dictionary')
22
+ # id = 1260061
23
+ # client.friend(:add, id)
24
+ # client.friend(:remove, id)
25
+ # user = Twitter::User.find(id, client)
26
+ # client.friend(:add, user)
27
+ # client.friend(:remove, user)
28
+ def friend(action, value)
29
+ raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
30
+ value = value.to_i unless value.is_a?(String)
31
+ uri = "#{@@FRIENDSHIP_URIS[action]}/#{value}.json"
32
+ response = http_connect {|conn| create_http_post_request(uri) }
33
+ bless_model(Twitter::User.unmarshal(response.body))
34
+ end
35
35
  end
@@ -0,0 +1,37 @@
1
+ class Twitter::Client
2
+ @@GRAPH_URIS = {
3
+ :friends => '/friends/ids',
4
+ :followers => '/followers/ids',
5
+ }
6
+
7
+ # Provides access to the Twitter Social Graphing API.
8
+ #
9
+ # You can retrieve the full graph of a user's friends or followers in one method call.
10
+ #
11
+ # <tt>action</tt> can be any of the following values:
12
+ # * <tt>:friends</tt> - retrieves ids of all friends of a given user.
13
+ # * <tt>:followers</tt> - retrieves ids of all followers of a given user.
14
+ #
15
+ # The <tt>value</tt> must be either the user screen name, integer unique user ID or Twitter::User
16
+ # object representation.
17
+ #
18
+ # Examples:
19
+ # screen_name = 'dictionary'
20
+ # client.graph(:friends, 'dictionary')
21
+ # client.graph(:followers, 'dictionary')
22
+ # id = 1260061
23
+ # client.graph(:friends, id)
24
+ # client.graph(:followers, id)
25
+ # user = Twitter::User.find(id, client)
26
+ # client.graph(:friends, user)
27
+ # client.graph(:followers, user)
28
+ def graph(action, value = nil)
29
+ raise ArgumentError, "Invalid friend action provided: #{action}" unless @@GRAPH_URIS.keys.member?(action)
30
+ id = value.to_i unless value.nil? || value.is_a?(String)
31
+ id ||= value
32
+ id ||= @login
33
+ uri = "#{@@GRAPH_URIS[action]}.json"
34
+ response = http_connect {|conn| create_http_get_request(uri, :id => id) }
35
+ JSON.parse(response.body)
36
+ end
37
+ end
@@ -17,11 +17,10 @@ class Twitter::Client
17
17
  # is given. Valid actions are:
18
18
  # * +:received+
19
19
  # * +:sent+
20
- def messages(action, options = nil)
21
- def uri_suffix(opts); opts && opts[:page] ? "?page=#{opts[:page]}" : ""; end
20
+ def messages(action, options = {})
22
21
  raise ArgumentError, "Invalid messaging action: #{action}" unless [:sent, :received].member?(action)
23
- uri = @@MESSAGING_URIS[action] + uri_suffix(options)
24
- response = http_connect {|conn| create_http_get_request(uri) }
22
+ uri = @@MESSAGING_URIS[action]
23
+ response = http_connect {|conn| create_http_get_request(uri, options) }
25
24
  bless_models(Twitter::Message.unmarshal(response.body))
26
25
  end
27
26
 
@@ -0,0 +1,29 @@
1
+ class Twitter::Client
2
+ @@PROFILE_URIS = {
3
+ :info => '/account/update_profile',
4
+ :colors => '/account/update_profile_colors',
5
+ :device => '/account/update_delivery_device',
6
+ }
7
+
8
+ # Provides access to the Twitter Profile API.
9
+ #
10
+ # You can update profile information. You can update the types of profile
11
+ # information:
12
+ # * :info (name, email, url, location, description)
13
+ # * :colors (background_color, text_color, link_color, sidebar_fill_color,
14
+ # sidebar_border_color)
15
+ # * :device (set device to either "sms", "im" or "none")
16
+ #
17
+ # Example:
18
+ # user = client.profile(:info, :location => "University Library")
19
+ # puts user.inspect
20
+ def profile(action, attributes)
21
+ connection = create_http_connection
22
+ connection.start do |connection|
23
+ response = http_connect(attributes.to_http_str) do |conn|
24
+ create_http_post_request(@@PROFILE_URIS[action])
25
+ end
26
+ bless_models(Twitter::User.unmarshal(response.body))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ class Twitter::Client
2
+
3
+ @@SEARCH_URIS = {
4
+ :basic => "/search.json",
5
+ }
6
+
7
+ # Provides access to Twitter's Search API.
8
+ #
9
+ # Example:
10
+ # # For keyword search
11
+ # iterator = @twitter.search(:q => "coworking")
12
+ # while (tweet = iterator.next)
13
+ # puts tweet.text
14
+ # end
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+
20
+ def search(options = {})
21
+ # raise ArgumentError, "Invalid messaging action: #{action}"
22
+ uri = @@SEARCH_URIS[:basic]
23
+ response = http_connect(nil, false, :search) {|conn| create_http_get_request(uri, options) }
24
+ json = JSON.parse(response.body)
25
+ bless_models(Twitter::Status.unmarshal(JSON.dump(json["results"])))
26
+ end
27
+ end
@@ -3,6 +3,7 @@ class Twitter::Client
3
3
  :get => '/statuses/show.json',
4
4
  :post => '/statuses/update.json',
5
5
  :delete => '/statuses/destroy.json',
6
+ :reply => '/statuses/update.json',
6
7
  }
7
8
 
8
9
  # Provides access to individual statuses via Twitter's Status APIs
@@ -11,6 +12,7 @@ class Twitter::Client
11
12
  # * <tt>:get</tt> to retrieve status content. Assumes <tt>value</tt> given responds to :to_i message in meaningful way to yield intended status id.
12
13
  # * <tt>:post</tt> to publish a new status
13
14
  # * <tt>:delete</tt> to remove an existing status. Assumes <tt>value</tt> given responds to :to_i message in meaningful way to yield intended status id.
15
+ # * <tt>:reply</tt> to reply to an existing status. Assumes <tt>value</tt> given is <tt>Hash</tt> which contains <tt>:in_reply_to_status_id</tt> and <tt>:status</tt>
14
16
  #
15
17
  # <tt>value</tt> should be set to:
16
18
  # * the status identifier for <tt>:get</tt> case
@@ -27,11 +29,12 @@ class Twitter::Client
27
29
  # * +:get+
28
30
  # * +:post+
29
31
  # * +:delete+
30
- def status(action, value)
32
+ def status(action, value = nil)
33
+ return self.timeline_for(action, value || {}) if :replies == action
31
34
  raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action)
32
35
  return nil unless value
33
- uri = @@STATUS_URIS[action]
34
- response = nil
36
+ uri = @@STATUS_URIS[action]
37
+ response = nil
35
38
  case action
36
39
  when :get
37
40
  response = http_connect {|conn| create_http_get_request(uri, :id => value.to_i) }
@@ -39,6 +42,9 @@ class Twitter::Client
39
42
  response = http_connect({:status => value, :source => @@config.source}.to_http_str) {|conn| create_http_post_request(uri) }
40
43
  when :delete
41
44
  response = http_connect {|conn| create_http_delete_request(uri, :id => value.to_i) }
45
+ when :reply
46
+ return nil if (!value.is_a?(Hash) || !value[:status] || !value[:in_reply_to_status_id])
47
+ response = http_connect(value.merge(:source => @@config.source).to_http_str) {|conn| create_http_post_request(uri) }
42
48
  end
43
49
  bless_model(Twitter::Status.unmarshal(response.body))
44
50
  end
@@ -5,6 +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
+ :replies => '/statuses/replies.json',
8
9
  }
9
10
 
10
11
  # Provides access to Twitter's Timeline APIs