class Resizing::Configuration
Configuration
class for Resizing
client¶ ↑
Constants
- DEFAULT_HOST
- DEFAULT_IMAGE_HOST
- DEFAULT_OPEN_TIMEOUT
- DEFAULT_RESPONSE_TIMEOUT
- DEFAULT_VIDEO_HOST
- TRANSFORM_OPTIONS
Attributes
enable_mock[R]
image_host[R]
open_timeout[R]
project_id[R]
response_timeout[R]
secret_token[R]
video_host[R]
Public Class Methods
new(*attrs)
click to toggle source
# File lib/resizing/configuration.rb, line 27 def initialize(*attrs) case attr = attrs.first when Hash if attr[:project_id].nil? || attr[:secret_token].nil? raise_configiration_error end if attr[:host].present? raise_configiration_error end initialize_by_hash attr return end raise_configiration_error end
Public Instance Methods
==(other)
click to toggle source
# File lib/resizing/configuration.rb, line 91 def ==(other) return false unless self.class == other.class %i[image_host video_host project_id secret_token open_timeout response_timeout].all? do |name| send(name) == other.send(name) end end
generate_auth_header()
click to toggle source
# File lib/resizing/configuration.rb, line 49 def generate_auth_header current_timestamp = Time.now.to_i data = [current_timestamp, secret_token].join('|') token = Digest::SHA2.hexdigest(data) version = 'v1' [version, current_timestamp, token].join(',') end
generate_identifier()
click to toggle source
たぶんここにおくものではない もしくはキャッシュしない
# File lib/resizing/configuration.rb, line 83 def generate_identifier "/projects/#{project_id}/upload/images/#{generate_image_id}" end
generate_image_id()
click to toggle source
# File lib/resizing/configuration.rb, line 87 def generate_image_id ::SecureRandom.uuid end
generate_image_url(image_id, version_id = nil, transforms = [])
click to toggle source
# File lib/resizing/configuration.rb, line 57 def generate_image_url(image_id, version_id = nil, transforms = []) path = transformation_path(transforms) version = if version_id.nil? nil else "v#{version_id}" end parts = [] parts << image_id parts << version if version parts << path unless path.empty? "#{image_host}/projects/#{project_id}/upload/images/#{parts.join('/')}" end
host()
click to toggle source
# File lib/resizing/configuration.rb, line 44 def host Kernel.warn "[DEPRECATED] The Configuration#host is deprecated. Use Configuration#image_host." self.image_host end
transformation_path(transformations)
click to toggle source
this method should be divided other class
# File lib/resizing/configuration.rb, line 73 def transformation_path(transformations) transformations = [transformations] if transformations.is_a? Hash transformations.map do |transform| transform.slice(*TRANSFORM_OPTIONS).map { |key, value| [key, value].join('_') }.join(',') end.join('/') end
Private Instance Methods
initialize_by_hash(attr)
click to toggle source
# File lib/resizing/configuration.rb, line 105 def initialize_by_hash(attr) # @host = attr[:host].dup.freeze || DEFAULT_HOST @image_host = attr[:image_host].dup.freeze || DEFAULT_IMAGE_HOST @video_host = attr[:video_host].dup.freeze || DEFAULT_VIDEO_HOST @project_id = attr[:project_id].dup.freeze @secret_token = attr[:secret_token].dup.freeze @open_timeout = attr[:open_timeout] || DEFAULT_OPEN_TIMEOUT @response_timeout = attr[:response_timeout] || DEFAULT_RESPONSE_TIMEOUT @enable_mock = attr[:enable_mock] || false end
raise_configiration_error()
click to toggle source
# File lib/resizing/configuration.rb, line 101 def raise_configiration_error raise ConfigurationError, 'need hash and some keys like :image_host, video_host, :project_id, :secret_token' end