Class: S3::Client::API
- Inherits:
-
Driver::API
- Object
- Driver::API
- S3::Client::API
- Defined in:
- lib/s3/client/api.rb,
lib/s3/client/api/storage.rb,
lib/s3/client/api/rest_parameter.rb
Defined Under Namespace
Modules: Storage Classes: RestParameter
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
Instance Method Summary collapse
- #download_signature(expire_at, bucket, output_object) ⇒ Object
- #execute_storage(rest_parameter, &block) ⇒ Object
- #force_path_style? ⇒ Boolean
-
#initialize(access_key_id, secret_access_key, endpoint: S3::Settings.endpoint, force_path_style: S3::Settings.force_path_style, location: S3::Settings.location, debug: S3::Settings.debug) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(access_key_id, secret_access_key, endpoint: S3::Settings.endpoint, force_path_style: S3::Settings.force_path_style, location: S3::Settings.location, debug: S3::Settings.debug) ⇒ API
Returns a new instance of API.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/s3/client/api.rb', line 8 def initialize(access_key_id, secret_access_key, endpoint: S3::Settings.endpoint, force_path_style: S3::Settings.force_path_style, location: S3::Settings.location, debug: S3::Settings.debug) require 'time' require 'base64' require 'rexml/document' require 'net/http' require 'xmlsimple' require 'ipaddr' require 'httpclient' require 'stringio' @access_key_id = access_key_id @secret_access_key = secret_access_key unless [TrueClass, FalseClass].any? { |c| force_path_style.kind_of?(c) } raise S3::Client::APIOptionInvalid.new("force_path_style is not boolean:#{force_path_style}") end unless [TrueClass, FalseClass].any? { |c| debug.kind_of?(c) } raise S3::Client::APIOptionInvalid.new("debug is not boolean:#{debug}") end @endpoint = endpoint @force_path_style = force_path_style @location = location @debug = debug @http_client = HTTPClient.new @http_client.connect_timeout = 300 @http_client.send_timeout = 300 @http_client.receive_timeout = 300 @http_client.debug_dev = STDERR if @debug end |
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
46 47 48 |
# File 'lib/s3/client/api.rb', line 46 def access_key_id @access_key_id end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
46 47 48 |
# File 'lib/s3/client/api.rb', line 46 def endpoint @endpoint end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
46 47 48 |
# File 'lib/s3/client/api.rb', line 46 def secret_access_key @secret_access_key end |
Instance Method Details
#download_signature(expire_at, bucket, output_object) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/s3/client/api.rb', line 86 def download_signature(expire_at, bucket, output_object) http_verb = "GET\n" content_md5 = "\n" content_type = "\n" expire = "#{expire_at}\n" string_to_sign = http_verb + content_md5 + content_type + expire + canonicalized_resource(bucket, output_object) digest = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA1.new, @secret_access_key, string_to_sign) Base64.encode64(digest).strip end |
#execute_storage(rest_parameter, &block) ⇒ Object
52 53 54 55 56 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 84 |
# File 'lib/s3/client/api.rb', line 52 def execute_storage(rest_parameter, &block) unless @access_key_id raise S3::Client::ParameterInvalid.new("missing access_key_id") end unless @secret_access_key raise S3::Client::ParameterInvalid.new("missing secret_access_key") end response = handle_api_failure(rest_parameter) do rest_client(:storage, rest_parameter, &block) end if response.present? data = if rest_parameter.raw_data? response.body else REXML::Document.new(response.body) end || '' if data.present? STDERR.print "\n\n" if @debug end data.instance_eval { class << self attr_accessor :headers end } data.headers = response.header return data.freeze end end |
#force_path_style? ⇒ Boolean
48 49 50 |
# File 'lib/s3/client/api.rb', line 48 def force_path_style? @force_path_style end |