twitter4r 0.5.0 → 0.5.1

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.
@@ -14,7 +14,7 @@ class Twitter::Client
14
14
  # Returns the response of the OAuth/HTTP(s) request for REST API requests (not Search)
15
15
  def rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
16
16
  atoken = rest_access_token
17
- uri = rest_request_uri(path)
17
+ uri = rest_request_uri(path, params)
18
18
  if [:get, :delete].include?(method)
19
19
  response = atoken.send(method, uri, http_header.merge(headers))
20
20
  else
@@ -27,7 +27,7 @@ class Twitter::Client
27
27
  # Returns the response of the OAuth/HTTP(s) request for Search API requests (not REST)
28
28
  def search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
29
29
  atoken = search_access_token
30
- uri = search_request_uri(path)
30
+ uri = search_request_uri(path, params)
31
31
  if method == :get
32
32
  response = atoken.send(method, uri, http_header.merge(headers))
33
33
  end
@@ -49,39 +49,56 @@ class Twitter::Client
49
49
  @@http_header = nil
50
50
 
51
51
  def rest_consumer
52
- unless @consumer
53
- @consumer = OAuth::Consumer.new(@oauth_consumer["key"],
54
- @oauth_consumer["secret"],
55
- :site => construct_site_url)
52
+ unless @rest_consumer
53
+ consumer = @oauth_consumer
54
+ if consumer
55
+ key = consumer[:key] || consumer["key"]
56
+ secret = consumer[:secret] || consumer["secret"]
57
+ end
58
+ cfg = self.class.config
59
+ key ||= cfg.oauth_consumer_token
60
+ secret ||= cfg.oauth_consumer_secret
61
+ @rest_consumer = OAuth::Consumer.new(key, secret,
62
+ :site => construct_site_url,
63
+ :proxy => construct_proxy_url)
56
64
  end
57
- @consumer
65
+ @rest_consumer
58
66
  end
59
67
 
60
68
  def rest_access_token
61
- unless @access_token
62
- @access_token = OAuth::AccessToken.new(rest_consumer,
63
- @oauth_access["key"],
64
- @oauth_access["secret"])
69
+ unless @rest_access_token
70
+ key = @oauth_access[:key] || @oauth_access["key"]
71
+ secret = @oauth_access[:secret] || @oauth_access["secret"]
72
+ @rest_access_token = OAuth::AccessToken.new(rest_consumer, key, secret)
65
73
  end
66
- @access_token
74
+ @rest_access_token
67
75
  end
68
76
 
69
77
  def search_consumer
70
- unless @consumer
71
- @consumer = OAuth::Consumer.new(@oauth_consumer["key"],
72
- @oauth_consumer["secret"],
73
- :site => construct_site_url(:search))
78
+ unless @search_consumer
79
+ cfg = self.class.config
80
+ consumer = @oauth_consumer
81
+ if consumer
82
+ key = consumer[:key] || consumer["key"]
83
+ secret = consumer[:secret] || consumer["secret"]
84
+ end
85
+ cfg = self.class.config
86
+ key ||= cfg.oauth_consumer_token
87
+ secret ||= cfg.oauth_consumer_secret
88
+ @search_consumer = OAuth::Consumer.new(key, secret,
89
+ :site => construct_site_url(:search),
90
+ :proxy => construct_proxy_url)
74
91
  end
75
- @consumer
92
+ @search_consumer
76
93
  end
77
94
 
78
95
  def search_access_token
79
- unless @access_token
80
- @access_token = OAuth::AccessToken.new(search_consumer,
81
- @oauth_access["key"],
82
- @oauth_access["secret"])
96
+ unless @search_access_token
97
+ key = @oauth_access[:key] || @oauth_access["key"]
98
+ secret = @oauth_access[:secret] || @oauth_access["secret"]
99
+ @search_access_token = OAuth::AccessToken.new(search_consumer, key, secret)
83
100
  end
84
- @access_token
101
+ @search_access_token
85
102
  end
86
103
 
87
104
  def raise_rest_error(response, uri = nil)
@@ -103,36 +120,57 @@ class Twitter::Client
103
120
  # create the contents of the HTTP header are determined by other
104
121
  # class variables that are not designed to change after instantiation.
105
122
  @@http_header ||= {
106
- 'User-Agent' => "Twitter4R v#{Twitter::Version.to_version} [#{@@config.user_agent}]",
123
+ 'User-Agent' => "Twitter4R v#{Twitter::Version.to_version} [#{self.class.config.user_agent}]",
107
124
  'Accept' => 'text/x-json',
108
- 'X-Twitter-Client' => @@config.application_name,
109
- 'X-Twitter-Client-Version' => @@config.application_version,
110
- 'X-Twitter-Client-URL' => @@config.application_url,
125
+ 'X-Twitter-Client' => self.class.config.application_name,
126
+ 'X-Twitter-Client-Version' => self.class.config.application_version,
127
+ 'X-Twitter-Client-URL' => self.class.config.application_url,
111
128
  }
112
129
  @@http_header
113
130
  end
114
131
 
115
- def rest_request_uri(path)
116
- "#{@@config.path_prefix}#{path}"
132
+ def rest_request_uri(path, params = nil)
133
+ uri = "#{self.class.config.path_prefix}#{path}"
134
+ uri << "?#{params.to_http_str}" if params
135
+ uri
117
136
  end
118
137
 
119
- def search_request_uri(path)
120
- "#{@@config.search_path_prefix}#{path}"
138
+ def search_request_uri(path, params = nil)
139
+ uri = "#{self.class.config.search_path_prefix}#{path}"
140
+ uri << "?#{params.to_http_str}" if params
141
+ uri
121
142
  end
122
143
 
123
144
  def uri_components(service = :rest)
124
145
  case service
125
146
  when :rest
126
- return @@config.protocol, @@config.host, @@config.port,
127
- @@config.path_prefix
147
+ return self.class.config.protocol, self.class.config.host, self.class.config.port,
148
+ self.class.config.path_prefix
128
149
  when :search
129
- return @@config.search_protocol, @@config.search_host,
130
- @@config.search_port, @@config.search_path_prefix
150
+ return self.class.config.search_protocol, self.class.config.search_host,
151
+ self.class.config.search_port, self.class.config.search_path_prefix
131
152
  end
132
153
  end
133
154
 
134
155
  def construct_site_url(service = :rest)
135
156
  protocol, host, port, path_prefix = uri_components(service)
136
- "#{protocol == :ssl ? :https : protocol}://#{host}:#{port}"
157
+ "#{(protocol == :ssl ? :https : protocol).to_s}://#{host}:#{port}"
158
+ end
159
+
160
+ def construct_proxy_url
161
+ cfg = self.class.config
162
+ proxy_user, proxy_pass = cfg.proxy_user, cfg.proxy_pass
163
+ proxy_host, proxy_port = cfg.proxy_host, cfg.proxy_port
164
+ protocol = ((cfg.proxy_protocol == :ssl) ? :https : cfg.proxy_protocol).to_s
165
+ url = nil
166
+ if proxy_host
167
+ url = "#{protocol}://"
168
+ if proxy_user
169
+ url << "#{proxy_user}:#{proxy_pass}@"
170
+ end
171
+ url << "#{proxy_host}:#{proxy_port.to_s}"
172
+ else
173
+ url
174
+ end
137
175
  end
138
176
  end
@@ -14,9 +14,8 @@ class Twitter::Client
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
16
  def favorites(options = nil)
17
- def uri_suffix(opts); opts && opts[:page] ? "?page=#{opts[:page]}" : ""; end
18
- uri = '/favorites.json' + uri_suffix(options)
19
- response = rest_oauth_connect(:get, uri)
17
+ uri = '/favorites.json'
18
+ response = rest_oauth_connect(:get, uri, options)
20
19
  bless_models(Twitter::Status.unmarshal(response.body))
21
20
  end
22
21
 
@@ -68,7 +68,7 @@ class Twitter::Client
68
68
  user = user.to_i if user and user.is_a?(Twitter::User)
69
69
  case action
70
70
  when :post
71
- response = rest_oauth_connect(:post, uri, {:text => value, :user => user, :source => @@config.source})
71
+ response = rest_oauth_connect(:post, uri, {:text => value, :user => user, :source => self.class.config.source})
72
72
  when :delete
73
73
  response = rest_oauth_connect(:delete, "#{uri}/#{value.to_i}")
74
74
  end
@@ -37,14 +37,14 @@ class Twitter::Client
37
37
  response = nil
38
38
  case action
39
39
  when :get
40
- response = rest_oauth_connect(:get, "#{uri}?#{{:id => value.to_i}.to_http_str}")
40
+ response = rest_oauth_connect(:get, uri, {:id => value.to_i})
41
41
  when :post
42
- response = rest_oauth_connect(:post, uri, :status => value, :source => @@config.source)
42
+ response = rest_oauth_connect(:post, uri, :status => value, :source => self.class.config.source)
43
43
  when :delete
44
- response = rest_oauth_connect(:delete, "#{uri}?#{{:id => value.to_i}.to_http_str}")
44
+ response = rest_oauth_connect(:delete, uri, {:id => value.to_i})
45
45
  when :reply
46
46
  return nil if (!value.is_a?(Hash) || !value[:status] || !value[:in_reply_to_status_id])
47
- params = value.merge(:source => @@config.source)
47
+ params = value.merge(:source => self.class.config.source)
48
48
  response = rest_oauth_connect(:post, uri, params)
49
49
  end
50
50
  bless_model(Twitter::Status.unmarshal(response.body))
@@ -40,9 +40,10 @@ class Twitter::Client
40
40
  # <tt>options</tt> can also include the following keys:
41
41
  # * <tt>:id</tt> is the user ID, screen name of Twitter::User representation of a <tt>Twitter</tt> user.
42
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.
43
- # * <tt>:per_page</tt> specifies the number of statuses to retrieve at a time. Only applicable for the :user case.
43
+ # * <tt>:count</tt> specifies the number of statuses to retrieve at a time. Only applicable for the :user case.
44
44
  # * <tt>:page</tt> specifies page number to retrieve.
45
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.
46
+ # * <tt>include_rts</tt> flags whether to retrieve native retweets in the timeline or not. True values are true, t or 1.
46
47
  #
47
48
  # You can also pass this method a block, which will iterate through the results
48
49
  # of the requested timeline and apply the block logic for each status returned.
@@ -35,8 +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
- uri = "#{@@USER_URIS[action]}?#{params.to_http_str}"
39
- response = rest_oauth_connect(:get, uri)
38
+ uri = @@USER_URIS[action]
39
+ response = rest_oauth_connect(:get, uri, params)
40
40
  bless_models(Twitter::User.unmarshal(response.body))
41
41
  end
42
42
 
@@ -60,8 +60,8 @@ class Twitter::Client
60
60
  def my(action, options = {})
61
61
  raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
62
62
  params = options.merge(:id => @login)
63
- uri = "#{@@USER_URIS[action]}?#{params.to_http_str}"
64
- response = rest_oauth_connect(:get, uri)
63
+ uri = @@USER_URIS[action]
64
+ response = rest_oauth_connect(:get, uri, params)
65
65
  users = Twitter::User.unmarshal(response.body)
66
66
  bless_models(users)
67
67
  end
@@ -12,8 +12,9 @@ module Twitter
12
12
  # * <tt>search_host</tt> - hostname to connect to for the Twitter Search service. Defaults to <tt>'twitter.com'</tt>.
13
13
  # * <tt>search_port</tt> - port to connect to for the Twitter Search service. Defaults to <tt>443</tt>.
14
14
  # * <tt>search_path_prefix</tt> - path to prefix URIs of Search API calls. Defaults to <tt>""</tt>.
15
+ # * <tt>proxy_protocol</tt> - proxy protocol to use. Defaults to http.
15
16
  # * <tt>proxy_host</tt> - proxy host to use. Defaults to nil.
16
- # * <tt>proxy_port</tt> - proxy host to use. Defaults to nil.
17
+ # * <tt>proxy_port</tt> - proxy host to use. Defaults to 8080.
17
18
  # * <tt>proxy_user</tt> - proxy username to use. Defaults to nil.
18
19
  # * <tt>proxy_pass</tt> - proxy password to use. Defaults to nil.
19
20
  # * <tt>user_agent</tt> - user agent string to use for each request of the HTTP header.
@@ -38,6 +39,7 @@ module Twitter
38
39
  :search_host,
39
40
  :search_port,
40
41
  :search_path_prefix,
42
+ :proxy_protocol,
41
43
  :proxy_host,
42
44
  :proxy_port,
43
45
  :proxy_user,
@@ -77,8 +79,9 @@ module Twitter
77
79
  :search_port => 80,
78
80
  :search_protocol => :http,
79
81
  :search_path_prefix => "",
82
+ :proxy_protocol => "http",
80
83
  :proxy_host => nil,
81
- :proxy_port => nil,
84
+ :proxy_port => 8080,
82
85
  :user_agent => "default",
83
86
  :application_name => 'Twitter4R',
84
87
  :application_version => Twitter::Version.to_version,
@@ -93,10 +96,15 @@ module Twitter
93
96
 
94
97
  # Twitter::Client class methods
95
98
  class << self
99
+ # returns configuration object
100
+ def config
101
+ @@config
102
+ end
103
+
96
104
  # Yields to given <tt>block</tt> to configure the Twitter4R API.
97
105
  def configure(&block)
98
106
  raise ArgumentError, "Block must be provided to configure" unless block_given?
99
- yield @@config
107
+ yield config
100
108
  end # configure
101
109
  end # class << self
102
110
  end # Client class
@@ -35,18 +35,3 @@ class Time
35
35
  end
36
36
  end
37
37
 
38
- # Extension to Kernel to add #gem_present? without any exceptions raised
39
- module Kernel
40
-
41
- # Returns whether or not a gem exists without raising a Gem::LoadError exception
42
- def gem_present?(gem_name, version = nil)
43
- present = false
44
- begin
45
- present = !!(version ? gem(gem_name, version) : gem(gem_name))
46
- rescue Gem::LoadError => le
47
- present = false
48
- warn("Gem load error: Couldn't load #{gem_name} #{version ? "with version requirement #{version}: #{le.to_s}": ""}")
49
- end
50
- present
51
- end
52
- end
@@ -4,7 +4,7 @@
4
4
  module Twitter::Version #:nodoc:
5
5
  MAJOR = 0
6
6
  MINOR = 5
7
- REVISION = 0
7
+ REVISION = 1
8
8
  class << self
9
9
  # Returns X.Y.Z formatted version string
10
10
  def to_version
@@ -137,3 +137,103 @@ describe Twitter::Client, "#bless_models" do
137
137
  nilize(@twitter, @models)
138
138
  end
139
139
  end
140
+
141
+ shared_examples_for "consumer token overrides" do
142
+ before(:each) do
143
+ @config_key = "234ufmewroi23o43SFsf"
144
+ @config_secret = "kfgIYFOasdfsfg236GSka"
145
+ @key_override = "#{@config_key}-1234"
146
+ @secret_override = "#{@config_secret}-1234"
147
+ Twitter::Client.configure do |conf|
148
+ conf.oauth_consumer_token = @config_key
149
+ conf.oauth_consumer_secret = @config_secret
150
+ end
151
+ @overridded_client = Twitter::Client.new(:oauth_consumer => { :key => @key_override, :secret => @secret_override })
152
+ @plain_client = Twitter::Client.new
153
+ end
154
+
155
+ it "should be set to key/secret pair passed into constructor when passed in and configuration object already has key/secret set" do
156
+ consumer = get_consumer(@overridded_client)
157
+ consumer.instance_eval("@key").should eql(@key_override)
158
+ consumer.instance_eval("@secret").should eql(@secret_override)
159
+ end
160
+
161
+ it "should be set to key/secret pair set in configuration object when none passed into constructor" do
162
+ consumer = get_consumer(@plain_client)
163
+ consumer.instance_eval("@key").should eql(@config_key)
164
+ consumer.instance_eval("@secret").should eql(@config_secret)
165
+ end
166
+
167
+ after(:each) do
168
+ Twitter::Client.configure do |conf|
169
+ conf.oauth_consumer_token = nil
170
+ conf.oauth_consumer_secret = nil
171
+ end
172
+ end
173
+ end
174
+
175
+ describe Twitter::Client, "rest consumer token" do
176
+ it_should_behave_like "consumer token overrides"
177
+
178
+ def get_consumer(client)
179
+ client.send(:rest_consumer)
180
+ end
181
+ end
182
+
183
+ describe Twitter::Client, "search consumer token" do
184
+ it_should_behave_like "consumer token overrides"
185
+
186
+ def get_consumer(client)
187
+ client.send(:search_consumer)
188
+ end
189
+ end
190
+
191
+ describe Twitter::Client, "#construct_proxy_url" do
192
+ before(:each) do
193
+ @host = "localhost"
194
+ @port = "8080"
195
+ @user = "user"
196
+ @pass = "pass123"
197
+ @client = client_context
198
+ end
199
+
200
+ def configure_host_and_port
201
+ Twitter::Client.configure do |conf|
202
+ conf.proxy_host = @host
203
+ conf.proxy_port = @port
204
+ end
205
+ end
206
+
207
+ def configure_user_and_password
208
+ Twitter::Client.configure do |conf|
209
+ conf.proxy_user = @user
210
+ conf.proxy_pass = @pass
211
+ end
212
+ end
213
+
214
+ it "should return the full proxy URL when proxy host and port given" do
215
+ configure_host_and_port
216
+ url = "http://#{@host}:#{@port}"
217
+ @client.send(:construct_proxy_url).should eql(url)
218
+ end
219
+
220
+ it "should return the full proxy URL when proxy host, port, username and password given" do
221
+ configure_host_and_port
222
+ configure_user_and_password
223
+ url = "http://#{@user}:#{@pass}@#{@host}:#{@port}"
224
+ @client.send(:construct_proxy_url).should eql(url)
225
+ end
226
+
227
+ it "should return nil when no proxy host is given" do
228
+ @client.send(:construct_proxy_url).should eql(nil)
229
+ end
230
+
231
+ after(:each) do
232
+ Twitter::Client.configure do |conf|
233
+ conf.proxy_user = nil
234
+ conf.proxy_pass = nil
235
+ conf.proxy_host = nil
236
+ conf.proxy_port = nil
237
+ end
238
+ end
239
+ end
@@ -15,12 +15,12 @@ describe Twitter::Client, "#favorites" do
15
15
  end
16
16
 
17
17
  it "should create expected HTTP GET request when not giving options" do
18
- @twitter.should_receive(:rest_oauth_connect).with(:get, @uri).and_return(@response)
18
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uri, nil).and_return(@response)
19
19
  @twitter.favorites
20
20
  end
21
21
 
22
22
  it "should create expected HTTP GET request when giving :page options" do
23
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uri}?#{@options.to_http_str}").and_return(@response)
23
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uri, @options).and_return(@response)
24
24
  @twitter.favorites(@options)
25
25
  end
26
26
 
@@ -98,34 +98,34 @@ module FavoriteSpecMixin
98
98
  end
99
99
  end
100
100
 
101
- describe "Twitter::Client#favorite error handling", :shared => true do
101
+ shared_examples_for "Twitter::Client#favorite error handling" do
102
102
  it "should raise a Twitter::RESTError exception when a 401 HTTP response is received" do
103
103
  connection = mas_net_http(mas_net_http_response(:not_authorized))
104
104
  lambda {
105
105
  execute_method
106
106
  }.should raise_error(Twitter::RESTError)
107
- end
107
+ end
108
108
 
109
109
  it "should raise a Twitter::RESTError exception when a 403 HTTP response is received" do
110
110
  connection = mas_net_http(mas_net_http_response(:forbidden))
111
111
  lambda {
112
112
  execute_method
113
113
  }.should raise_error(Twitter::RESTError)
114
- end
114
+ end
115
115
 
116
116
  it "should raise a Twitter::RESTError exception when a 404 HTTP response is received" do
117
117
  connection = mas_net_http(mas_net_http_response(:file_not_found))
118
118
  lambda {
119
119
  execute_method
120
120
  }.should raise_error(Twitter::RESTError)
121
- end
121
+ end
122
122
 
123
123
  it "should raise a Twitter::RESTError exception when a 500 HTTP response is received" do
124
124
  connection = mas_net_http(mas_net_http_response(:server_error))
125
125
  lambda {
126
126
  execute_method
127
127
  }.should raise_error(Twitter::RESTError)
128
- end
128
+ end
129
129
  end
130
130
 
131
131
  describe Twitter::Client, "#favorite(:add, status)" do
@@ -169,7 +169,7 @@ describe Twitter::Client, "#favorite(:remove, status)" do
169
169
 
170
170
  it "should create expected DELETE request for :remove action supplying integer id of status" do
171
171
  @twitter.should_receive(:rest_oauth_connect).with(:delete, create_uri(:destroy, @id)).and_return(@request)
172
- @twitter.favorite(:remove, @id)
172
+ execute_method
173
173
  end
174
174
 
175
175
  it "should create expected DELETE request for :remove action supplying status object" do
@@ -32,63 +32,63 @@ describe Twitter::Client, "#friend" do
32
32
  @connection = mas_net_http(@response)
33
33
  Twitter::User.stub!(:unmarshal).and_return(@friend)
34
34
  end
35
-
35
+
36
36
  def create_uri(action, id)
37
- "#{@uris[action]}/#{id}.json"
37
+ "#{@uris[action]}/#{id}.json"
38
38
  end
39
-
39
+
40
40
  it "should create expected HTTP POST request for :add case using integer user ID" do
41
- # the integer user ID scenario...
41
+ # the integer user ID scenario...
42
42
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:add, @id)).and_return(@response)
43
43
  @twitter.friend(:add, @id)
44
44
  end
45
-
45
+
46
46
  it "should create expected HTTP POST request for :add case using screen name" do
47
- # the screen name scenario...
47
+ # the screen name scenario...
48
48
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:add, @screen_name)).and_return(@response)
49
49
  @twitter.friend(:add, @screen_name)
50
50
  end
51
51
 
52
- it "should create expected HTTP GET request for :add case using Twitter::User object" do
53
- # the Twitter::User object scenario...
52
+ it "should create expected HTTP GET request for :add case using Twitter::User object" do
53
+ # the Twitter::User object scenario...
54
54
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:add, @friend.to_i)).and_return(@response)
55
55
  @twitter.friend(:add, @friend)
56
56
  end
57
-
57
+
58
58
  it "should create expected HTTP GET request for :remove case using integer user ID" do
59
- # the integer user ID scenario...
59
+ # the integer user ID scenario...
60
60
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:remove, @id)).and_return(@response)
61
61
  @twitter.friend(:remove, @id)
62
62
  end
63
63
 
64
- it "should create expected HTTP GET request for :remove case using screen name" do
65
- # the screen name scenario...
64
+ it "should create expected HTTP GET request for :remove case using screen name" do
65
+ # the screen name scenario...
66
66
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:remove, @screen_name)).and_return(@response)
67
67
  @twitter.friend(:remove, @screen_name)
68
68
  end
69
69
 
70
70
  it "should create expected HTTP GET request for :remove case using Twitter::User object" do
71
- # the Twitter::User object scenario...
71
+ # the Twitter::User object scenario...
72
72
  @twitter.should_receive(:rest_oauth_connect).with(:post, create_uri(:remove, @friend.to_i)).and_return(@response)
73
73
  @twitter.friend(:remove, @friend)
74
74
  end
75
-
75
+
76
76
  it "should bless user model returned for :add case" do
77
77
  @twitter.should_receive(:bless_model).with(@friend)
78
78
  @twitter.friend(:add, @friend)
79
79
  end
80
-
80
+
81
81
  it "should bless user model returned for :remove case" do
82
82
  @twitter.should_receive(:bless_model).with(@friend)
83
83
  @twitter.friend(:remove, @friend)
84
84
  end
85
-
85
+
86
86
  it "should raise ArgumentError if action given is not valid" do
87
87
  lambda {
88
88
  @twitter.friend(:crap, @friend)
89
89
  }.should raise_error(ArgumentError)
90
90
  end
91
-
91
+
92
92
  after(:each) do
93
93
  nilize(@twitter, @id, @uris, @response, @connection)
94
94
  end
@@ -26,17 +26,17 @@ describe Twitter::Client, "#status" do
26
26
  end
27
27
 
28
28
  it "should create expected HTTP GET request for :get case" do
29
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:get]}?#{@options.to_http_str}").and_return(@response)
29
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:get], @options).and_return(@response)
30
30
  @twitter.status(:get, @options[:id])
31
31
  end
32
32
 
33
33
  it "should invoke @twitter#rest_oauth_connect with given parameters equivalent to {:id => value.to_i} for :get case" do
34
34
  # Float case
35
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:get]}?#{{:id => @float.to_i}.to_http_str}").and_return(@response)
35
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:get], {:id => @float.to_i}).and_return(@response)
36
36
  @twitter.status(:get, @float)
37
37
 
38
38
  # Twitter::Status object case
39
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:get]}?#{{:id => @status.to_i}.to_http_str}").and_return(@response)
39
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:get], {:id => @status.to_i}).and_return(@response)
40
40
  @twitter.status(:get, @status)
41
41
  end
42
42
 
@@ -71,17 +71,17 @@ describe Twitter::Client, "#status" do
71
71
  end
72
72
 
73
73
  it "should create expected HTTP DELETE request for :delete case" do
74
- @twitter.should_receive(:rest_oauth_connect).with(:delete, "#{@uris[:delete]}?#{@options.to_http_str}").and_return(@response)
74
+ @twitter.should_receive(:rest_oauth_connect).with(:delete, @uris[:delete], @options).and_return(@response)
75
75
  @twitter.status(:delete, @options[:id])
76
76
  end
77
77
 
78
78
  it "should invoke @twitter#rest_oauth_connect with given parameters equivalent to {:id => value.to_i} for :delete case" do
79
79
  # Float case
80
- @twitter.should_receive(:rest_oauth_connect).with(:delete, "#{@uris[:delete]}?#{{:id => @float.to_i}.to_http_str}").and_return(@response)
80
+ @twitter.should_receive(:rest_oauth_connect).with(:delete, @uris[:delete], {:id => @float.to_i}).and_return(@response)
81
81
  @twitter.status(:delete, @float)
82
82
 
83
83
  # Twitter::Status object case
84
- @twitter.should_receive(:rest_oauth_connect).with(:delete, "#{@uris[:delete]}?#{{:id => @status.to_i}.to_http_str}").and_return(@response)
84
+ @twitter.should_receive(:rest_oauth_connect).with(:delete, @uris[:delete], {:id => @status.to_i}).and_return(@response)
85
85
  @twitter.status(:delete, @status)
86
86
  end
87
87
 
@@ -19,12 +19,12 @@ describe Twitter::Client, "#user(id, :info)" do
19
19
  end
20
20
 
21
21
  it "should create expected HTTP GET request when giving numeric user id" do
22
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:info]}?#{{:user_id => @id}.to_http_str}").and_return(@response)
22
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:info], {:user_id => @id}).and_return(@response)
23
23
  @twitter.user(@id)
24
24
  end
25
25
 
26
26
  it "should create expected HTTP GET request when giving screen name" do
27
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:info]}?#{{:screen_name => @screen_name}.to_http_str}").and_return(@response)
27
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:info], {:screen_name => @screen_name}).and_return(@response)
28
28
  @twitter.user(@screen_name)
29
29
  end
30
30
 
@@ -64,7 +64,7 @@ describe Twitter::Client, "#user(id, :friends)" do
64
64
  end
65
65
 
66
66
  it "should create expected HTTP GET request when giving numeric user id" do
67
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:friends]}?#{{:user_id => @id}.to_http_str}").and_return(@response)
67
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:friends], {:user_id => @id}).and_return(@response)
68
68
  @twitter.user(@id, :friends)
69
69
  end
70
70
 
@@ -74,12 +74,12 @@ describe Twitter::Client, "#user(id, :friends)" do
74
74
  end
75
75
 
76
76
  it "should create expected HTTP GET request when giving Twitter::User object" do
77
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:friends]}?#{{:user_id => @user.to_i}.to_http_str}").and_return(@response)
77
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:friends], {:user_id => @user.to_i}).and_return(@response)
78
78
  @twitter.user(@user, :friends)
79
79
  end
80
80
 
81
81
  it "should create expected HTTP GET request when giving screen name" do
82
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:friends]}?#{{:screen_name => @screen_name}.to_http_str}").and_return(@response)
82
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:friends], {:screen_name => @screen_name}).and_return(@response)
83
83
  @twitter.user(@screen_name, :friends)
84
84
  end
85
85
 
@@ -122,7 +122,7 @@ describe Twitter::Client, "#my(:info)" do
122
122
  end
123
123
 
124
124
  it "should create expected HTTP GET request" do
125
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:info]}?#{{:id => @screen_name}.to_http_str}").and_return(@response)
125
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:info], {:id => @screen_name}).and_return(@response)
126
126
  @twitter.my(:info)
127
127
  end
128
128
 
@@ -160,7 +160,7 @@ describe Twitter::Client, "#my(:friends)" do
160
160
  end
161
161
 
162
162
  it "should create expected HTTP GET request" do
163
- @twitter.should_receive(:rest_oauth_connect).with(:get, "#{@uris[:friends]}?#{{:id => @screen_name}.to_http_str}").and_return(@response)
163
+ @twitter.should_receive(:rest_oauth_connect).with(:get, @uris[:friends], {:id => @screen_name}).and_return(@response)
164
164
  @twitter.my(:friends)
165
165
  end
166
166
 
@@ -41,19 +41,3 @@ describe Time, "#to_s" do
41
41
  end
42
42
  end
43
43
 
44
- # TODO: figure out how to stub the gem method to do what we want rather than this monstrousity. It is dependent on the system installation, which is always a bad thing. For now it will do so we can ship with 100% C0 coverage.
45
- describe Kernel, "#gem_present?" do
46
- before(:each) do
47
- @present_gem = "rake"
48
- @uninstalled_gem = "uninstalled-gem-crap"
49
- end
50
-
51
- it "should return true when a gem isn't present on system" do
52
- gem_present?(@present_gem).should eql(true)
53
- end
54
-
55
- it "should return false when a gem isn't present on system" do
56
- gem_present?(@uninstalled_gem).should eql(false)
57
- end
58
- end
59
-
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter4r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- - 0
10
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Susan Potter
@@ -15,18 +14,16 @@ autorequire: twitter
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-29 00:00:00 -05:00
17
+ date: 2010-09-07 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: oauth
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 13
30
27
  segments:
31
28
  - 0
32
29
  - 4
@@ -38,11 +35,9 @@ dependencies:
38
35
  name: json
39
36
  prerelease: false
40
37
  requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
39
  - - ">="
44
40
  - !ruby/object:Gem::Version
45
- hash: 17
46
41
  segments:
47
42
  - 1
48
43
  - 1
@@ -122,22 +117,18 @@ rdoc_options: []
122
117
  require_paths:
123
118
  - lib
124
119
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
120
  requirements:
127
121
  - - ">="
128
122
  - !ruby/object:Gem::Version
129
- hash: 59
130
123
  segments:
131
124
  - 1
132
125
  - 8
133
126
  - 6
134
127
  version: 1.8.6
135
128
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
129
  requirements:
138
130
  - - ">="
139
131
  - !ruby/object:Gem::Version
140
- hash: 3
141
132
  segments:
142
133
  - 0
143
134
  version: "0"
@@ -146,7 +137,7 @@ requirements:
146
137
  - json gem, version 0.4.3 or higher
147
138
  - jcode (for unicode support)
148
139
  rubyforge_project: twitter4r
149
- rubygems_version: 1.3.7
140
+ rubygems_version: 1.3.6
150
141
  signing_key:
151
142
  specification_version: 3
152
143
  summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.