formio 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/formio/client.rb +19 -5
- data/lib/formio/form.rb +11 -8
- data/lib/formio/record.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e723660a1d929c17bcce26839fac021b49bab899eb1313e4e77c72ea6aa0df
|
4
|
+
data.tar.gz: ba45f9dad1f78441598eeacfdc4a85ef679d87c4507b8c51485c1cb0978ec620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f05f279f1ad25a23a1173b7a165b19f42c3deb60d2fc65fa1737e9b7c30c235960accb1a90d36b2d0c9b8516ae70cfd4b77c4a159324df91eddc4676f636cfc
|
7
|
+
data.tar.gz: 867a03cdc1fb9addadd66a40fd45e9597bb93c58c6c6cb6813ebf9cb0c1dd2b08877be2e3d802ef316bd2427d900aedc374d21133c795248abe7ddd2ae7af49c
|
data/lib/formio/client.rb
CHANGED
@@ -99,14 +99,14 @@ module Formio
|
|
99
99
|
response = parse_response(response.body)
|
100
100
|
if response.is_a?(Array)
|
101
101
|
return response.map do |f|
|
102
|
-
|
102
|
+
::Formio::Form.new f
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
::Formio::Form.new(response)
|
106
106
|
end
|
107
107
|
|
108
108
|
def create_form(formio_form)
|
109
|
-
raise "Must supply a formio form" unless formio_form.is_a?(
|
109
|
+
raise "Must supply a formio form" unless formio_form.is_a?(::Formio::Form)
|
110
110
|
response = connection.post do |req|
|
111
111
|
req.url "/form"
|
112
112
|
set_headers(req)
|
@@ -118,6 +118,18 @@ module Formio
|
|
118
118
|
true
|
119
119
|
end
|
120
120
|
|
121
|
+
def update_form(formio_form)
|
122
|
+
raise "Must supply a formio form" unless formio_form.is_a?(::Formio::Form)
|
123
|
+
response = connection.put do |req|
|
124
|
+
req.url "/form/#{formio_form.id}"
|
125
|
+
set_headers(req)
|
126
|
+
req.body = formio_form.to_json
|
127
|
+
end
|
128
|
+
if response.status >= 200 && response.status < 300
|
129
|
+
parse_response(response.body)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
121
133
|
def delete_form(form_name)
|
122
134
|
response = connection.delete do |req|
|
123
135
|
req.url "/#{form_name}"
|
@@ -146,8 +158,8 @@ module Formio
|
|
146
158
|
Zlib::GzipReader.new(stringio, encoding: 'ASCII-8BIT')
|
147
159
|
rescue Zlib::GzipFile::Error
|
148
160
|
puts "An issue occured with formio: #{response}"
|
149
|
-
rescue
|
150
|
-
puts "An issue occured with formio"
|
161
|
+
rescue e
|
162
|
+
puts "An issue occured with formio #{response}"
|
151
163
|
end
|
152
164
|
}
|
153
165
|
|
@@ -178,11 +190,13 @@ module Formio
|
|
178
190
|
req.url '/current'
|
179
191
|
set_headers(req)
|
180
192
|
end
|
193
|
+
return nil unless response.status >= 200 && response.status < 300
|
181
194
|
Record.new(parse_response(response.body))
|
182
195
|
end
|
183
196
|
|
184
197
|
def login
|
185
198
|
@auth_token ||= begin
|
199
|
+
return unless email
|
186
200
|
Rails.cache.fetch("formio_login_" + email, expires_in: 12.hours) do
|
187
201
|
formio_conn = Faraday::Connection.new("https://formio.form.io", ssl: { verify: true })
|
188
202
|
|
data/lib/formio/form.rb
CHANGED
@@ -8,6 +8,7 @@ module Formio
|
|
8
8
|
:name,
|
9
9
|
:title,
|
10
10
|
:path,
|
11
|
+
:submission_access,
|
11
12
|
:created_at,
|
12
13
|
:updated_at
|
13
14
|
)
|
@@ -21,6 +22,7 @@ module Formio
|
|
21
22
|
@path = formio_hash['path']
|
22
23
|
@created_at = DateTime.parse formio_hash['created']
|
23
24
|
@updated_at = DateTime.parse formio_hash['modified']
|
25
|
+
@submission_access = formio_hash['submissionAccess']
|
24
26
|
end
|
25
27
|
|
26
28
|
def name=(name)
|
@@ -31,15 +33,16 @@ module Formio
|
|
31
33
|
@name = @title = title
|
32
34
|
end
|
33
35
|
|
36
|
+
def id
|
37
|
+
formio_hash['_id']
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_h
|
41
|
+
formio_hash
|
42
|
+
end
|
43
|
+
|
34
44
|
def to_json
|
35
|
-
|
36
|
-
title: title,
|
37
|
-
display: 'form',
|
38
|
-
type: type,
|
39
|
-
name: name,
|
40
|
-
path: path,
|
41
|
-
components: components,
|
42
|
-
}.to_json
|
45
|
+
to_h.to_json
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
data/lib/formio/record.rb
CHANGED