Class: AwsSigner::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_signer/signature.rb

Constant Summary collapse

REQUIRED_OPTIONS =
[:file_name, :mime_type]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Signature

Public: Initialize a Signature object.



8
9
10
11
12
# File 'lib/aws_signer/signature.rb', line 8

def initialize(options = {})
  AwsSigner.validate_configuration!
  @options = Hashie::Mash.new(default_options.merge(options))
  validate_options!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/aws_signer/signature.rb', line 5

def options
  @options
end

Instance Method Details

#expirationObject

Public: The expiration of the signing request.

Returns a timestamp in Integer format (in seconds).



45
46
47
# File 'lib/aws_signer/signature.rb', line 45

def expiration
  @expiration ||= Time.now.to_i + (60 * options.request_expiration)
end

#public_urlObject

Public: The public url for the file being uploaded

Returns the url as a String.



17
18
19
# File 'lib/aws_signer/signature.rb', line 17

def public_url
  "#{AwsSigner.s3_base_url}/#{AwsSigner.upload_bucket}/#{file_path}"
end

#signed_urlObject

Public: The signed url for the file being uploaded. This includes the public url as well as all required signature parameters.

Returns the signed url as a String.



26
27
28
# File 'lib/aws_signer/signature.rb', line 26

def signed_url
  [public_url, signed_url_params.to_query].join('?')
end

#signed_url_paramsObject

Public: The signed url parameters.

Returns a Hash of required parameters for signing the public url.



34
35
36
37
38
39
40
# File 'lib/aws_signer/signature.rb', line 34

def signed_url_params
  {
    'AWSAccessKeyId' => AwsSigner.access_key_id,
    'Expires' => expiration,
    'Signature' => base64_encoded_signature
  }
end

#to_jsonObject

Public: The JSON representation of this object.

Returns a Hash containing the public and signed urls that can be serialized into JSON.



53
54
55
56
57
58
# File 'lib/aws_signer/signature.rb', line 53

def to_json
  {
    :public_url => public_url,
    :signed_url => signed_url
  }
end