twitter4r 0.3.2 → 0.5.0

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/README CHANGED
@@ -15,6 +15,8 @@ Code:
15
15
  * Christian Johansen <christian at cjohansen dot no> - in_reply_to attributes in Twitter::Status
16
16
  * Harry Love <harrylove at gmail dot com> - added attributes to Twitter::Status
17
17
  * Filipe Giusti <filipegiusti at gmail dot com> - fixed users/show issue that Twitter.com changed from under us
18
+ * Seth Cousins <seth.cousins at gmail dot com> - added HTTP timeout option and provided a patch that inspired the OAuth support for Twitter4R
19
+ * John McKerrell <@mcknut on twitter> - added geo attribute to Twitter::Message.
18
20
 
19
21
  Design Suggestions:
20
22
  * Bosco So <rubymeetup at boscoso dot com> - making Twitter::Error a RuntimeError instead of an Exception to prevent irb from crashing out.
@@ -13,12 +13,7 @@ class Twitter::Client
13
13
  # account_status = client.account_info
14
14
  # puts account_status.remaining_hits
15
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
16
+ response = rest_oauth_connect(:get, @@ACCOUNT_URIS[type])
17
+ bless_models(Twitter::RateLimitStatus.unmarshal(response.body))
23
18
  end
24
19
  end
@@ -2,26 +2,20 @@ class Twitter::Client
2
2
  @@AUTHENTICATION_URIS = {
3
3
  :verify => '/account/verify_credentials',
4
4
  }
5
-
6
- # Provides access to the Twitter verify credentials API.
7
- #
8
- # You can verify Twitter user credentials with minimal overhead using this method.
5
+
6
+ # Provides access to the Twitter verify credentials API.
7
+ #
8
+ # You can verify Twitter user credentials with minimal overhead using this method.
9
9
  #
10
- # Example:
11
- # client.authenticate?("osxisforlightweights", "l30p@rd_s^cks!")
12
- def authenticate?(login, password)
10
+ # Example:
11
+ # client.authenticate?("osxisforlightweights", "l30p@rd_s^cks!")
12
+ def authenticate?(login, password)
13
13
  verify_credentials(login, password)
14
- end
15
-
16
- private
14
+ end
15
+
16
+ private
17
17
  def verify_credentials(username, passwd)
18
- connection = create_http_connection
19
- connection.start do |connection|
20
- request = create_http_get_request("#{@@AUTHENTICATION_URIS[:verify]}.json")
21
- request.basic_auth(username, passwd)
22
- response = connection.request(request)
23
- response.is_a?(Net::HTTPSuccess) ? true : false
24
- end
18
+ response = rest_oauth_connect(:get, "#{@@AUTHENTICATION_URIS[:verify]}.json")
19
+ response.is_a?(Net::HTTPSuccess) ? true : false
25
20
  end
26
21
  end
27
-
@@ -4,24 +4,37 @@ class Twitter::Client
4
4
  def inspect
5
5
  s = old_inspect
6
6
  s.gsub!(/@password=".*?"/, '@password="XXXX"')
7
+ s.gsub!(/"secret"=>".*?"/, '"secret"=>"XXXX"')
8
+ s
7
9
  end
8
10
 
9
11
  protected
10
- attr_accessor :login, :password
11
-
12
- # Returns the response of the HTTP connection.
13
- def http_connect(body = nil, require_auth = true, service = :rest, &block)
14
- require_block(block_given?)
15
- connection = create_http_connection(service)
16
- connection.start do |connection|
17
- request = yield connection if block_given?
18
- request.basic_auth(@login, @password) if require_auth
19
- response = connection.request(request, body)
20
- handle_rest_response(response)
21
- response
12
+ attr_accessor :login, :oauth_consumer, :oauth_access
13
+
14
+ # Returns the response of the OAuth/HTTP(s) request for REST API requests (not Search)
15
+ def rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
16
+ atoken = rest_access_token
17
+ uri = rest_request_uri(path)
18
+ if [:get, :delete].include?(method)
19
+ response = atoken.send(method, uri, http_header.merge(headers))
20
+ else
21
+ response = atoken.send(method, uri, params, http_header.merge(headers))
22
22
  end
23
+ handle_rest_response(response)
24
+ response
23
25
  end
24
-
26
+
27
+ # Returns the response of the OAuth/HTTP(s) request for Search API requests (not REST)
28
+ def search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
29
+ atoken = search_access_token
30
+ uri = search_request_uri(path)
31
+ if method == :get
32
+ response = atoken.send(method, uri, http_header.merge(headers))
33
+ end
34
+ handle_rest_response(response)
35
+ response
36
+ end
37
+
25
38
  # "Blesses" model object with client information
26
39
  def bless_model(model)
27
40
  model.bless(self) if model
@@ -34,7 +47,43 @@ class Twitter::Client
34
47
 
35
48
  private
36
49
  @@http_header = nil
50
+
51
+ def rest_consumer
52
+ unless @consumer
53
+ @consumer = OAuth::Consumer.new(@oauth_consumer["key"],
54
+ @oauth_consumer["secret"],
55
+ :site => construct_site_url)
56
+ end
57
+ @consumer
58
+ end
59
+
60
+ def rest_access_token
61
+ unless @access_token
62
+ @access_token = OAuth::AccessToken.new(rest_consumer,
63
+ @oauth_access["key"],
64
+ @oauth_access["secret"])
65
+ end
66
+ @access_token
67
+ end
37
68
 
69
+ def search_consumer
70
+ unless @consumer
71
+ @consumer = OAuth::Consumer.new(@oauth_consumer["key"],
72
+ @oauth_consumer["secret"],
73
+ :site => construct_site_url(:search))
74
+ end
75
+ @consumer
76
+ end
77
+
78
+ def search_access_token
79
+ unless @access_token
80
+ @access_token = OAuth::AccessToken.new(search_consumer,
81
+ @oauth_access["key"],
82
+ @oauth_access["secret"])
83
+ end
84
+ @access_token
85
+ end
86
+
38
87
  def raise_rest_error(response, uri = nil)
39
88
  map = JSON.parse(response.body)
40
89
  raise Twitter::RESTError.new(:code => response.code,
@@ -49,23 +98,6 @@ class Twitter::Client
49
98
  end
50
99
  end
51
100
 
52
- def create_http_connection(service = :rest)
53
- case service
54
- when :rest
55
- protocol, host, port = @@config.protocol, @@config.host, @@config.port
56
- when :search
57
- protocol, host, port = @@config.search_protocol, @@config.search_host, @@config.search_port
58
- end
59
- conn = Net::HTTP.new(host, port,
60
- @@config.proxy_host, @@config.proxy_port,
61
- @@config.proxy_user, @@config.proxy_pass)
62
- if protocol == :ssl
63
- conn.use_ssl = true
64
- conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
65
- end
66
- conn
67
- end
68
-
69
101
  def http_header
70
102
  # can cache this in class variable since all "variables" used to
71
103
  # create the contents of the HTTP header are determined by other
@@ -79,18 +111,28 @@ class Twitter::Client
79
111
  }
80
112
  @@http_header
81
113
  end
82
-
83
- def create_http_get_request(uri, params = {})
84
- path = (params.size > 0) ? "#{uri}?#{params.to_http_str}" : uri
85
- Net::HTTP::Get.new(path, http_header)
114
+
115
+ def rest_request_uri(path)
116
+ "#{@@config.path_prefix}#{path}"
86
117
  end
87
118
 
88
- def create_http_post_request(uri)
89
- Net::HTTP::Post.new(uri, http_header)
119
+ def search_request_uri(path)
120
+ "#{@@config.search_path_prefix}#{path}"
90
121
  end
91
122
 
92
- def create_http_delete_request(uri, params = {})
93
- path = (params.size > 0) ? "#{uri}?#{params.to_http_str}" : uri
94
- Net::HTTP::Delete.new(path, http_header)
123
+ def uri_components(service = :rest)
124
+ case service
125
+ when :rest
126
+ return @@config.protocol, @@config.host, @@config.port,
127
+ @@config.path_prefix
128
+ when :search
129
+ return @@config.search_protocol, @@config.search_host,
130
+ @@config.search_port, @@config.search_path_prefix
131
+ end
132
+ end
133
+
134
+ def construct_site_url(service = :rest)
135
+ protocol, host, port, path_prefix = uri_components(service)
136
+ "#{protocol == :ssl ? :https : protocol}://#{host}:#{port}"
95
137
  end
96
138
  end
@@ -29,7 +29,7 @@ class Twitter::Client
29
29
  raise ArgumentError, "Invalid friend action provided: #{action}" unless @@BLOCK_URIS.keys.member?(action)
30
30
  value = value.to_i unless value.is_a?(String)
31
31
  uri = "#{@@BLOCK_URIS[action]}/#{value}.json"
32
- response = http_connect {|conn| create_http_get_request(uri) }
32
+ response = rest_oauth_connect(:get, uri)
33
33
  bless_model(Twitter::User.unmarshal(response.body))
34
34
  end
35
35
  end
@@ -16,7 +16,7 @@ class Twitter::Client
16
16
  def favorites(options = nil)
17
17
  def uri_suffix(opts); opts && opts[:page] ? "?page=#{opts[:page]}" : ""; end
18
18
  uri = '/favorites.json' + uri_suffix(options)
19
- response = http_connect {|conn| create_http_get_request(uri) }
19
+ response = rest_oauth_connect(:get, uri)
20
20
  bless_models(Twitter::Status.unmarshal(response.body))
21
21
  end
22
22
 
@@ -44,9 +44,9 @@ class Twitter::Client
44
44
  uri = "#{@@FAVORITES_URIS[action]}/#{value}.json"
45
45
  case action
46
46
  when :add
47
- response = http_connect {|conn| create_http_post_request(uri) }
47
+ response = rest_oauth_connect(:post, uri)
48
48
  when :remove
49
- response = http_connect {|conn| create_http_delete_request(uri) }
49
+ response = rest_oauth_connect(:delete, uri)
50
50
  end
51
51
  bless_model(Twitter::Status.unmarshal(response.body))
52
52
  end
@@ -1,8 +1,13 @@
1
1
  class Twitter::Client
2
- @@FRIENDSHIP_URIS = {
2
+ @@FRIEND_URIS = {
3
3
  :add => '/friendships/create',
4
4
  :remove => '/friendships/destroy',
5
5
  }
6
+
7
+ @@FRIENDSHIP_URIS = {
8
+ :incoming => '/friendships/incoming.json',
9
+ :outgoing => '/friendships/outgoing.json',
10
+ }
6
11
 
7
12
  # Provides access to the Twitter Friendship API.
8
13
  #
@@ -26,10 +31,24 @@ class Twitter::Client
26
31
  # client.friend(:add, user)
27
32
  # client.friend(:remove, user)
28
33
  def friend(action, value)
29
- raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
34
+ raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIEND_URIS.keys.member?(action)
30
35
  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) }
36
+ uri = "#{@@FRIEND_URIS[action]}/#{value}.json"
37
+ response = rest_oauth_connect(:post, uri)
33
38
  bless_model(Twitter::User.unmarshal(response.body))
34
39
  end
40
+
41
+ # Provides friendship information for the following scenarios:
42
+ # * <tt>:incoming</tt> - returns an array of numeric IDs for every user who has a pending request to follow the authenticating user.
43
+ # * <tt>:outgoing</tt> - returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request.
44
+ #
45
+ # Examples:
46
+ # client.friendships(:incoming)
47
+ # #=> { :id_list => { :ids => [30592818, 21249843], :next_cursor => 1288724293877798413, :previous_cursor => -1300794057949944903 }}
48
+ def friendships(action)
49
+ raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
50
+ uri = @@FRIENDSHIP_URIS[action]
51
+ response = rest_oauth_connect(:get, uri)
52
+ JSON.parse(response.body)
53
+ end
35
54
  end
@@ -31,7 +31,7 @@ class Twitter::Client
31
31
  id ||= value
32
32
  id ||= @login
33
33
  uri = "#{@@GRAPH_URIS[action]}.json"
34
- response = http_connect {|conn| create_http_get_request(uri, :id => id) }
34
+ response = rest_oauth_connect(:get, uri, :id => id)
35
35
  JSON.parse(response.body)
36
36
  end
37
37
  end
@@ -1,5 +1,4 @@
1
1
  class Twitter::Client
2
-
3
2
  @@MESSAGING_URIS = {
4
3
  :received => '/direct_messages.json',
5
4
  :sent => '/direct_messages/sent.json',
@@ -20,7 +19,7 @@ class Twitter::Client
20
19
  def messages(action, options = {})
21
20
  raise ArgumentError, "Invalid messaging action: #{action}" unless [:sent, :received].member?(action)
22
21
  uri = @@MESSAGING_URIS[action]
23
- response = http_connect {|conn| create_http_get_request(uri, options) }
22
+ response = rest_oauth_connect(:get, uri, options)
24
23
  bless_models(Twitter::Message.unmarshal(response.body))
25
24
  end
26
25
 
@@ -69,9 +68,9 @@ class Twitter::Client
69
68
  user = user.to_i if user and user.is_a?(Twitter::User)
70
69
  case action
71
70
  when :post
72
- response = http_connect({:text => value, :user => user, :source => @@config.source}.to_http_str) {|conn| create_http_post_request(uri) }
71
+ response = rest_oauth_connect(:post, uri, {:text => value, :user => user, :source => @@config.source})
73
72
  when :delete
74
- response = http_connect {|conn| create_http_delete_request(uri, :id => value.to_i) }
73
+ response = rest_oauth_connect(:delete, "#{uri}/#{value.to_i}")
75
74
  end
76
75
  message = Twitter::Message.unmarshal(response.body)
77
76
  bless_model(message)
@@ -18,12 +18,7 @@ class Twitter::Client
18
18
  # user = client.profile(:info, :location => "University Library")
19
19
  # puts user.inspect
20
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
21
+ response = rest_oauth_connect(:post, @@PROFILE_URIS[action], attributes)
22
+ bless_models(Twitter::User.unmarshal(response.body))
28
23
  end
29
24
  end
@@ -1,5 +1,4 @@
1
1
  class Twitter::Client
2
-
3
2
  @@SEARCH_URIS = {
4
3
  :basic => "/search.json",
5
4
  }
@@ -18,9 +17,8 @@ class Twitter::Client
18
17
  # * +:received+
19
18
  # * +:sent+
20
19
  def search(options = {})
21
- # raise ArgumentError, "Invalid messaging action: #{action}"
22
20
  uri = @@SEARCH_URIS[:basic]
23
- response = http_connect(nil, false, :search) {|conn| create_http_get_request(uri, options) }
21
+ response = search_oauth_connect(:get, uri, options)
24
22
  json = JSON.parse(response.body)
25
23
  bless_models(Twitter::Status.unmarshal(JSON.dump(json["results"])))
26
24
  end
@@ -3,7 +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
+ :reply => '/statuses/update.json'
7
7
  }
8
8
 
9
9
  # Provides access to individual statuses via Twitter's Status APIs
@@ -37,14 +37,15 @@ class Twitter::Client
37
37
  response = nil
38
38
  case action
39
39
  when :get
40
- response = http_connect {|conn| create_http_get_request(uri, :id => value.to_i) }
40
+ response = rest_oauth_connect(:get, "#{uri}?#{{:id => value.to_i}.to_http_str}")
41
41
  when :post
42
- response = http_connect({:status => value, :source => @@config.source}.to_http_str) {|conn| create_http_post_request(uri) }
42
+ response = rest_oauth_connect(:post, uri, :status => value, :source => @@config.source)
43
43
  when :delete
44
- response = http_connect {|conn| create_http_delete_request(uri, :id => value.to_i) }
44
+ response = rest_oauth_connect(:delete, "#{uri}?#{{:id => value.to_i}.to_http_str}")
45
45
  when :reply
46
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) }
47
+ params = value.merge(:source => @@config.source)
48
+ response = rest_oauth_connect(:post, uri, params)
48
49
  end
49
50
  bless_model(Twitter::Status.unmarshal(response.body))
50
51
  end
@@ -1,11 +1,16 @@
1
1
  class Twitter::Client
2
2
  @@TIMELINE_URIS = {
3
3
  :public => '/statuses/public_timeline.json',
4
+ :home => '/statuses/home_timeline.json',
4
5
  :friends => '/statuses/friends_timeline.json',
5
6
  :friend => '/statuses/friends_timeline.json',
6
7
  :user => '/statuses/user_timeline.json',
7
8
  :me => '/statuses/user_timeline.json',
8
9
  :replies => '/statuses/replies.json',
10
+ :mentions => '/statuses/mentions.json',
11
+ :retweetsbyme => '/statuses/retweeted_by_me.json',
12
+ :retweetstome => '/statuses/retweeted_to_me.json',
13
+ :retweetsofme => '/statuses/retweets_of_me.json',
9
14
  }
10
15
 
11
16
  # Provides access to Twitter's Timeline APIs
@@ -35,7 +40,8 @@ class Twitter::Client
35
40
  # <tt>options</tt> can also include the following keys:
36
41
  # * <tt>:id</tt> is the user ID, screen name of Twitter::User representation of a <tt>Twitter</tt> user.
37
42
  # * <tt>:since</tt> is a Time object specifying the date-time from which to return results for. Applicable for the :friend, :friends, :user and :me cases.
38
- # * <tt>:count</tt> specifies the number of statuses to retrieve. Only applicable for the :user case.
43
+ # * <tt>:per_page</tt> specifies the number of statuses to retrieve at a time. Only applicable for the :user case.
44
+ # * <tt>:page</tt> specifies page number to retrieve.
39
45
  # * <tt>since_id</tt> is the status id of the public timeline from which to retrieve statuses for <tt>:public</tt>. Only applicable for the :public case.
40
46
  #
41
47
  # You can also pass this method a block, which will iterate through the results
@@ -61,10 +67,15 @@ class Twitter::Client
61
67
  # * +:friend+
62
68
  # * +:user+
63
69
  # * +:me+
70
+ # * +:mentions+
71
+ # * +:replies+
72
+ # * +:retweetsbyme+
73
+ # * +:retweetstome+
74
+ # * +:retweetsofme+
64
75
  def timeline_for(type, options = {}, &block)
65
76
  raise ArgumentError, "Invalid timeline type: #{type}" unless @@TIMELINE_URIS.keys.member?(type)
66
77
  uri = @@TIMELINE_URIS[type]
67
- response = http_connect {|conn| create_http_get_request(uri, options) }
78
+ response = rest_oauth_connect(:get, uri, options)
68
79
  timeline = Twitter::Status.unmarshal(response.body)
69
80
  timeline.each {|status| bless_model(status); yield status if block_given? }
70
81
  timeline
@@ -35,7 +35,8 @@ class Twitter::Client
35
35
  id = id.to_i if id.is_a?(Twitter::User)
36
36
  id_param = id.is_a?(String) ? :screen_name : :user_id
37
37
  params = options.merge(id_param => id)
38
- response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], params) }
38
+ uri = "#{@@USER_URIS[action]}?#{params.to_http_str}"
39
+ response = rest_oauth_connect(:get, uri)
39
40
  bless_models(Twitter::User.unmarshal(response.body))
40
41
  end
41
42
 
@@ -59,7 +60,8 @@ class Twitter::Client
59
60
  def my(action, options = {})
60
61
  raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
61
62
  params = options.merge(:id => @login)
62
- response = http_connect {|conn| create_http_get_request(@@USER_URIS[action], params) }
63
+ uri = "#{@@USER_URIS[action]}?#{params.to_http_str}"
64
+ response = rest_oauth_connect(:get, uri)
63
65
  users = Twitter::User.unmarshal(response.body)
64
66
  bless_models(users)
65
67
  end
@@ -7,24 +7,37 @@ module Twitter
7
7
  # * <tt>protocol</tt> - <tt>:http</tt>, <tt>:https</tt> or <tt>:ssl</tt> supported. <tt>:ssl</tt> is an alias for <tt>:https</tt>. Defaults to <tt>:ssl</tt>
8
8
  # * <tt>host</tt> - hostname to connect to for the Twitter service. Defaults to <tt>'twitter.com'</tt>.
9
9
  # * <tt>port</tt> - port to connect to for the Twitter service. Defaults to <tt>443</tt>.
10
+ # * <tt>path_prefix</tt> - path to prefix URIs of REST API calls. Defaults to <tt>""</tt>.
11
+ # * <tt>search_protocol</tt> - <tt>:http</tt>, <tt>:https</tt> or <tt>:ssl</tt> supported. <tt>:ssl</tt> is an alias for <tt>:https</tt>. Defaults to <tt>:ssl</tt>
12
+ # * <tt>search_host</tt> - hostname to connect to for the Twitter Search service. Defaults to <tt>'twitter.com'</tt>.
13
+ # * <tt>search_port</tt> - port to connect to for the Twitter Search service. Defaults to <tt>443</tt>.
14
+ # * <tt>search_path_prefix</tt> - path to prefix URIs of Search API calls. Defaults to <tt>""</tt>.
10
15
  # * <tt>proxy_host</tt> - proxy host to use. Defaults to nil.
11
16
  # * <tt>proxy_port</tt> - proxy host to use. Defaults to nil.
12
17
  # * <tt>proxy_user</tt> - proxy username to use. Defaults to nil.
13
18
  # * <tt>proxy_pass</tt> - proxy password to use. Defaults to nil.
14
19
  # * <tt>user_agent</tt> - user agent string to use for each request of the HTTP header.
15
- # * <tt>application_name</tt> - name of your client application. Defaults to 'Twitter4R'
20
+ # * <tt>application_name</tt> - name of your client application. Defaults to 'Twitter4R'.
16
21
  # * <tt>application_version</tt> - version of your client application. Defaults to current <tt>Twitter::Version.to_version</tt>.
17
22
  # * <tt>application_url</tt> - URL of your client application. Defaults to http://twitter4r.rubyforge.org.
18
23
  # * <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.
24
+ # * <tt>timeout</tt> - the timeout in second for HTTP requests.
25
+ # * <tt>oauth_consumer_token</tt> - the OAuth consumer token for your application
26
+ # * <tt>oauth_consumer_secret</tt> - the OAuth consumer secret for your application
27
+ # * <tt>oauth_request_token_path</tt> - the URI path for Twitter API's OAuth request token call. Not usually necessary to override.
28
+ # * <tt>oauth_access_token_path</tt> - the URI path for Twitter API's OAuth access token call. Not usually necessary to override.
29
+ # * <tt>oauth_authorize_path</tt> - the URI path for Twitter API's OAuth authorize call. Not usually necessary to override.
19
30
  class Config
20
31
  include ClassUtilMixin
21
32
  @@ATTRIBUTES = [
22
33
  :protocol,
23
34
  :host,
24
35
  :port,
36
+ :path_prefix,
25
37
  :search_protocol,
26
38
  :search_host,
27
39
  :search_port,
40
+ :search_path_prefix,
28
41
  :proxy_host,
29
42
  :proxy_port,
30
43
  :proxy_user,
@@ -34,8 +47,15 @@ module Twitter
34
47
  :application_version,
35
48
  :application_url,
36
49
  :source,
50
+ :timeout,
51
+ :oauth_consumer_token,
52
+ :oauth_consumer_secret,
53
+ :oauth_request_token_path,
54
+ :oauth_access_token_path,
55
+ :oauth_authorize_path,
37
56
  ]
38
- attr_accessor *@@ATTRIBUTES
57
+
58
+ attr_accessor(*@@ATTRIBUTES)
39
59
 
40
60
  # Override of Object#eql? to ensure RSpec specifications run
41
61
  # correctly. Also done to follow Ruby best practices.
@@ -52,9 +72,11 @@ module Twitter
52
72
  @@defaults = { :host => 'twitter.com',
53
73
  :port => 443,
54
74
  :protocol => :ssl,
75
+ :path_prefix => "",
55
76
  :search_host => 'search.twitter.com',
56
77
  :search_port => 80,
57
78
  :search_protocol => :http,
79
+ :search_path_prefix => "",
58
80
  :proxy_host => nil,
59
81
  :proxy_port => nil,
60
82
  :user_agent => "default",
@@ -62,6 +84,10 @@ module Twitter
62
84
  :application_version => Twitter::Version.to_version,
63
85
  :application_url => 'http://twitter4r.rubyforge.org',
64
86
  :source => 'twitter4r',
87
+ :timeout => 20,
88
+ :oauth_request_token_path => '/oauth/request_token',
89
+ :oauth_access_token_path => '/oauth/access_token',
90
+ :oauth_authorize_path => '/oauth/authorize',
65
91
  }
66
92
  @@config = Twitter::Config.new(@@defaults)
67
93
 
@@ -18,7 +18,7 @@ class Twitter::Client
18
18
  # represent Twitter's featured users.
19
19
  def featured(type)
20
20
  uri = @@FEATURED_URIS[type]
21
- response = http_connect {|conn| create_http_get_request(uri) }
21
+ response = rest_oauth_connect(:get, uri)
22
22
  bless_models(Twitter::User.unmarshal(response.body))
23
23
  end
24
24
  end
data/lib/twitter/model.rb CHANGED
@@ -164,8 +164,8 @@ module Twitter
164
164
  :profile_sidebar_border_color, :profile_background_image_url,
165
165
  :profile_background_tile, :utc_offset, :time_zone,
166
166
  :following, :notifications, :favourites_count, :followers_count,
167
- :friends_count, :statuses_count, :created_at, ]
168
- attr_accessor *@@ATTRIBUTES
167
+ :friends_count, :statuses_count, :created_at ]
168
+ attr_accessor(*@@ATTRIBUTES)
169
169
 
170
170
  class << self
171
171
  # Used as factory method callback
@@ -227,8 +227,8 @@ module Twitter
227
227
  include ModelMixin
228
228
  @@ATTRIBUTES = [:id, :text, :source, :truncated, :created_at, :user, :from_user, :to_user,
229
229
  :favorited, :in_reply_to_status_id, :in_reply_to_user_id,
230
- :in_reply_to_screen_name]
231
- attr_accessor *@@ATTRIBUTES
230
+ :in_reply_to_screen_name, :geo]
231
+ attr_accessor(*@@ATTRIBUTES)
232
232
 
233
233
  class << self
234
234
  # Used as factory method callback
@@ -288,8 +288,8 @@ module Twitter
288
288
  # Represents a direct message on <tt>Twitter</tt> between <tt>Twitter</tt> users.
289
289
  class Message
290
290
  include ModelMixin
291
- @@ATTRIBUTES = [:id, :recipient, :sender, :text, :created_at]
292
- attr_accessor *@@ATTRIBUTES
291
+ @@ATTRIBUTES = [:id, :recipient, :sender, :text, :geo, :created_at]
292
+ attr_accessor(*@@ATTRIBUTES)
293
293
 
294
294
  class << self
295
295
  # Used as factory method callback
@@ -350,7 +350,7 @@ module Twitter
350
350
  class RateLimitStatus
351
351
  include ModelMixin
352
352
  @@ATTRIBUTES = [:remaining_hits, :hourly_limit, :reset_time_in_seconds, :reset_time]
353
- attr_accessor *@@ATTRIBUTES
353
+ attr_accessor(*@@ATTRIBUTES)
354
354
 
355
355
  class << self
356
356
  # Used as factory method callback
@@ -3,8 +3,8 @@
3
3
 
4
4
  module Twitter::Version #:nodoc:
5
5
  MAJOR = 0
6
- MINOR = 3
7
- REVISION = 2
6
+ MINOR = 5
7
+ REVISION = 0
8
8
  class << self
9
9
  # Returns X.Y.Z formatted version string
10
10
  def to_version
data/lib/twitter.rb CHANGED
@@ -21,7 +21,11 @@ require('net/https')
21
21
  require('uri')
22
22
  require('cgi')
23
23
  require('json')
24
- require('yaml')
24
+ require('oauth')
25
+
26
+ if RUBY_VERSION < "1.9.0"
27
+ require('yaml')
28
+ end
25
29
 
26
30
  # Ordering matters...pay attention here!
27
31
  require_local('twitter/ext')
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
3
3
  describe Twitter::Client, "#account_info" do
4
4
  before(:each) do
5
5
  @uri = Twitter::Client.class_eval("@@ACCOUNT_URIS[:rate_limit_status]")
6
- @request = mas_net_http_get(:basic_auth => nil)
6
+ @request = mas_net_http_get
7
7
  @twitter = client_context
8
8
  @default_header = @twitter.send(:http_header)
9
9
  @response = mas_net_http_response(:success)
@@ -15,7 +15,7 @@ describe Twitter::Client, "#account_info" do
15
15
  end
16
16
 
17
17
  it "should create expected HTTP GET request" do
18
- @twitter.should_receive(:create_http_get_request).with(@uri).and_return(@request)
18
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uri).and_return(@response)
19
19
  @twitter.account_info
20
20
  end
21
21