Sha256: 681526b0c9400cad486d089f50a45d5ad0e58e9336ce3f9f93e267d0ab84e0db

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

module S3Lib
  require 'time'
  
  def self.request(verb, request_path, headers = {})
    s3requester = AuthenticatedRequest.new()
    s3requester.make_authenticated_request(verb, request_path, headers)
  end  
  
  class AuthenticatedRequest
    
    POSITIONAL_HEADERS = ['content-md5', 'content-type', 'date']      
    
    def make_authenticated_request(verb, request_path, headers = {})
      @verb = verb
      @headers = headers
      fix_date
    end
    
    private
    
    def fix_date
      @headers['date'] ||= Time.now.httpdate
    end
  
    def canonical_string
      "#{@verb.to_s.upcase}\n#{canonicalized_headers}"
    end
    
    def canonicalized_headers
      "#{canonicalized_positional_headers}"
    end
    
    def canonicalized_positional_headers
      POSITIONAL_HEADERS.collect do |header|
        (@headers[header] || "") + "\n"
      end.join
    end    
  
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
spatten-s3lib-0.0.1 lib/s3_authenticator_dev_private.rb
s3lib-0.1.1 lib/s3_authenticator_dev_private.rb
s3lib-0.1.0 lib/s3_authenticator_dev_private.rb