grackle 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.1.8 (2010-2-2)
2
+ * Added proxy support to Grackle::Transport via proxy attribute. Can specify a Proc that returns a Net::HTTP subclass or a Net::HTTP subclass directly. Typically this will be from Net::HTTP.Proxy.
3
+
1
4
  == 0.1.7 (2009-12-13)
2
5
  * Fixed a bug in Ruby 1.9 where the client was incorrectly handling request method parameters
3
6
  * Fixed a bug in the _ method that wasn't correctly appending numeric path elements
data/grackle.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{grackle}
5
- s.version = "0.1.7"
5
+ s.version = "0.1.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Hayes Davis"]
9
- s.date = %q{2009-12-13}
9
+ s.date = %q{2010-2-2}
10
10
  s.description = %q{Grackle is a lightweight library for the Twitter REST and Search API.}
11
11
  s.email = %q{hayes@appozite.com}
12
12
  s.files = ["CHANGELOG.rdoc", "README.rdoc", "grackle.gemspec", "lib/grackle.rb", "lib/grackle/client.rb", "lib/grackle/handlers.rb", "lib/grackle/transport.rb", "lib/grackle/utils.rb", "test/test_grackle.rb", "test/test_helper.rb", "test/test_client.rb", "test/test_handlers.rb"]
@@ -13,7 +13,7 @@ module Grackle
13
13
 
14
14
  class Transport
15
15
 
16
- attr_accessor :debug
16
+ attr_accessor :debug, :proxy
17
17
 
18
18
  CRLF = "\r\n"
19
19
  DEFAULT_REDIRECT_LIMIT = 5
@@ -46,7 +46,7 @@ module Grackle
46
46
  end
47
47
 
48
48
  def execute_request(method,url,options={})
49
- conn = Net::HTTP.new(url.host, url.port)
49
+ conn = http_class.new(url.host, url.port)
50
50
  conn.use_ssl = (url.scheme == 'https')
51
51
  if conn.use_ssl?
52
52
  configure_ssl(conn)
@@ -199,6 +199,18 @@ module Grackle
199
199
  end
200
200
  end
201
201
 
202
+ def http_class
203
+ if proxy
204
+ if proxy.kind_of?(Proc)
205
+ proxy.call(self)
206
+ else
207
+ proxy
208
+ end
209
+ else
210
+ Net::HTTP
211
+ end
212
+ end
213
+
202
214
  def configure_ssl(conn)
203
215
  if self.class.ca_cert_file
204
216
  conn.verify_mode = OpenSSL::SSL::VERIFY_PEER
data/lib/grackle.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Grackle
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
data/test/test_client.rb CHANGED
@@ -21,7 +21,24 @@ class TestClient < Test::Unit::TestCase
21
21
  self.class.response
22
22
  end
23
23
  end
24
- end
24
+ end
25
+
26
+ class MockProxy < Net::HTTP
27
+ class << self
28
+ attr_accessor :started
29
+ [:response,:request,:last_instance,:responder].each do |m|
30
+ class_eval "
31
+ def #{m}; Net::HTTP.#{m}; end
32
+ def #{m}=(val); Net::HTTP.#{m} = val; end
33
+ "
34
+ end
35
+ end
36
+
37
+ def start
38
+ self.class.started = true
39
+ super
40
+ end
41
+ end
25
42
 
26
43
  #Mock responses that conform to HTTPResponse's interface
27
44
  class MockResponse < Net::HTTPResponse
@@ -258,6 +275,24 @@ class TestClient < Test::Unit::TestCase
258
275
  assert_equal(12345,value.id)
259
276
  end
260
277
 
278
+ def test_transport_proxy_setting_is_used
279
+ client = new_client(200,'{"id":12345,"screen_name":"test_user"}')
280
+ called = false
281
+ call_trans = nil
282
+ client.transport.proxy = Proc.new {|trans| call_trans = trans; called = true; MockProxy }
283
+ client.users.show._(12345).json?
284
+ assert(called,"Proxy proc should be called during request")
285
+ assert(MockProxy.started,"Proxy should have been called")
286
+ assert_equal(client.transport,call_trans,"Proxy should have been called with transport")
287
+ MockProxy.started = false
288
+ client.transport.proxy = MockProxy
289
+ client.users.show._(12345).json?
290
+ assert(MockProxy.started,"Proxy should have been called")
291
+ MockProxy.started = false
292
+ client.transport.proxy = nil
293
+ assert_equal(false,MockProxy.started,"Proxy should not have been called")
294
+ end
295
+
261
296
  private
262
297
  def with_http_responder(responder)
263
298
  Net::HTTP.responder = responder
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grackle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hayes Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-13 00:00:00 -06:00
12
+ date: 2010-02-02 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency