1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

simplify by pushing query string building down into excon

This commit is contained in:
geemus 2010-06-05 14:19:39 -07:00
parent 6e156d0cfb
commit 4529a3444f
23 changed files with 32 additions and 61 deletions

View file

@ -1,7 +1,7 @@
source 'http://gemcutter.org'
gem 'rake'
gem 'excon', '>= 0.0.24'
gem 'excon', '>= 0.0.25'
gem 'formatador', ">= 0.0.10"
gem 'json', ">= 0"
gem 'mime-types', ">= 0"

View file

@ -31,7 +31,7 @@ dependencies:
excon:
group:
- :default
version: ">= 0.0.24"
version: ">= 0.0.25"
builder:
group:
- :default
@ -50,7 +50,7 @@ specs:
- builder:
version: 2.1.2
- excon:
version: 0.0.24
version: 0.0.25
- formatador:
version: 0.0.14
- gestalt:
@ -60,7 +60,7 @@ specs:
- mime-types:
version: "1.16"
- net-ssh:
version: 2.0.22
version: 2.0.23
- nokogiri:
version: 1.4.2
- rspec:
@ -69,7 +69,7 @@ specs:
version: 0.4.0
- shindo:
version: 0.1.4
hash: 3e4f041a5b790fadb4d85f239577c92b71b9dd78
hash: 47be4240cdce9d626cc1834c503ca8e275e76307
sources:
- Rubygems:
uri: http://gemcutter.org

View file

@ -38,11 +38,6 @@ module Fog
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
query = ''
for key, value in options
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
query.chop!
request({
:expects => 200,
:headers => {},
@ -50,7 +45,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucket.new,
:query => query
:query => options
})
end

View file

@ -35,7 +35,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::AccessControlList.new,
:query => 'acl'
:query => {'acl' => nil}
})
end

View file

@ -20,7 +20,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
:query => 'location'
:query => {'location' => nil}
})
end

View file

@ -35,7 +35,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketLogging.new,
:query => 'logging'
:query => {'logging' => nil}
})
end

View file

@ -53,11 +53,6 @@ module Fog
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
query = 'versions&'
for key, value in options
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
query.chop!
request({
:expects => 200,
:headers => {},
@ -65,7 +60,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketObjectVersions.new,
:query => query
:query => {'versions' => nil}.merge!(options)
})
end

View file

@ -25,7 +25,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketVersioning.new,
:query => 'versioning'
:query => {'versioning' => nil}
})
end

View file

@ -33,7 +33,7 @@ module Fog
raise ArgumentError.new('object_name is required')
end
if version_id = options.delete('versionId')
query = CGI.escape(version_id)
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']

View file

@ -34,9 +34,9 @@ module Fog
unless object_name
raise ArgumentError.new('object_name is required')
end
query = 'acl'
query = {'acl' => nil}
if version_id = options.delete('versionId')
query << "&#{CGI.escape(version_id)}"
query['versionId'] = version_id
end
request({
:expects => 200,

View file

@ -37,7 +37,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:path => CGI.escape(object_name),
:query => 'torrent'
:query => {'torrent' => nil}
})
end

View file

@ -20,7 +20,7 @@ module Fog
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
:query => 'requestPayment'
:query => {'requestPayment' => nil}
})
end

View file

@ -32,7 +32,7 @@ module Fog
raise ArgumentError.new('object_name is required')
end
if version_id = options.delete('versionId')
query = CGI.escape(version_id)
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']

View file

@ -62,7 +62,7 @@ DATA
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => 'acl'
:query => {'acl' => nil}
})
end

View file

@ -69,7 +69,7 @@ DATA
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => 'logging'
:query => {'logging' => nil}
})
end

View file

@ -22,7 +22,7 @@ DATA
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => 'versioning'
:query => {'versioning' => nil}
})
end

View file

@ -21,7 +21,7 @@ DATA
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => "requestPayment"
:query => {'requestPayment' => nil}
})
end

View file

@ -208,9 +208,13 @@ DATA
canonical_resource << "#{CGI.escape(subdomain).downcase}/"
end
canonical_resource << "#{params[:path]}"
if ['acl', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(params[:query])
canonical_resource << "?#{params[:query]}"
canonical_resource << '?'
for key in params[:query].keys
if ['acl', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(key)
canonical_resource << "#{key}&"
end
end
canonical_resource.chop!
string_to_sign << "#{canonical_resource}"
hmac = @hmac.update(string_to_sign)

View file

@ -18,23 +18,11 @@ module Fog
# * body<~Hash>:
# TODO
def create_block(product_id, template_id, options = {})
data = {
'product' => product_id,
'template' => template_id
}.merge!(options)
query = ''
for key, value in data
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
query.chop!
request(
# :body => data.to_json,
:expects => 200,
:method => 'POST',
:path => '/api/blocks.json',
:query => query
:query => {'product' => product_id, 'template' => templated_id}.merge!(query)
)
end

View file

@ -29,16 +29,11 @@ module Fog
# * 'last_modified'<~String> - Last modified timestamp
# * 'name'<~String> - Name of object
def get_container(container, options = {})
query = ''
for key, value in options.merge!({ 'format' => 'json' })
query << "#{key}=#{value}&"
end
query.chop!
response = storage_request(
:expects => 200,
:method => 'GET',
:path => container,
:query => query
:query => {'format' => 'json'}.merge!(options)
)
response
end

View file

@ -18,17 +18,11 @@ module Fog
# * 'count'<~Integer>: - Number of items in container
# * 'name'<~String>: - Name of container
def get_containers(options = {})
options = { 'format' => 'json' }.merge!(options)
query = ''
for key, value in options
query << "#{key}=#{CGI.escape(value)}&"
end
query.chop!
response = storage_request(
:expects => [200, 204],
:method => 'GET',
:path => '',
:query => query
:query => {'format' => 'json'}.merge!(options)
)
response
end

View file

@ -18,7 +18,7 @@ module Fog
:expects => 204,
:method => 'HEAD',
:path => container,
:query => 'format=json'
:query => {'format' => 'json'}
)
response
end

View file

@ -15,7 +15,7 @@ module Fog
:expects => 204,
:method => 'HEAD',
:path => '',
:query => 'format=json'
:query => {'format' => 'json'}
)
response
end