Class: Resizing::Configuration
- Inherits:
-
Object
- Object
- Resizing::Configuration
- Defined in:
- lib/resizing/configuration.rb
Overview
Constant Summary collapse
- DEFAULT_HOST =
'https://img.resizing.net'
- DEFAULT_IMAGE_HOST =
'https://img.resizing.net'
- DEFAULT_VIDEO_HOST =
'https://video.resizing.net'
- DEFAULT_OPEN_TIMEOUT =
2
- DEFAULT_RESPONSE_TIMEOUT =
10
- TRANSFORM_OPTIONS =
%i[w width h height f format c crop q quality].freeze
Instance Attribute Summary collapse
-
#enable_mock ⇒ Object
readonly
Returns the value of attribute enable_mock.
-
#image_host ⇒ Object
readonly
Returns the value of attribute image_host.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#response_timeout ⇒ Object
readonly
Returns the value of attribute response_timeout.
-
#secret_token ⇒ Object
readonly
Returns the value of attribute secret_token.
-
#video_host ⇒ Object
readonly
Returns the value of attribute video_host.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #generate_auth_header ⇒ Object
-
#generate_identifier ⇒ Object
たぶんここにおくものではない もしくはキャッシュしない.
- #generate_image_id ⇒ Object
- #generate_image_url(image_id, version_id = nil, transforms = []) ⇒ Object
- #host ⇒ Object
-
#initialize(*attrs) ⇒ Configuration
constructor
A new instance of Configuration.
-
#transformation_path(transformations) ⇒ Object
this method should be divided other class.
Constructor Details
#initialize(*attrs) ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#enable_mock ⇒ Object (readonly)
Returns the value of attribute enable_mock.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def enable_mock @enable_mock end |
#image_host ⇒ Object (readonly)
Returns the value of attribute image_host.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def image_host @image_host end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def open_timeout @open_timeout end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def project_id @project_id end |
#response_timeout ⇒ Object (readonly)
Returns the value of attribute response_timeout.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def response_timeout @response_timeout end |
#secret_token ⇒ Object (readonly)
Returns the value of attribute secret_token.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def secret_token @secret_token end |
#video_host ⇒ Object (readonly)
Returns the value of attribute video_host.
18 19 20 |
# File 'lib/resizing/configuration.rb', line 18 def video_host @video_host end |
Instance Method Details
#==(other) ⇒ Object
91 92 93 94 95 96 97 |
# 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 ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/resizing/configuration.rb', line 49 def generate_auth_header = Time.now.to_i data = [, secret_token].join('|') token = Digest::SHA2.hexdigest(data) version = 'v1' [version, , token].join(',') end |
#generate_identifier ⇒ Object
たぶんここにおくものではない もしくはキャッシュしない
83 84 85 |
# File 'lib/resizing/configuration.rb', line 83 def generate_identifier "/projects/#{project_id}/upload/images/#{generate_image_id}" end |
#generate_image_id ⇒ Object
87 88 89 |
# File 'lib/resizing/configuration.rb', line 87 def generate_image_id ::SecureRandom.uuid end |
#generate_image_url(image_id, version_id = nil, transforms = []) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
44 45 46 47 |
# 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) ⇒ Object
this method should be divided other class
73 74 75 76 77 78 79 |
# 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 |