Class: Uploadcare::Configuration
- Inherits:
-
Object
- Object
- Uploadcare::Configuration
- Defined in:
- lib/uploadcare/configuration.rb
Overview
Configuration container for client defaults and per-client overrides.
Constant Summary collapse
- DEFAULTS =
Default configuration values used as the template for new instances.
{ public_key: nil, secret_key: nil, auth_type: 'Uploadcare', multipart_size_threshold: 100 * 1024 * 1024, rest_api_root: 'https://api.uploadcare.com', upload_api_root: 'https://upload.uploadcare.com', max_request_tries: 100, base_request_sleep: 1, # seconds max_request_sleep: 60.0, # seconds sign_uploads: false, upload_signature_lifetime: 30 * 60, # seconds max_throttle_attempts: 5, upload_threads: 2, # used for multiupload only ATM framework_data: '', file_chunk_size: 100, logger: nil, use_subdomains: false, cdn_base_postfix: 'https://ucarecd.net/', default_cdn_base: 'https://ucarecdn.com/', multipart_chunk_size: 5 * 1024 * 1024, # 5MB chunks for multipart upload upload_timeout: 60, # seconds max_upload_retries: 3 # retry failed uploads 3 times }.freeze
Instance Attribute Summary collapse
-
#auth_type ⇒ Object
Returns the value of attribute auth_type.
-
#base_request_sleep ⇒ Object
Returns the value of attribute base_request_sleep.
-
#cdn_base_postfix ⇒ Object
Returns the value of attribute cdn_base_postfix.
-
#default_cdn_base ⇒ Object
Returns the value of attribute default_cdn_base.
-
#file_chunk_size ⇒ Object
Returns the value of attribute file_chunk_size.
-
#framework_data ⇒ Object
Returns the value of attribute framework_data.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_request_sleep ⇒ Object
Returns the value of attribute max_request_sleep.
-
#max_request_tries ⇒ Object
Returns the value of attribute max_request_tries.
-
#max_throttle_attempts ⇒ Object
Returns the value of attribute max_throttle_attempts.
-
#max_upload_retries ⇒ Object
Returns the value of attribute max_upload_retries.
-
#multipart_chunk_size ⇒ Object
Returns the value of attribute multipart_chunk_size.
-
#multipart_size_threshold ⇒ Object
Returns the value of attribute multipart_size_threshold.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#rest_api_root ⇒ Object
Returns the value of attribute rest_api_root.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#sign_uploads ⇒ Object
Returns the value of attribute sign_uploads.
-
#upload_api_root ⇒ Object
Returns the value of attribute upload_api_root.
-
#upload_signature_lifetime ⇒ Object
Returns the value of attribute upload_signature_lifetime.
-
#upload_threads ⇒ Object
Returns the value of attribute upload_threads.
-
#upload_timeout ⇒ Object
Returns the value of attribute upload_timeout.
-
#use_subdomains ⇒ Object
Returns the value of attribute use_subdomains.
Instance Method Summary collapse
-
#cdn_base ⇒ String
Resolve the CDN base URL for this configuration.
-
#custom_cname ⇒ String
Build the deterministic subdomain prefix for the configured public key.
-
#initialize(**options) ⇒ Configuration
constructor
A new instance of Configuration.
-
#to_h ⇒ Hash
Convert this configuration to a serializable hash.
-
#with(**options) ⇒ Uploadcare::Configuration
Clone this configuration with overrides.
Constructor Details
#initialize(**options) ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/uploadcare/configuration.rb', line 40 def initialize(**) values = DEFAULTS.merge() values[:public_key] = ENV.fetch('UPLOADCARE_PUBLIC_KEY', '') unless .key?(:public_key) values[:secret_key] = ENV.fetch('UPLOADCARE_SECRET_KEY', '') unless .key?(:secret_key) values.each do |attribute, value| send("#{attribute}=", value) end @logger ||= Logger.new($stdout) end |
Instance Attribute Details
#auth_type ⇒ Object
Returns the value of attribute auth_type.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def auth_type @auth_type end |
#base_request_sleep ⇒ Object
Returns the value of attribute base_request_sleep.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def base_request_sleep @base_request_sleep end |
#cdn_base_postfix ⇒ Object
Returns the value of attribute cdn_base_postfix.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def cdn_base_postfix @cdn_base_postfix end |
#default_cdn_base ⇒ Object
Returns the value of attribute default_cdn_base.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def default_cdn_base @default_cdn_base end |
#file_chunk_size ⇒ Object
Returns the value of attribute file_chunk_size.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def file_chunk_size @file_chunk_size end |
#framework_data ⇒ Object
Returns the value of attribute framework_data.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def framework_data @framework_data end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def logger @logger end |
#max_request_sleep ⇒ Object
Returns the value of attribute max_request_sleep.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def max_request_sleep @max_request_sleep end |
#max_request_tries ⇒ Object
Returns the value of attribute max_request_tries.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def max_request_tries @max_request_tries end |
#max_throttle_attempts ⇒ Object
Returns the value of attribute max_throttle_attempts.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def max_throttle_attempts @max_throttle_attempts end |
#max_upload_retries ⇒ Object
Returns the value of attribute max_upload_retries.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def max_upload_retries @max_upload_retries end |
#multipart_chunk_size ⇒ Object
Returns the value of attribute multipart_chunk_size.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def multipart_chunk_size @multipart_chunk_size end |
#multipart_size_threshold ⇒ Object
Returns the value of attribute multipart_size_threshold.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def multipart_size_threshold @multipart_size_threshold end |
#public_key ⇒ Object
Returns the value of attribute public_key.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def public_key @public_key end |
#rest_api_root ⇒ Object
Returns the value of attribute rest_api_root.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def rest_api_root @rest_api_root end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def secret_key @secret_key end |
#sign_uploads ⇒ Object
Returns the value of attribute sign_uploads.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def sign_uploads @sign_uploads end |
#upload_api_root ⇒ Object
Returns the value of attribute upload_api_root.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def upload_api_root @upload_api_root end |
#upload_signature_lifetime ⇒ Object
Returns the value of attribute upload_signature_lifetime.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def upload_signature_lifetime @upload_signature_lifetime end |
#upload_threads ⇒ Object
Returns the value of attribute upload_threads.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def upload_threads @upload_threads end |
#upload_timeout ⇒ Object
Returns the value of attribute upload_timeout.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def upload_timeout @upload_timeout end |
#use_subdomains ⇒ Object
Returns the value of attribute use_subdomains.
7 8 9 |
# File 'lib/uploadcare/configuration.rb', line 7 def use_subdomains @use_subdomains end |
Instance Method Details
#cdn_base ⇒ String
Resolve the CDN base URL for this configuration.
61 62 63 64 65 |
# File 'lib/uploadcare/configuration.rb', line 61 def cdn_base return Uploadcare::CnameGenerator.cdn_base_postfix(config: self) if use_subdomains default_cdn_base end |
#custom_cname ⇒ String
Build the deterministic subdomain prefix for the configured public key.
54 55 56 |
# File 'lib/uploadcare/configuration.rb', line 54 def custom_cname Uploadcare::CnameGenerator.generate_cname(public_key: public_key) end |
#to_h ⇒ Hash
Convert this configuration to a serializable hash.
78 79 80 |
# File 'lib/uploadcare/configuration.rb', line 78 def to_h DEFAULTS.keys.to_h { |attribute| [attribute, public_send(attribute)] } end |
#with(**options) ⇒ Uploadcare::Configuration
Clone this configuration with overrides.
71 72 73 |
# File 'lib/uploadcare/configuration.rb', line 71 def with(**) self.class.new(**to_h, **) end |