Class: S3::AWSAuthConnection
- Inherits:
-
Object
- Object
- S3::AWSAuthConnection
- Defined in:
- lib/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
- #check_bucket_exists(bucket) ⇒ Object
- #create_bucket(bucket, headers = {}) ⇒ Object
- #create_located_bucket(bucket, location = BucketLocation::DEFAULT, 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_location(bucket) ⇒ Object
- #get_bucket_logging(bucket, headers = {}) ⇒ Object
-
#initialize(aws_access_key_id, aws_secret_access_key, 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, is_secure = true, server = DEFAULT_HOST, port = , calling_format = CallingFormat::SUBDOMAIN) ⇒ AWSAuthConnection
Returns a new instance of AWSAuthConnection.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/S3.rb', line 145 def initialize(aws_access_key_id, aws_secret_access_key, 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 end |
Instance Attribute Details
#calling_format ⇒ Object
Returns the value of attribute calling_format.
143 144 145 |
# File 'lib/S3.rb', line 143 def calling_format @calling_format end |
Instance Method Details
#check_bucket_exists(bucket) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/S3.rb', line 167 def check_bucket_exists(bucket) begin make_request('HEAD', bucket, '', {}, {}) return true rescue Net::HTTPServerException response = $!.response return false if (response.code.to_i == 404) raise end end |
#create_bucket(bucket, headers = {}) ⇒ Object
156 157 158 |
# File 'lib/S3.rb', line 156 def create_bucket(bucket, headers={}) return Response.new(make_request('PUT', bucket, '', {}, headers)) end |
#create_located_bucket(bucket, location = BucketLocation::DEFAULT, headers = {}) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/S3.rb', line 160 def create_located_bucket(bucket, location=BucketLocation::DEFAULT, headers={}) if (location != BucketLocation::DEFAULT) xmlbody = "<CreateBucketConstraint><LocationConstraint>#{location}</LocationConstraint></CreateBucketConstraint>" end return Response.new(make_request('PUT', bucket, '', {}, headers, xmlbody)) end |
#delete(bucket, key, headers = {}) ⇒ Object
204 205 206 |
# File 'lib/S3.rb', line 204 def delete(bucket, key, headers={}) return Response.new(make_request('DELETE', bucket, CGI::escape(key), {}, headers)) end |
#delete_bucket(bucket, headers = {}) ⇒ Object
188 189 190 |
# File 'lib/S3.rb', line 188 def delete_bucket(bucket, headers={}) return Response.new(make_request('DELETE', bucket, '', {}, headers)) end |
#get(bucket, key, headers = {}) ⇒ Object
200 201 202 |
# File 'lib/S3.rb', line 200 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.
222 223 224 |
# File 'lib/S3.rb', line 222 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
216 217 218 |
# File 'lib/S3.rb', line 216 def get_bucket_acl(bucket, headers={}) return get_acl(bucket, '', headers) end |
#get_bucket_location(bucket) ⇒ Object
238 239 240 |
# File 'lib/S3.rb', line 238 def get_bucket_location(bucket) return LocationResponse.new(make_request('GET', bucket, '', {'location' => nil}, {})) end |
#get_bucket_logging(bucket, headers = {}) ⇒ Object
208 209 210 |
# File 'lib/S3.rb', line 208 def get_bucket_logging(bucket, headers={}) return GetResponse.new(make_request('GET', bucket, '', {'logging' => nil}, headers)) end |
#list_all_my_buckets(headers = {}) ⇒ Object
242 243 244 |
# File 'lib/S3.rb', line 242 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
179 180 181 182 183 184 185 186 |
# File 'lib/S3.rb', line 179 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
192 193 194 195 196 197 198 |
# File 'lib/S3.rb', line 192 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.
232 233 234 235 236 |
# File 'lib/S3.rb', line 232 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
226 227 228 |
# File 'lib/S3.rb', line 226 def put_bucket_acl(bucket, acl_xml_doc, headers={}) return put_acl(bucket, '', acl_xml_doc, headers) end |