Class: SdbDal::S3::AWSAuthConnection
- Inherits:
-
Object
- Object
- SdbDal::S3::AWSAuthConnection
- Defined in:
- lib/sdb_dal/s3.rb
Overview
uses Net::HTTP to interface with S3. note that this interface should only be used for smaller objects, as it does not stream the data. if you were to download a 1gb file, it would require 1gb of memory. also, this class creates a new http connection each time. it would be greatly improved with some connection pooling.
Instance Attribute Summary collapse
-
#calling_format ⇒ Object
Returns the value of attribute calling_format.
Instance Method Summary collapse
- #copy(source_bucket, source_key, destination_bucket, destination_key, headers = {}) ⇒ Object
- #create_bucket(bucket, headers = {}) ⇒ Object
- #delete(bucket, key, headers = {}) ⇒ Object
- #delete_bucket(bucket, headers = {}) ⇒ Object
- #get(bucket, key, headers = {}) ⇒ Object
-
#get_acl(bucket, key, headers = {}) ⇒ Object
returns an xml document representing the access control list.
- #get_bucket_acl(bucket, headers = {}) ⇒ Object
- #get_bucket_logging(bucket, headers = {}) ⇒ Object
- #get_content_type(bucket, key, headers = {}) ⇒ Object
- #get_head(bucket, key, headers = {}) ⇒ Object
-
#initialize(aws_access_key_id, aws_secret_access_key, tokens = Array.new, is_secure = true, server = DEFAULT_HOST, port = , calling_format = CallingFormat::SUBDOMAIN) ⇒ AWSAuthConnection
constructor
A new instance of AWSAuthConnection.
- #list_all_my_buckets(headers = {}) ⇒ Object
-
#list_bucket(bucket, options = {}, headers = {}) ⇒ Object
takes options :prefix, :marker, :max_keys, and :delimiter.
- #put(bucket, key, object, headers = {}) ⇒ Object
-
#put_acl(bucket, key, acl_xml_doc, headers = {}) ⇒ Object
sets the access control policy for the given resource.
- #put_bucket_acl(bucket, acl_xml_doc, headers = {}) ⇒ Object
- #put_bucket_logging(bucket, logging_xml_doc, headers = {}) ⇒ Object
Constructor Details
#initialize(aws_access_key_id, aws_secret_access_key, tokens = Array.new, is_secure = true, server = DEFAULT_HOST, port = , calling_format = CallingFormat::SUBDOMAIN) ⇒ AWSAuthConnection
Returns a new instance of AWSAuthConnection.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/sdb_dal/s3.rb', line 141 def initialize(aws_access_key_id, aws_secret_access_key, tokens=Array.new, is_secure=true, server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure], calling_format=CallingFormat::SUBDOMAIN) @aws_access_key_id = aws_access_key_id @aws_secret_access_key = aws_secret_access_key @server = server @is_secure = is_secure @calling_format = calling_format @port = port @init_headers = {} if tokens && !tokens.empty? @init_headers[AMAZON_TOKEN_HEADER_PREFIX] = tokens.join(',') end end |
Instance Attribute Details
#calling_format ⇒ Object
Returns the value of attribute calling_format.
139 140 141 |
# File 'lib/sdb_dal/s3.rb', line 139 def calling_format @calling_format end |
Instance Method Details
#copy(source_bucket, source_key, destination_bucket, destination_key, headers = {}) ⇒ Object
185 186 187 188 189 |
# File 'lib/sdb_dal/s3.rb', line 185 def copy(source_bucket, source_key, destination_bucket,destination_key, headers={}) headers['x-amz-copy-source']="#{source_bucket}/#{source_key}" headers['x-amz-metadata-directive']="REPLACE " return GetResponse.new(make_request('PUT', destination_bucket, CGI::escape(destination_key),{}, headers)) end |
#create_bucket(bucket, headers = {}) ⇒ Object
160 161 162 |
# File 'lib/sdb_dal/s3.rb', line 160 def create_bucket(bucket, headers={}) return Response.new(make_request('PUT', bucket, '', {}, headers)) end |
#delete(bucket, key, headers = {}) ⇒ Object
210 211 212 |
# File 'lib/sdb_dal/s3.rb', line 210 def delete(bucket, key, headers={}) return Response.new(make_request('DELETE', bucket, CGI::escape(key), {}, headers)) end |
#delete_bucket(bucket, headers = {}) ⇒ Object
174 175 176 |
# File 'lib/sdb_dal/s3.rb', line 174 def delete_bucket(bucket, headers={}) return Response.new(make_request('DELETE', bucket, '', {}, headers)) end |
#get(bucket, key, headers = {}) ⇒ Object
206 207 208 |
# File 'lib/sdb_dal/s3.rb', line 206 def get(bucket, key, headers={}) return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {}, headers)) end |
#get_acl(bucket, key, headers = {}) ⇒ Object
returns an xml document representing the access control list. this could be parsed into an object.
228 229 230 |
# File 'lib/sdb_dal/s3.rb', line 228 def get_acl(bucket, key, headers={}) return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {'acl' => nil}, headers)) end |
#get_bucket_acl(bucket, headers = {}) ⇒ Object
222 223 224 |
# File 'lib/sdb_dal/s3.rb', line 222 def get_bucket_acl(bucket, headers={}) return get_acl(bucket, '', headers) end |
#get_bucket_logging(bucket, headers = {}) ⇒ Object
214 215 216 |
# File 'lib/sdb_dal/s3.rb', line 214 def get_bucket_logging(bucket, headers={}) return GetResponse.new(make_request('GET', bucket, '', {'logging' => nil}, headers)) end |
#get_content_type(bucket, key, headers = {}) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/sdb_dal/s3.rb', line 194 def get_content_type(bucket, key, headers={}) response= get_head(bucket, key, headers) if response.http_response.code=='404' return nil elsif response.http_response.code=='200' return response.http_response.header.content_type end raise response.http_response.code end |
#get_head(bucket, key, headers = {}) ⇒ Object
191 192 193 |
# File 'lib/sdb_dal/s3.rb', line 191 def get_head(bucket, key, headers={}) return GetResponse.new(make_request('HEAD',bucket, CGI::escape(key),{}, headers)) end |
#list_all_my_buckets(headers = {}) ⇒ Object
244 245 246 |
# File 'lib/sdb_dal/s3.rb', line 244 def list_all_my_buckets(headers={}) return ListAllMyBucketsResponse.new(make_request('GET', '', '', {}, headers)) end |
#list_bucket(bucket, options = {}, headers = {}) ⇒ Object
takes options :prefix, :marker, :max_keys, and :delimiter
165 166 167 168 169 170 171 172 |
# File 'lib/sdb_dal/s3.rb', line 165 def list_bucket(bucket, ={}, headers={}) path_args = {} .each { |k, v| path_args[k] = v.to_s } return ListBucketResponse.new(make_request('GET', bucket, '', path_args, headers)) end |
#put(bucket, key, object, headers = {}) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/sdb_dal/s3.rb', line 178 def put(bucket, key, object, headers={}) object = S3Object.new(object) if not object.instance_of? S3Object return Response.new( make_request('PUT', bucket, CGI::escape(key), {}, headers, object.data, object.) ) end |
#put_acl(bucket, key, acl_xml_doc, headers = {}) ⇒ Object
sets the access control policy for the given resource. acl_xml_doc must be a string in the acl xml format.
238 239 240 241 242 |
# File 'lib/sdb_dal/s3.rb', line 238 def put_acl(bucket, key, acl_xml_doc, headers={}) return Response.new( make_request('PUT', bucket, CGI::escape(key), {'acl' => nil}, headers, acl_xml_doc, {}) ) end |
#put_bucket_acl(bucket, acl_xml_doc, headers = {}) ⇒ Object
232 233 234 |
# File 'lib/sdb_dal/s3.rb', line 232 def put_bucket_acl(bucket, acl_xml_doc, headers={}) return put_acl(bucket, '', acl_xml_doc, headers) end |