mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
update excon, pass a block instead of params[:block]
This commit is contained in:
parent
1a1985db25
commit
242d7a5088
7 changed files with 58 additions and 57 deletions
2
Gemfile
2
Gemfile
|
@ -1,7 +1,7 @@
|
||||||
source 'http://gemcutter.org'
|
source 'http://gemcutter.org'
|
||||||
|
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
gem 'excon', '>= 0.0.21'
|
gem 'excon', '>= 0.0.22'
|
||||||
gem 'formatador', ">= 0.0.10"
|
gem 'formatador', ">= 0.0.10"
|
||||||
gem 'json', ">= 0"
|
gem 'json', ">= 0"
|
||||||
gem 'mime-types', ">= 0"
|
gem 'mime-types', ">= 0"
|
||||||
|
|
88
Gemfile.lock
88
Gemfile.lock
|
@ -1,15 +1,56 @@
|
||||||
---
|
---
|
||||||
|
dependencies:
|
||||||
|
formatador:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0.0.10"
|
||||||
|
rake:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
ruby-hmac:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
mime-types:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
rspec:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
net-ssh:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
json:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
excon:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0.0.22"
|
||||||
|
shindo:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
|
nokogiri:
|
||||||
|
group:
|
||||||
|
- :default
|
||||||
|
version: ">= 0"
|
||||||
specs:
|
specs:
|
||||||
- rake:
|
- rake:
|
||||||
version: 0.8.7
|
version: 0.8.7
|
||||||
- excon:
|
- excon:
|
||||||
version: 0.0.21
|
version: 0.0.22
|
||||||
- formatador:
|
- formatador:
|
||||||
version: 0.0.14
|
version: 0.0.14
|
||||||
- gestalt:
|
- gestalt:
|
||||||
version: 0.0.6
|
version: 0.0.6
|
||||||
- json:
|
- json:
|
||||||
version: 1.4.2
|
version: 1.4.3
|
||||||
- mime-types:
|
- mime-types:
|
||||||
version: "1.16"
|
version: "1.16"
|
||||||
- net-ssh:
|
- net-ssh:
|
||||||
|
@ -22,48 +63,7 @@ specs:
|
||||||
version: 0.4.0
|
version: 0.4.0
|
||||||
- shindo:
|
- shindo:
|
||||||
version: 0.0.18
|
version: 0.0.18
|
||||||
hash: e443f12a9a7794f2ff4fc8e8d201b12b1e8b30bb
|
hash: a39d842433b002231eebfd269d32fe72b489b62f
|
||||||
sources:
|
sources:
|
||||||
- Rubygems:
|
- Rubygems:
|
||||||
uri: http://gemcutter.org
|
uri: http://gemcutter.org
|
||||||
dependencies:
|
|
||||||
formatador:
|
|
||||||
version: ">= 0.0.10"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
nokogiri:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
rake:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
rspec:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
ruby-hmac:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
mime-types:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
net-ssh:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
json:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
excon:
|
|
||||||
version: ">= 0.0.21"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
shindo:
|
|
||||||
version: ">= 0"
|
|
||||||
group:
|
|
||||||
- :default
|
|
||||||
|
|
|
@ -34,14 +34,13 @@ module Fog
|
||||||
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
|
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
|
||||||
headers.merge!(options)
|
headers.merge!(options)
|
||||||
request({
|
request({
|
||||||
:block => block,
|
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:idempotent => true,
|
:idempotent => true,
|
||||||
:method => 'GET',
|
:method => 'GET',
|
||||||
:path => CGI.escape(object_name)
|
:path => CGI.escape(object_name)
|
||||||
})
|
}, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_object_url(bucket_name, object_name, expires)
|
def get_object_url(bucket_name, object_name, expires)
|
||||||
|
|
|
@ -141,12 +141,12 @@ module Fog
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def request(params)
|
def request(params, &block)
|
||||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||||
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
||||||
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
|
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
|
||||||
|
|
||||||
response = @connection.request(params)
|
response = @connection.request(params, &block)
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,13 +5,15 @@ module Fog
|
||||||
@excon = Excon.new(url)
|
@excon = Excon.new(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def request(params)
|
def request(params, &block)
|
||||||
if parser = params.delete(:parser)
|
unless block_given?
|
||||||
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
if (parser = params.delete(:parser))
|
||||||
params[:block] = lambda { |chunk| body << chunk }
|
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
||||||
|
block = lambda { |chunk| body << chunk }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
response = @excon.request(params)
|
response = @excon.request(params, &block)
|
||||||
|
|
||||||
if parser
|
if parser
|
||||||
body.finish
|
body.finish
|
||||||
|
|
|
@ -112,7 +112,7 @@ module Fog
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
def storage_request(params, parse_json = true)
|
def storage_request(params, parse_json = true, &block)
|
||||||
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
|
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
|
||||||
response = @storage_connection.request({
|
response = @storage_connection.request({
|
||||||
:body => params[:body],
|
:body => params[:body],
|
||||||
|
@ -125,7 +125,7 @@ module Fog
|
||||||
:method => params[:method],
|
:method => params[:method],
|
||||||
:path => "#{@storage_path}/#{params[:path]}",
|
:path => "#{@storage_path}/#{params[:path]}",
|
||||||
:query => params[:query]
|
:query => params[:query]
|
||||||
})
|
}, &block)
|
||||||
if !response.body.empty? && parse_json
|
if !response.body.empty? && parse_json
|
||||||
response.body = JSON.parse(response.body)
|
response.body = JSON.parse(response.body)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:method => 'GET',
|
:method => 'GET',
|
||||||
:path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
|
:path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
|
||||||
}, false)
|
}, false, &block)
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue