Class: ImageFlux::Origin
- Inherits:
-
Object
- Object
- ImageFlux::Origin
- Defined in:
- lib/image_flux/origin.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#signing_secret ⇒ Object
readonly
Returns the value of attribute signing_secret.
-
#signing_version ⇒ Object
readonly
Returns the value of attribute signing_version.
Instance Method Summary collapse
- #base_url ⇒ Object
- #image_url(path, options = {}) ⇒ Object
-
#initialize(domain:, scheme: 'https', signing_version: '1', signing_secret: nil, **_options) ⇒ Origin
constructor
A new instance of Origin.
- #sign(path) ⇒ Object
Constructor Details
#initialize(domain:, scheme: 'https', signing_version: '1', signing_secret: nil, **_options) ⇒ Origin
Returns a new instance of Origin.
10 11 12 13 14 15 |
# File 'lib/image_flux/origin.rb', line 10 def initialize(domain:, scheme: 'https', signing_version: '1', signing_secret: nil, **) @domain = domain.to_s @scheme = scheme.to_s @signing_version = signing_version @signing_secret = signing_secret end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
9 10 11 |
# File 'lib/image_flux/origin.rb', line 9 def domain @domain end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
9 10 11 |
# File 'lib/image_flux/origin.rb', line 9 def scheme @scheme end |
#signing_secret ⇒ Object (readonly)
Returns the value of attribute signing_secret.
9 10 11 |
# File 'lib/image_flux/origin.rb', line 9 def signing_secret @signing_secret end |
#signing_version ⇒ Object (readonly)
Returns the value of attribute signing_version.
9 10 11 |
# File 'lib/image_flux/origin.rb', line 9 def signing_version @signing_version end |
Instance Method Details
#base_url ⇒ Object
17 18 19 |
# File 'lib/image_flux/origin.rb', line 17 def base_url @base_url ||= URI("#{@scheme}://#{@domain}/") end |
#image_url(path, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/image_flux/origin.rb', line 21 def image_url(path, = {}) path = "/#{path}" unless path.start_with?('/') = .merge(sig: sign(path)) if @signing_secret opt = ImageFlux::Option.new() path = "#{opt.prefix_path}#{path}" if opt.prefix_path query = opt.to_query url = base_url.dup url.path = query.length.zero? ? path : "/c/#{opt.to_query}#{path}" url end |
#sign(path) ⇒ Object
36 37 38 39 40 |
# File 'lib/image_flux/origin.rb', line 36 def sign(path) digest = OpenSSL::HMAC.digest('sha256', @signing_secret, path) "#{@signing_version}.#{Base64.urlsafe_encode64(digest)}" end |