Class: AuthenticImage::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/authentic_image/request.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, prefix:, signing_key:, digest: "sha1", bucket:, key:, region: "full", size: "full", rotation: "0", quality: "default", format: "jpg", version: 1) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/authentic_image/request.rb', line 6

def initialize(host:, prefix:, signing_key:, digest: "sha1", bucket:, key:, region: "full", size: "full", rotation: "0", quality: "default", format: "jpg", version: 1)
  @host        = host
  @prefix      = prefix
  @signing_key = signing_key
  @digest      = OpenSSL::Digest.new(digest)
  @bucket      = bucket
  @key         = key
  @region      = region
  @size        = size
  @rotation    = rotation
  @quality     = quality
  @format      = format
  @version     = version
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



23
24
25
# File 'lib/authentic_image/request.rb', line 23

def bucket
  @bucket
end

#formatObject (readonly)

Returns the value of attribute format.



33
34
35
# File 'lib/authentic_image/request.rb', line 33

def format
  @format
end

#hostObject (readonly)

Returns the value of attribute host.



21
22
23
# File 'lib/authentic_image/request.rb', line 21

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



23
24
25
# File 'lib/authentic_image/request.rb', line 23

def key
  @key
end

#prefixObject (readonly)

Returns the value of attribute prefix.



21
22
23
# File 'lib/authentic_image/request.rb', line 21

def prefix
  @prefix
end

#qualityObject (readonly)

Returns the value of attribute quality.



31
32
33
# File 'lib/authentic_image/request.rb', line 31

def quality
  @quality
end

#regionObject (readonly)

Returns the value of attribute region.



25
26
27
# File 'lib/authentic_image/request.rb', line 25

def region
  @region
end

#rotationObject (readonly)

Returns the value of attribute rotation.



29
30
31
# File 'lib/authentic_image/request.rb', line 29

def rotation
  @rotation
end

#sizeObject (readonly)

Returns the value of attribute size.



27
28
29
# File 'lib/authentic_image/request.rb', line 27

def size
  @size
end

#versionObject (readonly)

Returns the value of attribute version.



35
36
37
# File 'lib/authentic_image/request.rb', line 35

def version
  @version
end

Instance Method Details

#identifierObject



37
38
39
# File 'lib/authentic_image/request.rb', line 37

def identifier
  CGI.escape("#{bucket}/#{key}")
end

#pathObject



41
42
43
# File 'lib/authentic_image/request.rb', line 41

def path
  "#{prefix}/#{identifier}/#{region}/#{size}/#{rotation}/#{quality}.#{format}"
end

#signatureObject



45
46
47
# File 'lib/authentic_image/request.rb', line 45

def signature
  OpenSSL::HMAC.hexdigest(digest, signing_key, path)
end

#to_sObject



53
54
55
# File 'lib/authentic_image/request.rb', line 53

def to_s
  url
end

#urlObject



49
50
51
# File 'lib/authentic_image/request.rb', line 49

def url
  "#{host}#{path}?sig=#{signature}&ver=#{version}"
end