Class: Uploadcare::Rails::Settings

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/uploadcare/rails/settings.rb

Constant Summary collapse

@@widget_keys =
{
  # Excluded
  :api_url_base => false,
  :api_version => false,
  :private_key => false,
  :widget_version => false,
   # Renamed
  :static_url_base => :cdn_base,
  :upload_url_base => :url_base
}
@@client_keys =
[
  :public_key, :private_key, :upload_url_base,
  :api_url_base, :static_url_base, :api_version,
  :widget_version
]

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}, *args) ⇒ Settings

Returns a new instance of Settings.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/uploadcare/rails/settings.rb', line 4

def initialize(settings = {}, *args)
  super(*args)
  settings = {
    :public_key => 'demopublickey',
    :private_key => 'demoprivatekey',
    :widget_version => '0.8'
  }.update(settings)
  settings.each do |k, v|
    send "#{k}=", v
  end
end

Instance Method Details

#apiObject



52
53
54
# File 'lib/uploadcare/rails/settings.rb', line 52

def api
  @api ||= configure_api
end

#configure_apiObject



62
63
64
# File 'lib/uploadcare/rails/settings.rb', line 62

def configure_api
  @api = Uploadcare::Api.new(get_client_settings)
end

#configure_uploaderObject



66
67
68
# File 'lib/uploadcare/rails/settings.rb', line 66

def configure_uploader
  @uploader = Uploadcare::Uploader.new(get_client_settings)
end

#get_client_settingsObject



46
47
48
# File 'lib/uploadcare/rails/settings.rb', line 46

def get_client_settings
  get_settings(@@client_keys)
end

#get_settings(keys) ⇒ Object



42
43
44
# File 'lib/uploadcare/rails/settings.rb', line 42

def get_settings(keys)
  marshal_dump.select{|k| keys.include? k}
end

#get_widget_settingsObject



28
29
30
31
32
33
34
# File 'lib/uploadcare/rails/settings.rb', line 28

def get_widget_settings
  Hash[
    marshal_dump
      .reject{|k| @@widget_keys[k] == false }
      .keys.map{|k| [@@widget_keys[k] || k, send(k)]}
  ]
end

#uploaderObject



56
57
58
# File 'lib/uploadcare/rails/settings.rb', line 56

def uploader
  @uploader ||= configure_uploader
end