filestack-rails 4.0.7 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/app/helpers/filestack_rails/application_helper.rb +10 -32
- data/lib/filestack-rails.rb +1 -0
- data/lib/filestack_rails/configuration.rb +5 -1
- data/lib/filestack_rails/filestack_js.rb +73 -0
- data/lib/filestack_rails/version.rb +1 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4585b209ea7e22c920cf51484b9202c920f893e6
|
4
|
+
data.tar.gz: 5107599301ef1abc00035cfd47a6500eb431f761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc03c00d69dd1d5ac3a59978081f4fa8b5d0b44767300bfb5638f1dde9aa5267549d3231efe2c8db3793c8be59ec9a6722c4f7bd56244a708e248b2beb36f8a
|
7
|
+
data.tar.gz: d2495c2c7c2779a5b361dbe0f93980a4db048dd864707a6a62304d1b357a22a50927a774ef29c5c0302f777dca85e65d02378793ffe55d82be83ea9c11250c85
|
data/README.md
CHANGED
@@ -64,6 +64,21 @@ config.filestack_rails.version = 'v2'
|
|
64
64
|
# filestack-js (1.x.x)
|
65
65
|
config.filestack_rails.version = 'v3'
|
66
66
|
```
|
67
|
+
|
68
|
+
For Filestack Rails SDK v.5.0.0+, you have to provide picker version precisely. By default the picker version is setup to `3.x.x`. If you want to use older filestack-js version (0.11.5), you have to configure `version` to `0.11.5` in `config/application.rb`:
|
69
|
+
```ruby
|
70
|
+
# filestack-js (0.11.5)
|
71
|
+
config.filestack_rails.version = '0.11.5'
|
72
|
+
|
73
|
+
# filestack-js (1.x.x)
|
74
|
+
config.filestack_rails.version = '1.x.x'
|
75
|
+
|
76
|
+
# filestack-js (3.x.x)
|
77
|
+
config.filestack_rails.version = '3.x.x'
|
78
|
+
```
|
79
|
+
|
80
|
+
You can find all available filestack-js versions in [`lib/filestack_rails/version.rb`](./lib/filestack_rails/version.rb)
|
81
|
+
|
67
82
|
### CNAME
|
68
83
|
|
69
84
|
If you have set up a custom CNAME, you can add it to your configuration file. The Picker will modify all assets to formatted with your domain origin instead of Filestack's.
|
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'json'
|
2
2
|
include FilestackRails::Transform
|
3
|
-
include FilestackRails::
|
3
|
+
include FilestackRails::FilestackJs
|
4
4
|
|
5
5
|
module FilestackRails
|
6
6
|
module ApplicationHelper
|
7
7
|
def filestack_js_include_tag
|
8
|
-
|
9
|
-
v3 = -> { javascript_include_tag('https://static.filestackapi.com/filestack-js/1.x.x/filestack.min.js', type: 'text/javascript') }
|
10
|
-
|
11
|
-
get_filestack_js_result(v2: v2, v3: v3)
|
8
|
+
javascript_include_tag(get_filestack_js.url, type: 'text/javascript')
|
12
9
|
end
|
13
10
|
|
14
11
|
def filestack_js_init_tag
|
@@ -49,31 +46,15 @@ module FilestackRails
|
|
49
46
|
end
|
50
47
|
|
51
48
|
def create_javascript_for_picker(callback, options)
|
52
|
-
client_name,
|
49
|
+
client_name, api_key = get_client_and_api_key
|
53
50
|
other_callbacks = build_callbacks_js(options) if options
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
v2 = -> do
|
60
|
-
<<~HTML
|
61
|
-
(function(){
|
62
|
-
#{client_name}.pick(#{json_string}).then(function(data){#{callback}(data)})
|
63
|
-
})()
|
64
|
-
HTML
|
65
|
-
end
|
51
|
+
options = if options.nil?
|
52
|
+
''
|
53
|
+
else
|
54
|
+
options.to_json
|
55
|
+
end
|
66
56
|
|
67
|
-
|
68
|
-
json_string = json_string[1..-2] # removed curly brackets help to generate pickerOptions in js
|
69
|
-
|
70
|
-
<<~HTML
|
71
|
-
(function(){
|
72
|
-
#{client_name}.picker({ onUploadDone: data => #{callback}(data)#{other_callbacks}, #{json_string} }).open()
|
73
|
-
})()
|
74
|
-
HTML
|
75
|
-
end
|
76
|
-
get_filestack_js_result(v2: v2, v3: v3)
|
57
|
+
get_filestack_js.picker(client_name, api_key, options, callback, other_callbacks)
|
77
58
|
end
|
78
59
|
|
79
60
|
def build_callbacks_js(options)
|
@@ -104,10 +85,7 @@ module FilestackRails
|
|
104
85
|
signature, policy = get_policy_and_signature
|
105
86
|
|
106
87
|
if policy && signature
|
107
|
-
|
108
|
-
v2 = -> { signature_and_policy.to_json }
|
109
|
-
v3 = -> { { security: signature_and_policy }.to_json }
|
110
|
-
get_filestack_js_result(v2: v2, v3: v3)
|
88
|
+
get_filestack_js.security(signature, policy)
|
111
89
|
else
|
112
90
|
"''"
|
113
91
|
end
|
data/lib/filestack-rails.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
1
3
|
module FilestackRails
|
2
4
|
class Configuration
|
3
5
|
attr_accessor :api_key, :client_name, :secret_key, :security, :expiry, :app_secret, :cname, :version
|
4
6
|
|
7
|
+
OUTDATED_VERSION = '0.11.5'
|
8
|
+
|
5
9
|
def api_key
|
6
10
|
@api_key or raise "Set config.filestack_rails.api_key"
|
7
11
|
end
|
@@ -11,7 +15,7 @@ module FilestackRails
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def version
|
14
|
-
@version or '
|
18
|
+
@version or '3.x.x'
|
15
19
|
end
|
16
20
|
|
17
21
|
def expiry
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class Picker
|
4
|
+
attr_reader :url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
raise 'Incorrect config.filestack_rails.version' unless url_exists?(filestack_js_url)
|
8
|
+
@url = filestack_js_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def version
|
12
|
+
::Rails.application.config.filestack_rails.version
|
13
|
+
end
|
14
|
+
|
15
|
+
def security(signature, policy)
|
16
|
+
{ security: { signature: signature, policy: policy } }.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def filestack_js_url
|
20
|
+
"https://static.filestackapi.com/filestack-js/#{version}/filestack.min.js"
|
21
|
+
end
|
22
|
+
|
23
|
+
def picker(client_name, api_key, options, callback, other_callbacks = nil)
|
24
|
+
options_string = options[1..-2] # removed curly brackets help to generate pickerOptions in js
|
25
|
+
|
26
|
+
<<~HTML
|
27
|
+
(function(){
|
28
|
+
#{client_name}.picker({ onUploadDone: data => #{callback}(data)#{other_callbacks}, #{options_string} }).open()
|
29
|
+
})()
|
30
|
+
HTML
|
31
|
+
end
|
32
|
+
|
33
|
+
def url_exists?(url)
|
34
|
+
uri = URI(url)
|
35
|
+
request = Net::HTTP.new(uri.host)
|
36
|
+
response = request.request_head(uri.path)
|
37
|
+
response.code.to_i == 200
|
38
|
+
rescue
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class OutdatedPicker < Picker
|
44
|
+
def filestack_js_url
|
45
|
+
'https://static.filestackapi.com/v3/filestack.js'
|
46
|
+
end
|
47
|
+
|
48
|
+
def picker(client_name, api_key, options, callback, other_callbacks = nil)
|
49
|
+
<<~HTML
|
50
|
+
(function(){
|
51
|
+
#{client_name}.pick(#{options}).then(function(data){#{callback}(data)})
|
52
|
+
})()
|
53
|
+
HTML
|
54
|
+
end
|
55
|
+
|
56
|
+
def security(signature, policy)
|
57
|
+
{ signature: signature, policy: policy }.to_json
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module FilestackRails
|
62
|
+
module FilestackJs
|
63
|
+
OUTDATED_VERSION = '0.11.5'
|
64
|
+
|
65
|
+
def get_filestack_js
|
66
|
+
if ::Rails.application.config.filestack_rails.version == OUTDATED_VERSION
|
67
|
+
OutdatedPicker.new
|
68
|
+
else
|
69
|
+
Picker.new
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,24 +1,3 @@
|
|
1
|
-
class FilestackVersion
|
2
|
-
def initialize(results)
|
3
|
-
@version = ::Rails.application.config.filestack_rails.version
|
4
|
-
@results = results
|
5
|
-
end
|
6
|
-
|
7
|
-
def determine_filestack_js_result
|
8
|
-
begin
|
9
|
-
@results[@version.to_sym].call
|
10
|
-
rescue
|
11
|
-
raise 'Set correct version in config.filestack_rails.version'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
1
|
module FilestackRails
|
17
|
-
VERSION = '
|
18
|
-
|
19
|
-
module Version
|
20
|
-
def get_filestack_js_result(results)
|
21
|
-
FilestackVersion.new(results).determine_filestack_js_result
|
22
|
-
end
|
23
|
-
end
|
2
|
+
VERSION = '5.0.0'
|
24
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filestack-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- filestack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/filestack-rails.rb
|
110
110
|
- lib/filestack_rails/configuration.rb
|
111
111
|
- lib/filestack_rails/engine.rb
|
112
|
+
- lib/filestack_rails/filestack_js.rb
|
112
113
|
- lib/filestack_rails/transform.rb
|
113
114
|
- lib/filestack_rails/version.rb
|
114
115
|
- lib/tasks/filestack_rails_tasks.rake
|