prontoforms 0.2.0 → 0.3.0
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/.gitignore +2 -0
- data/CHANGELOG.md +21 -0
- data/lib/prontoforms.rb +13 -1
- data/lib/prontoforms/client.rb +51 -7
- data/lib/prontoforms/form_submission.rb +21 -1
- data/lib/prontoforms/user.rb +19 -0
- data/lib/prontoforms/version.rb +1 -1
- data/prontoforms.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad60a48189a843b3116774beae036174e1b606ff5b7be8e8ad65e08a5a94b7f
|
4
|
+
data.tar.gz: ca6fa882e2fa9f2bef9aa1753f1df168259d0aed49f316cd22bb7cb24f92aa37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e3abe87d14de60e671bdf88cd6eade2ce65ea1152826de892596ecc22ec4724c80679771978e87aed72125b2be3944edde0e21ab7680293dfd57c0a4678d1b7
|
7
|
+
data.tar.gz: 126bd9432699a6cd954c770f91c41c050aff180ef0368351cba122cabcb661ef864bb9d4dffb7b07fbc56c4b0128fd5787e9ecaba28cccfa8d83dca98f08c99d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# prontoforms changelog
|
2
|
+
|
3
|
+
|
4
|
+
## [Unreleased]
|
5
|
+
### Added
|
6
|
+
* Autogenerated documentation via YARD.
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
* Errors now provide a message describing the issue
|
10
|
+
* `ProntoForms::Client` now raises error on invalid resource definition.
|
11
|
+
|
12
|
+
## [0.2.0] - 26 Aug 2020
|
13
|
+
### Bugfixes
|
14
|
+
* Corrected pagination of resource lists
|
15
|
+
|
16
|
+
## [0.1.0] - 25 Aug 2020
|
17
|
+
* Initial release
|
18
|
+
|
19
|
+
[Unreleased]: https://github.com/paulholden2/prontoforms/compare/v0.2.0...HEAD
|
20
|
+
[0.1.0]: https://github.com/paulholden2/prontoforms/releases/tag/v0.1.0
|
21
|
+
[0.2.0]: https://github.com/paulholden2/prontoforms/releases/tag/v0.2.0
|
data/lib/prontoforms.rb
CHANGED
@@ -2,5 +2,17 @@ require 'prontoforms/version'
|
|
2
2
|
require 'prontoforms/client'
|
3
3
|
|
4
4
|
module ProntoForms
|
5
|
-
class Error < StandardError
|
5
|
+
class Error < StandardError
|
6
|
+
attr_reader :message
|
7
|
+
|
8
|
+
def initialize(message)
|
9
|
+
@message = message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class InvalidHttpVerb < Error
|
14
|
+
def initialize(verb)
|
15
|
+
super("Invalid HTTP verb: #{verb}")
|
16
|
+
end
|
17
|
+
end
|
6
18
|
end
|
data/lib/prontoforms/client.rb
CHANGED
@@ -3,21 +3,32 @@ require 'json'
|
|
3
3
|
require 'prontoforms/resource_list'
|
4
4
|
require 'prontoforms/form_space'
|
5
5
|
require 'prontoforms/form_submission'
|
6
|
+
require 'prontoforms/user'
|
6
7
|
|
7
8
|
module ProntoForms
|
8
9
|
class Client
|
9
|
-
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :api_key_id
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :api_key_secret
|
10
14
|
|
15
|
+
# @param api_key_id Your ProntoForms REST API key
|
16
|
+
# @param api_key_secret Your ProntoForms REST API secret
|
11
17
|
def initialize(api_key_id, api_key_secret)
|
12
18
|
@api_key_id = api_key_id
|
13
19
|
@api_key_secret = api_key_secret
|
14
20
|
end
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
# Defines a resource that can be retrieved in a list
|
23
|
+
# @return [nil]
|
24
|
+
# @api private
|
25
|
+
# @!macro [attach] resource_list
|
26
|
+
# @method $1
|
27
|
+
# Retrieve a list of $2 resources
|
28
|
+
# @return [ResourceList] A ResourceList containing $2 results
|
29
|
+
def self.resource_list(method, resource, url = resource.resource_name)
|
19
30
|
define_method(method) do |query: {}|
|
20
|
-
res = connection.
|
31
|
+
res = connection.get do |req|
|
21
32
|
req.url url
|
22
33
|
query.each { |k, v| req.params[k] = v }
|
23
34
|
end
|
@@ -32,9 +43,42 @@ module ProntoForms
|
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
35
|
-
|
36
|
-
|
46
|
+
resource_list :form_spaces, FormSpace
|
47
|
+
resource_list :form_submissions, FormSubmission
|
48
|
+
|
49
|
+
# Retrieve a user by identifier
|
50
|
+
# @param id [String] The user identifier
|
51
|
+
# @return [User] A User object for the requested user
|
52
|
+
def user(id)
|
53
|
+
return nil if id.nil?
|
54
|
+
res = connection.get do |req|
|
55
|
+
req.url "users/#{id.to_s}"
|
56
|
+
end
|
57
|
+
if res.success?
|
58
|
+
data = JSON.parse(res.body)
|
59
|
+
User.new(data, self)
|
60
|
+
else
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def form_submission(id)
|
66
|
+
return nil if id.nil?
|
67
|
+
res = connection.get do |req|
|
68
|
+
req.url "data/#{id.to_s}"
|
69
|
+
end
|
70
|
+
if res.success?
|
71
|
+
data = JSON.parse(res.body)
|
72
|
+
FormSubmission.new(data, self)
|
73
|
+
else
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
end
|
37
77
|
|
78
|
+
# Create a connection that can be used to execute a request against the
|
79
|
+
# ProntoForms API.
|
80
|
+
# @return [Faraday::Connection]
|
81
|
+
# @api private
|
38
82
|
def connection
|
39
83
|
Faraday.new(url: 'https://api.prontoforms.com/api/1.1') do |conn|
|
40
84
|
conn.basic_auth(api_key_id, api_key_secret)
|
@@ -18,6 +18,7 @@ module ProntoForms
|
|
18
18
|
property :data_persisted?, key: 'dataPersisted'
|
19
19
|
property :submitter_id, key: 'userId'
|
20
20
|
property :submitter_username, key: 'username'
|
21
|
+
property :dispatcher, key: 'dispatcher'
|
21
22
|
|
22
23
|
property :server_receive_date do
|
23
24
|
str = data.fetch('serverReceiveDate')
|
@@ -25,11 +26,30 @@ module ProntoForms
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def pages
|
29
|
+
document.fetch('pages')
|
30
|
+
end
|
31
|
+
|
32
|
+
def dispatcher
|
33
|
+
client.user(document.dig('dispatcher', 'identifier'))
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Returns additional data about the submission. Uses cached data,
|
39
|
+
# otherwise it loads and returns the data via #document!
|
40
|
+
def document
|
41
|
+
return @document if !@document.nil?
|
42
|
+
document!
|
43
|
+
end
|
44
|
+
|
45
|
+
# Force loads the submission document
|
46
|
+
def document!
|
28
47
|
res = client.connection.get do |req|
|
29
48
|
req.url "#{resource_name}/#{id}/document.json"
|
30
49
|
end
|
31
50
|
if res.success?
|
32
|
-
JSON.parse(res.body)
|
51
|
+
@document = JSON.parse(res.body)
|
52
|
+
@document
|
33
53
|
end
|
34
54
|
end
|
35
55
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'prontoforms/resource'
|
2
|
+
|
3
|
+
module ProntoForms
|
4
|
+
class User < Resource
|
5
|
+
def self.resource_name() 'users'; end
|
6
|
+
|
7
|
+
property :id, key: 'identifier'
|
8
|
+
property :username, key: 'username'
|
9
|
+
property :role, key: 'role'
|
10
|
+
property :email, key: 'email'
|
11
|
+
property :first_name, key: 'firstName'
|
12
|
+
property :last_name, key: 'lastName'
|
13
|
+
property :locale, key: 'locale'
|
14
|
+
|
15
|
+
def display_name
|
16
|
+
"#{first_name} #{last_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/prontoforms/version.rb
CHANGED
data/prontoforms.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prontoforms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Holden
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
69
83
|
description: A library for using the ProntoForms REST API in Ruby applications.
|
70
84
|
email:
|
71
85
|
- paul@holdensoftware.com
|
@@ -89,6 +103,7 @@ files:
|
|
89
103
|
- lib/prontoforms/form_submission.rb
|
90
104
|
- lib/prontoforms/resource.rb
|
91
105
|
- lib/prontoforms/resource_list.rb
|
106
|
+
- lib/prontoforms/user.rb
|
92
107
|
- lib/prontoforms/version.rb
|
93
108
|
- prontoforms.gemspec
|
94
109
|
homepage: https://github.com/paulholden2/prontoforms
|