Browse files

Added support for HTTP proxies

  • Loading branch information...
1 parent 000a043 commit e99e0b698de2a66e7e7c08f9e4c9b8ffe83eacc8 @bkeepers bkeepers committed Apr 18, 2008
Showing with 18 additions and 5 deletions.
  1. +3 −0 CHANGELOG.txt
  2. +15 −5 lib/tinder/campfire.rb
View
3 CHANGELOG.txt
@@ -1,3 +1,6 @@
+0.1.7 - unreleased
+* Added support for HTTP proxies
+
0.1.6 - 2008-03-07
* Added Room#topic for getting the current topic [Even Weaver]
* Trap INT in #listen(&block) [borrowed from Chris Shea's Pyre]
View
20 lib/tinder/campfire.rb
@@ -11,14 +11,24 @@ class Campfire
attr_reader :subdomain, :uri
# Create a new connection to the campfire account with the given +subdomain+.
- # There's an +:ssl+ option to use SSL for the connection.
+ #
+ # == Options:
+ # * +:ssl+: use SSL for the connection, which is required if you have a Campfire SSL account.
+ # Defaults to false
+ # * +:proxy+: a proxy URI. (e.g. :proxy => 'http://user:pass@example.com:8000')
#
# c = Tinder::Campfire.new("mysubdomain", :ssl => true)
def initialize(subdomain, options = {})
options = { :ssl => false }.merge(options)
@cookie = nil
@subdomain = subdomain
@uri = URI.parse("#{options[:ssl] ? 'https' : 'http' }://#{subdomain}.campfirenow.com")
+ if options[:proxy]
+ uri = URI.parse(options[:proxy])
+ @http = Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password)
+ else
+ @http = Net::HTTP
+ end
@logged_in = false
end
@@ -32,7 +42,7 @@ def login(email, password)
# Returns true when successfully logged in
def logged_in?
- @logged_in === true
+ @logged_in == true
end
def logout
@@ -132,7 +142,7 @@ def prepare_request(request, options = {})
def perform_request(options = {}, &block)
@request = prepare_request(yield, options)
- http = Net::HTTP.new(uri.host, uri.port)
+ http = @http.new(uri.host, uri.port)
http.use_ssl = ssl?
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ssl?
@response = returning http.request(@request) do |response|
@@ -154,8 +164,8 @@ def flatten(params)
def verify_response(response, options = {})
if options.is_a?(Symbol)
codes = case options
- when :success then [200]
- when :redirect then 300..399
+ when :success; [200]
+ when :redirect; 300..399
else raise ArgumentError.new("Unknown response #{options}")
end
codes.include?(response.code.to_i)

0 comments on commit e99e0b6

Please sign in to comment.