Class: Picker

Inherits:
Object
  • Object
show all
Defined in:
lib/filestack_rails/filestack_js.rb

Direct Known Subclasses

OutdatedPicker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePicker

Returns a new instance of Picker.


4
5
6
# File 'lib/filestack_rails/filestack_js.rb', line 4

def initialize
  @url = filestack_js_url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url


2
3
4
# File 'lib/filestack_rails/filestack_js.rb', line 2

def url
  @url
end

Instance Method Details

#domainObject


16
17
18
# File 'lib/filestack_rails/filestack_js.rb', line 16

def domain
  ::Rails.application.config.filestack_rails.cname || 'filestackapi.com'
end

#filestack_js_urlObject


8
9
10
# File 'lib/filestack_rails/filestack_js.rb', line 8

def filestack_js_url
  "https://static.#{domain}/filestack-js/#{version}/filestack.min.js"
end

#picker(client_name, api_key, options, callback, other_callbacks = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'lib/filestack_rails/filestack_js.rb', line 20

def picker(client_name, api_key, options, callback, other_callbacks = nil)
  options_string = options[1..-2] # removed curly brackets help to generate pickerOptions in js

  <<~HTML
    (function(){
      #{client_name}.picker({ onUploadDone: data => #{callback}(data)#{other_callbacks}, #{options_string} }).open()
    })()
  HTML
end

#security(signature, policy) ⇒ Object


30
31
32
# File 'lib/filestack_rails/filestack_js.rb', line 30

def security(signature, policy)
  { security: { signature: signature, policy: policy } }.to_json
end

#versionObject


12
13
14
# File 'lib/filestack_rails/filestack_js.rb', line 12

def version
  ::Rails.application.config.filestack_rails.version
end