Skip to content

Commit

Permalink
add connection resetting/persistent option to connections
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Jun 20, 2010
1 parent 7f91db2 commit 4b736a3
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,7 +1,7 @@
source 'http://gemcutter.org'

gem 'rake'
gem 'excon', '>= 0.1.0'
gem 'excon', '>= 0.1.1'
gem 'formatador', ">= 0.0.10"
gem 'json', ">= 0"
gem 'mime-types', ">= 0"
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -31,7 +31,7 @@ dependencies:
excon:
group:
- :default
version: ">= 0.1.0"
version: ">= 0.1.1"
builder:
group:
- :default
Expand All @@ -50,7 +50,7 @@ specs:
- builder:
version: 2.1.2
- excon:
version: 0.1.0
version: 0.1.1
- formatador:
version: 0.0.14
- gestalt:
Expand All @@ -69,7 +69,7 @@ specs:
version: 0.4.0
- shindo:
version: 0.1.6
hash: 8e1636212741876b9021efe871e1f6cd8969ab94
hash: 566a73651b09dfc6a62475d86d7f75545ce12990
sources:
- Rubygems:
uri: http://gemcutter.org
2 changes: 1 addition & 1 deletion fog.gemspec
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |s|

## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
s.add_dependency('excon', '>=0.1.0')
s.add_dependency('excon', '>=0.1.1')
s.add_dependency('formatador', '>=0.0.10')
s.add_dependency('json')
s.add_dependency('mime-types')
Expand Down
7 changes: 5 additions & 2 deletions lib/fog/aws/ec2.rb
Expand Up @@ -160,13 +160,16 @@ def initialize(options={})
end
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

private

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")

idempotent = params.delete(:idempotent)
parser = params.delete(:parser)

Expand Down
7 changes: 5 additions & 2 deletions lib/fog/aws/elb.rb
Expand Up @@ -63,13 +63,16 @@ def initialize(options={})
end
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

private

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")

idempotent = params.delete(:idempotent)
parser = params.delete(:parser)

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aws/s3.rb
Expand Up @@ -135,11 +135,11 @@ def initialize(options={})
end
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
reload
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent] || true)
end

def reload
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
@connection.reset
end

private
Expand Down
6 changes: 5 additions & 1 deletion lib/fog/aws/simpledb.rb
Expand Up @@ -68,6 +68,7 @@ def initialize(options={})
@nil_string = options[:nil_string]|| 'nil'
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

private
Expand Down Expand Up @@ -117,8 +118,11 @@ def encode_batch_attributes(items, replace_attributes = Hash.new([]))
encoded_attributes
end

def reload
@connection.reset
end

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
idempotent = params.delete(:idempotent)
parser = params.delete(:parser)

Expand Down
6 changes: 5 additions & 1 deletion lib/fog/bluebox.rb
Expand Up @@ -53,10 +53,14 @@ def initialize(options={})
@host = options[:bluebox_host] || "boxpanel.blueboxgrp.com"
@port = options[:bluebox_port] || 443
@scheme = options[:bluebox_scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
params[:headers] ||= {}
params[:headers].merge!({
'Authorization' => "Basic #{Base64.encode64([@bluebox_customer_id, @bluebox_api_key].join(':')).delete("\r\n")}"
Expand Down
10 changes: 9 additions & 1 deletion lib/fog/connection.rb
@@ -1,11 +1,15 @@
module Fog
class Connection

def initialize(url)
def initialize(url, persistent=false)
@excon = Excon.new(url)
@persistent = persistent
end

def request(params, &block)
unless @persistent
reset
end
unless block_given?
if (parser = params.delete(:parser))
body = Nokogiri::XML::SAX::PushParser.new(parser)
Expand All @@ -23,5 +27,9 @@ def request(params, &block)
response
end

def reset
@excon.reset
end

end
end
10 changes: 8 additions & 2 deletions lib/fog/rackspace/files.rb
Expand Up @@ -78,20 +78,27 @@ class Real
def initialize(options={})
credentials = Fog::Rackspace.authenticate(options)
@auth_token = credentials['X-Auth-Token']

cdn_uri = URI.parse(credentials['X-CDN-Management-Url'])
@cdn_host = cdn_uri.host
@cdn_path = cdn_uri.path
@cdn_port = cdn_uri.port
@cdn_scheme = cdn_uri.scheme
@cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}", options[:persistent])

storage_uri = URI.parse(credentials['X-Storage-Url'])
@storage_host = storage_uri.host
@storage_path = storage_uri.path
@storage_port = storage_uri.port
@storage_scheme = storage_uri.scheme
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}", options[:persistent])
end

def reload
@connection.reset
end

def cdn_request(params)
@cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}")
response = @cdn_connection.request(params.merge!({
:headers => {
'Content-Type' => 'application/json',
Expand All @@ -107,7 +114,6 @@ def cdn_request(params)
end

def storage_request(params, parse_json = true, &block)
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
response = @storage_connection.request(params.merge!({
:headers => {
'Content-Type' => 'application/json',
Expand Down
6 changes: 5 additions & 1 deletion lib/fog/rackspace/servers.rb
Expand Up @@ -73,10 +73,14 @@ def initialize(options={})
@path = uri.path
@port = uri.port
@scheme = uri.scheme
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
begin
response = @connection.request(params.merge!({
:headers => {
Expand Down
6 changes: 5 additions & 1 deletion lib/fog/slicehost.rb
Expand Up @@ -54,10 +54,14 @@ def initialize(options={})
@host = options[:host] || "api.slicehost.com"
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
params[:headers] ||= {}
params[:headers].merge!({
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
Expand Down
1 change: 1 addition & 0 deletions lib/fog/terremark/ecloud.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(options={})
@path = options[:path] || Fog::Terremark::Ecloud::Defaults::PATH
@port = options[:port] || Fog::Terremark::Ecloud::Defaults::PORT
@scheme = options[:scheme] || Fog::Terremark::Ecloud::Defaults::SCHEME
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

end
Expand Down
5 changes: 4 additions & 1 deletion lib/fog/terremark/shared.rb
Expand Up @@ -51,8 +51,11 @@ def auth_token
response.headers['Set-Cookie']
end

def reload
@connection.reset
end

def request(params)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
unless @cookie
@cookie = auth_token
end
Expand Down
1 change: 1 addition & 0 deletions lib/fog/terremark/vcloud.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(options={})
@path = options[:path] || Fog::Terremark::Vcloud::Defaults::PATH
@port = options[:port] || Fog::Terremark::Vcloud::Defaults::PORT
@scheme = options[:scheme] || Fog::Terremark::Vcloud::Defaults::SCHEME
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def default_vdc_id
Expand Down

0 comments on commit 4b736a3

Please sign in to comment.