Class: Resizing::Configuration
- Inherits:
-
Object
- Object
- Resizing::Configuration
- Defined in:
- lib/resizing/configuration.rb
Overview
Configuration class for Resizing client
-- usage. options = { host: 'https://www.resizing.net', project_id: '098a2a0d-0000-0000-0000-000000000000', secret_token: '4g1cshg......rbs6' } configuration = Resizing::Configuration.new(options) Resizing::Client.new(configuration) ++
Constant Summary collapse
- DEFAULT_HOST =
'https://img.resizing.net'- DEFAULT_IMAGE_HOST =
'https://img.resizing.net'- DEFAULT_VIDEO_HOST =
動画 API はサービス側で廃止されたため非推奨。将来のバージョンで削除する
VIDEO_HOST_FALLBACK- DEPRECATED_VIDEO_HOST_MESSAGE =
'[resizing] video_host is deprecated: ' \ 'the video API has been removed from Resizing and this value is no longer used. ' \ 'It will be deleted in a future version.'
- 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.
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
-
#initialize(*attrs) ⇒ Configuration
constructor
A new instance of Configuration.
-
#transformation_path(transformations) ⇒ Object
this method should be divided other class.
-
#video_host ⇒ Object
動画 API の廃止により非推奨。値は保持するが利用されない.
Constructor Details
#initialize(*attrs) ⇒ Configuration
Returns a new instance of Configuration.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/resizing/configuration.rb', line 34 def initialize(*attrs) case attr = attrs.first when Hash raise_configiration_error if attr[:project_id].nil? || attr[:secret_token].nil? raise_deprecated_host_error unless blank_value?(attr[:host]) 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 |
Instance Method Details
#==(other) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/resizing/configuration.rb', line 95 def ==(other) return false unless self.class == other.class return false unless @video_host == other.instance_variable_get(:@video_host) i[image_host project_id secret_token open_timeout response_timeout].all? do |name| send(name) == other.send(name) end end |
#generate_auth_header ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/resizing/configuration.rb', line 47 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
たぶんここにおくものではない もしくはキャッシュしない
81 82 83 |
# File 'lib/resizing/configuration.rb', line 81 def generate_identifier "/projects/#{project_id}/upload/images/#{generate_image_id}" end |
#generate_image_id ⇒ Object
85 86 87 |
# File 'lib/resizing/configuration.rb', line 85 def generate_image_id ::SecureRandom.uuid end |
#generate_image_url(image_id, version_id = nil, transforms = []) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/resizing/configuration.rb', line 55 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 |
#transformation_path(transformations) ⇒ Object
this method should be divided other class
71 72 73 74 75 76 77 |
# File 'lib/resizing/configuration.rb', line 71 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 |
#video_host ⇒ Object
動画 API の廃止により非推奨。値は保持するが利用されない
90 91 92 93 |
# File 'lib/resizing/configuration.rb', line 90 def video_host warn_video_host_deprecation @video_host end |