Class: S3::Connection
- Inherits:
-
Object
- Object
- S3::Connection
- Defined in:
- lib/s3/connection.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#use_ssl ⇒ Object
(also: #use_ssl?)
Returns the value of attribute use_ssl.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #request(method, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 |
# File 'lib/s3/connection.rb', line 6 def initialize( = {}) @access_key_id = [:access_key_id] @secret_access_key = [:secret_access_key] @use_ssl = [:use_ssl] || false @debug = [:debug] @timeout = [:timeout] end |
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
3 4 5 |
# File 'lib/s3/connection.rb', line 3 def access_key_id @access_key_id end |
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/s3/connection.rb', line 3 def debug @debug end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
3 4 5 |
# File 'lib/s3/connection.rb', line 3 def secret_access_key @secret_access_key end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/s3/connection.rb', line 3 def timeout @timeout end |
#use_ssl ⇒ Object Also known as: use_ssl?
Returns the value of attribute use_ssl.
3 4 5 |
# File 'lib/s3/connection.rb', line 3 def use_ssl @use_ssl end |
Class Method Details
.parse_headers(headers) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/s3/connection.rb', line 57 def self.parse_headers(headers) interesting_keys = [:content_type, :x_amz_acl, :range, :if_modified_since, :if_unmodified_since, :if_match, :if_none_match, :content_disposition, :content_encoding, :x_amz_copy_source, :x_amz_metadata_directive, :x_amz_copy_source_if_match, :x_amz_copy_source_if_none_match, :x_amz_copy_source_if_unmodified_since, :x_amz_copy_source_if_modified_since] parsed_headers = {} if headers headers.each do |key, value| if interesting_keys.include?(key) parsed_key = key.to_s.gsub("_", "-") parsed_value = value case value when Range parsed_value = "bytes=#{value.first}-#{value.last}" end parsed_headers[parsed_key] = parsed_value end end end parsed_headers end |
.parse_params(params) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/s3/connection.rb', line 39 def self.parse_params(params) interesting_keys = [:max_keys, :prefix, :marker, :delimiter, :location] result = [] params.each do |key, value| if interesting_keys.include?(key) parsed_key = key.to_s.gsub("_", "-") case value when nil result << parsed_key else result << "#{parsed_key}=#{value}" end end end result.join("&") end |
Instance Method Details
#request(method, options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/s3/connection.rb', line 14 def request(method, ) host = [:host] || HOST path = [:path] or raise ArgumentError.new("no path given") body = [:body] params = [:params] headers = [:headers] if params params = params.is_a?(String) ? params : self.class.parse_params(params) path << "?#{params}" end path = URI.escape(path) request = request_class(method).new(path) headers = self.class.parse_headers(headers) headers.each do |key, value| request[key] = value end request.body = body send_request(host, request) end |