Module | AWS::S3::Connection::Management::ClassMethods |
In: |
lib/aws/s3/connection.rb
|
Manage the creation and destruction of connections for AWS::S3::Base and its subclasses. Connections are created with establish_connection!.
Returns true if a connection has been made yet.
# File lib/aws/s3/connection.rb, line 218 218: def connected? 219: !connections.empty? 220: end
Returns the connection for the current class, or Base‘s default connection if the current class does not have its own connection.
If not connection has been established yet, NoConnectionEstablished will be raised.
# File lib/aws/s3/connection.rb, line 209 209: def connection 210: if connected? 211: connections[connection_name] || default_connection 212: else 213: raise NoConnectionEstablished 214: end 215: end
Removes the connection for the current class. If there is no connection for the current class, the default connection will be removed.
# File lib/aws/s3/connection.rb, line 224 224: def disconnect(name = connection_name) 225: name = default_connection unless connections.has_key?(name) 226: connection = connections[name] 227: connection.http.finish if connection.persistent? 228: connections.delete(name) 229: end
Clears all connections, from all classes, with prejudice.
# File lib/aws/s3/connection.rb, line 232 232: def disconnect! 233: connections.each_key {|connection| disconnect(connection)} 234: end
Creates a new connection with which to make requests to the S3 servers for the calling class.
AWS::S3::Base.establish_connection!(:access_key_id => '...', :secret_access_key => '...')
You can set connections for every subclass of AWS::S3::Base. Once the initial connection is made on Base, all subsequent connections will inherit whatever values you don‘t specify explictly. This allows you to customize details of the connection, such as what server the requests are made to, by just specifying one option.
AWS::S3::Bucket.established_connection!(:use_ssl => true)
The Bucket connection would inherit the :access_key_id and the :secret_access_key from Base‘s connection. Unlike the Base connection, all Bucket requests would be made over SSL.
If any of these required arguments is missing, a MissingAccessKey exception will be raised.
or your own domain‘s cname if you are using virtual hosted buckets. Defaults to s3.amazonaws.com.
argument is set.
will be implicitly set to 443, unless specified otherwise. Defaults to false.
performance increase but for long running processes some firewalls may find the long lived connection suspicious and close the connection. If you run into connection errors, try setting :persistent to false. Defaults to false.
with the :proxy option. The :host setting is required if specifying a :proxy.
AWS::S3::Bucket.established_connection!(:proxy => { :host => '...', :port => 8080, :user => 'marcel', :password => 'secret' })
# File lib/aws/s3/connection.rb, line 198 198: def establish_connection!(options = {}) 199: # After you've already established the default connection, just specify 200: # the difference for subsequent connections 201: options = default_connection.options.merge(options) if connected? 202: connections[connection_name] = Connection.connect(options) 203: end