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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 381a07d7ab5966796ebd564c3dc997dbc0e0c1d109fcacd24d35d9e693e88f52
4
- data.tar.gz: b371922c91953de976f9a2547e438caa154d522c5c61c4d7023baedf6766a753
3
+ metadata.gz: 02e723660a1d929c17bcce26839fac021b49bab899eb1313e4e77c72ea6aa0df
4
+ data.tar.gz: ba45f9dad1f78441598eeacfdc4a85ef679d87c4507b8c51485c1cb0978ec620
5
5
  SHA512:
6
- metadata.gz: 77b94aa40862154e11b62198282041f11e40aeeeb2951ade5800deebf6b7c434aa7b9ce161dbe6d2e864188420bbbe44a46ce1bf2cf25837ccd78c7466832474
7
- data.tar.gz: d29b5954e9520659406a56b2475e8fadf78af0e40bce8d8911ee66eb161956d8205c6e2ab13925ed27b4bfdae73f69b0e8068fe8ef0f65088337c8d2d2791fcc
6
+ metadata.gz: 9f05f279f1ad25a23a1173b7a165b19f42c3deb60d2fc65fa1737e9b7c30c235960accb1a90d36b2d0c9b8516ae70cfd4b77c4a159324df91eddc4676f636cfc
7
+ data.tar.gz: 867a03cdc1fb9addadd66a40fd45e9597bb93c58c6c6cb6813ebf9cb0c1dd2b08877be2e3d802ef316bd2427d900aedc374d21133c795248abe7ddd2ae7af49c
@@ -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
- FormioForm.new f
102
+ ::Formio::Form.new f
103
103
  end
104
104
  end
105
- FormioForm.new(response)
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?(FormioForm)
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
 
@@ -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
@@ -24,6 +24,14 @@ module Formio
24
24
  formio_hash
25
25
  end
26
26
 
27
+ def [](key)
28
+ formio_hash[key]
29
+ end
30
+
31
+ def []=(key, value)
32
+ formio_hash[key] = value
33
+ end
34
+
27
35
  attr_reader(
28
36
  :id,
29
37
  :_id,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Frias