prontoforms 0.3.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/checks.yml +66 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +11 -2
- data/Gemfile +6 -0
- data/README.md +17 -1
- data/Rakefile +5 -3
- data/bin/console +4 -10
- data/bin/setup +2 -2
- data/lib/prontoforms.rb +3 -0
- data/lib/prontoforms/client.rb +39 -24
- data/lib/prontoforms/document.rb +31 -0
- data/lib/prontoforms/form.rb +22 -0
- data/lib/prontoforms/form_space.rb +34 -0
- data/lib/prontoforms/form_submission.rb +75 -11
- data/lib/prontoforms/resource.rb +17 -6
- data/lib/prontoforms/resource_list.rb +21 -4
- data/lib/prontoforms/user.rb +6 -1
- data/lib/prontoforms/version.rb +3 -1
- data/prontoforms.gemspec +27 -15
- metadata +69 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d15ef56d13e8ea0e980e73be80c8a766b9d82ab5947899aea364e5e5f8562bd0
|
4
|
+
data.tar.gz: 75e60d77da7d5bfabf8494029a5e80f24f8548fb1f8781847e4adf2e4b43b797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b3883d2eb0c2a740546ac2d9deb955dc90e68c66dec3409b3fa05ba025111b4fd8340c84b40861071a7a47851250df95062edcd08f43f3b24fb9b14954f1a90
|
7
|
+
data.tar.gz: 0d483ea0b5b6cb8bf112a3c6097c6ff2af4180a8c5b6c859afc7b724a57e5a0999b14c49aecc03d887f3bf09d5de85668254f52ab9a87bb9131bceb83515c713
|
@@ -0,0 +1,66 @@
|
|
1
|
+
name: Checks
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
name: Run automated tests
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- name: Checkout repository
|
13
|
+
uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: Set up ruby
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6
|
19
|
+
|
20
|
+
- name: Install dependencies
|
21
|
+
run: |
|
22
|
+
gem install bundler -v 2.1.4
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
- name: Test
|
26
|
+
run: bundle exec rake
|
27
|
+
|
28
|
+
- name: Report test coverage
|
29
|
+
uses: paambaati/codeclimate-action@v2.7.4
|
30
|
+
env:
|
31
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
32
|
+
|
33
|
+
rubocop:
|
34
|
+
name: Rubocop
|
35
|
+
runs-on: ubuntu-latest
|
36
|
+
strategy:
|
37
|
+
fail-fast: false
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
- name: Set up Ruby
|
44
|
+
uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: 2.6
|
47
|
+
|
48
|
+
- name: Install Code Scanning integration
|
49
|
+
run: bundle add code-scanning-rubocop --version 0.3.0 --skip-install
|
50
|
+
|
51
|
+
- name: Install dependencies
|
52
|
+
run: |
|
53
|
+
gem install bundler -v 2.1.4
|
54
|
+
bundle install
|
55
|
+
|
56
|
+
- name: Rubocop run
|
57
|
+
run: |
|
58
|
+
bash -c "
|
59
|
+
bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
|
60
|
+
[[ $? -ne 2 ]]
|
61
|
+
"
|
62
|
+
|
63
|
+
- name: Upload Sarif output
|
64
|
+
uses: github/codeql-action/upload-sarif@v1
|
65
|
+
with:
|
66
|
+
sarif_file: rubocop.sarif
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
---
|
2
|
+
os: linux
|
3
|
+
dist: xenial
|
2
4
|
language: ruby
|
3
5
|
cache: bundler
|
4
6
|
rvm:
|
5
7
|
- 2.6.0
|
6
8
|
before_install: gem install bundler -v 2.1.4
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
13
|
+
script:
|
14
|
+
- bundle exec rspec
|
15
|
+
after_script:
|
16
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# prontoforms changelog
|
2
2
|
|
3
|
+
## [Unreleased]
|
4
|
+
### Added
|
5
|
+
* Added Form resource
|
6
|
+
* Can retrieve forms by form space
|
7
|
+
|
8
|
+
## [v0.3.1] - 15 Sep 2020
|
9
|
+
### Removed
|
10
|
+
* Unused `InvalidHttpVerb` error class
|
3
11
|
|
4
|
-
## [v0.3.0]
|
12
|
+
## [v0.3.0] - 15 Sep 2020
|
5
13
|
### Added
|
6
14
|
* Autogenerated documentation via YARD.
|
7
15
|
|
@@ -16,7 +24,8 @@
|
|
16
24
|
## [v0.1.0] - 25 Aug 2020
|
17
25
|
* Initial release
|
18
26
|
|
19
|
-
[Unreleased]: https://github.com/paulholden2/prontoforms/compare/v0.3.
|
27
|
+
[Unreleased]: https://github.com/paulholden2/prontoforms/compare/v0.3.1...HEAD
|
20
28
|
[v0.1.0]: https://github.com/paulholden2/prontoforms/releases/tag/v0.1.0
|
21
29
|
[v0.2.0]: https://github.com/paulholden2/prontoforms/releases/tag/v0.2.0
|
22
30
|
[v0.3.0]: https://github.com/paulholden2/prontoforms/releases/tag/v0.3.0
|
31
|
+
[v0.3.1]: https://github.com/paulholden2/prontoforms/releases/tag/v0.3.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# ProntoForms
|
2
2
|
|
3
|
+
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fpaulholden2%2Fprontoforms%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/paulholden2/prontoforms/goto?ref=master) [![Gem Version](https://badge.fury.io/rb/prontoforms.svg)](https://badge.fury.io/rb/prontoforms) [![Inline docs](http://inch-ci.org/github/paulholden2/prontoforms.svg?branch=master)](http://inch-ci.org/github/paulholden2/prontoforms) [![Maintainability](https://api.codeclimate.com/v1/badges/e47cd40058313e1c1c38/maintainability)](https://codeclimate.com/github/paulholden2/prontoforms/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e47cd40058313e1c1c38/test_coverage)](https://codeclimate.com/github/paulholden2/prontoforms/test_coverage)
|
4
|
+
|
3
5
|
A library for interacting with the ProntoForms REST API in Ruby applications.
|
4
6
|
|
7
|
+
Note: version 0.4.0 included a breaking change, and has been yanked from
|
8
|
+
RubyGems. If you are using it, please upgrade to 1.x or revert to 0.3.1.
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -20,7 +25,16 @@ Or install it yourself as:
|
|
20
25
|
|
21
26
|
## Usage
|
22
27
|
|
23
|
-
|
28
|
+
To get started, first [create a ProntoForms API key] in your ProntoForms
|
29
|
+
account. Then you can begin using the API client in your Ruby application:
|
30
|
+
|
31
|
+
```rb
|
32
|
+
client = ProntoForms::Client.new(api_key_id, api_key_secret)
|
33
|
+
client.form_spaces # Returns all FormSpaces in your account
|
34
|
+
```
|
35
|
+
|
36
|
+
Review [the documentation](https://rubydoc.info/github/paulholden2/prontoforms)
|
37
|
+
for more information on how to use this library to interact with ProntoForms.
|
24
38
|
|
25
39
|
## Development
|
26
40
|
|
@@ -37,3 +51,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/paulho
|
|
37
51
|
## License
|
38
52
|
|
39
53
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
[create a ProntoForms API key]: https://support.prontoforms.com/hc/en-us/articles/217496468-Setup-an-API-Application-on-ProntoForms#Create
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'prontoforms'
|
6
|
+
require 'irb'
|
5
7
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
8
|
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
data/lib/prontoforms.rb
CHANGED
data/lib/prontoforms/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'json'
|
3
5
|
require 'prontoforms/resource_list'
|
@@ -6,12 +8,15 @@ require 'prontoforms/form_submission'
|
|
6
8
|
require 'prontoforms/user'
|
7
9
|
|
8
10
|
module ProntoForms
|
11
|
+
# Allows you to retrieve resources from ProntoForms and perform other
|
12
|
+
# functions with the API.
|
9
13
|
class Client
|
10
|
-
# @return [String]
|
14
|
+
# @return [String] ProntoForms API key ID
|
11
15
|
attr_reader :api_key_id
|
12
|
-
# @return [String]
|
16
|
+
# @return [String] ProntoForms API key secret
|
13
17
|
attr_reader :api_key_secret
|
14
18
|
|
19
|
+
# Create a client and use provided API credentials
|
15
20
|
# @param api_key_id Your ProntoForms REST API key
|
16
21
|
# @param api_key_secret Your ProntoForms REST API secret
|
17
22
|
def initialize(api_key_id, api_key_secret)
|
@@ -32,14 +37,13 @@ module ProntoForms
|
|
32
37
|
req.url url
|
33
38
|
query.each { |k, v| req.params[k] = v }
|
34
39
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
40
|
+
|
41
|
+
data = JSON.parse(res.body)
|
42
|
+
|
43
|
+
return nil if data.fetch('pageData').size.zero?
|
44
|
+
|
45
|
+
ResourceList.new(data, { 'p' => 0, 's' => 100 }.merge(query), method,
|
46
|
+
resource, self)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -50,29 +54,39 @@ module ProntoForms
|
|
50
54
|
# @param id [String] The user identifier
|
51
55
|
# @return [User] A User object for the requested user
|
52
56
|
def user(id)
|
53
|
-
|
57
|
+
raise ArgumentError, 'id must be provided' if id.nil?
|
58
|
+
|
54
59
|
res = connection.get do |req|
|
55
|
-
req.url "users/#{id
|
60
|
+
req.url "users/#{id}"
|
56
61
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
|
63
|
+
User.new(JSON.parse(res.body), self)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Retrieve a form space by its identifier
|
67
|
+
# @param id [String] The form space identifier
|
68
|
+
# @return [FormSpace] A FormSpace object
|
69
|
+
def form_space(id)
|
70
|
+
raise ArgumentError, 'id must be provided' if id.nil?
|
71
|
+
|
72
|
+
res = connection.get do |req|
|
73
|
+
req.url "formspaces/#{id}"
|
62
74
|
end
|
75
|
+
|
76
|
+
FormSpace.new(JSON.parse(res.body), self)
|
63
77
|
end
|
64
78
|
|
79
|
+
# Retrieve a form submission by identifier
|
80
|
+
# @param id [String] The form submission identifier
|
81
|
+
# @return [FormSubmission] A FormSubmission object
|
65
82
|
def form_submission(id)
|
66
83
|
return nil if id.nil?
|
84
|
+
|
67
85
|
res = connection.get do |req|
|
68
|
-
req.url "data/#{id
|
69
|
-
end
|
70
|
-
if res.success?
|
71
|
-
data = JSON.parse(res.body)
|
72
|
-
FormSubmission.new(data, self)
|
73
|
-
else
|
74
|
-
nil
|
86
|
+
req.url "data/#{id}"
|
75
87
|
end
|
88
|
+
|
89
|
+
FormSubmission.new(JSON.parse(res.body), self)
|
76
90
|
end
|
77
91
|
|
78
92
|
# Create a connection that can be used to execute a request against the
|
@@ -82,6 +96,7 @@ module ProntoForms
|
|
82
96
|
def connection
|
83
97
|
Faraday.new(url: 'https://api.prontoforms.com/api/1.1') do |conn|
|
84
98
|
conn.basic_auth(api_key_id, api_key_secret)
|
99
|
+
conn.use Faraday::Response::RaiseError
|
85
100
|
end
|
86
101
|
end
|
87
102
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'prontoforms/resource'
|
4
|
+
|
5
|
+
module ProntoForms
|
6
|
+
# A Document is a configuration that generates output data or files when
|
7
|
+
# attached to a form.
|
8
|
+
class Document < Resource
|
9
|
+
def self.resource_name
|
10
|
+
'documents'
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String] The Document identifier
|
14
|
+
property :id, key: 'identifier'
|
15
|
+
# @return [String] Document type
|
16
|
+
property :type, key: 'type'
|
17
|
+
# @return [String] Document name
|
18
|
+
property :name, key: 'name'
|
19
|
+
# @return [String] Document descriptiojn
|
20
|
+
property :description, key: 'description'
|
21
|
+
# @return [String] Document form version
|
22
|
+
property :form_document_version, key: 'formDocumentVersion'
|
23
|
+
# @return [Boolean] Whether the document is standard (system generated)
|
24
|
+
property :standard, key: 'standard'
|
25
|
+
# @return [String] Whether the document auto-links to new forms
|
26
|
+
property :auto_link, key: 'autoLink'
|
27
|
+
|
28
|
+
alias standard? standard
|
29
|
+
alias auto_link? auto_link
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'prontoforms/resource'
|
4
|
+
|
5
|
+
module ProntoForms
|
6
|
+
# A form includes inputs, validations, logic, and other configuration that
|
7
|
+
# facilitates data capture for a specific purpose.
|
8
|
+
class Form < Resource
|
9
|
+
def self.resource_name
|
10
|
+
'forms'
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String] The Form identifier
|
14
|
+
property :id, key: 'identifier'
|
15
|
+
# @return [String] Form name
|
16
|
+
property :name, key: 'name'
|
17
|
+
# @return [String] Form description
|
18
|
+
property :description, key: 'description'
|
19
|
+
# @return [String] Form state
|
20
|
+
property :state, key: 'state'
|
21
|
+
end
|
22
|
+
end
|
@@ -1,6 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'prontoforms/resource'
|
4
|
+
require 'prontoforms/form'
|
5
|
+
require 'prontoforms/document'
|
2
6
|
|
3
7
|
module ProntoForms
|
8
|
+
# Represents a form space resource in ProntoForms. Form spaces are the
|
9
|
+
# primary organizational unit for forms, data sources, destinations, and
|
10
|
+
# other resources.
|
4
11
|
class FormSpace < Resource
|
5
12
|
# @return [String] The FormSpace identifier
|
6
13
|
property :id, key: 'identifier'
|
@@ -10,5 +17,32 @@ module ProntoForms
|
|
10
17
|
property :problem_contact_email, key: 'problemContactEmail'
|
11
18
|
# @return [Boolean] Whether updates are automatically pushed to devices
|
12
19
|
property :push_updates_to_device, key: 'pushUpdatesToDevice'
|
20
|
+
|
21
|
+
# Get all documents in the form space
|
22
|
+
# @return [ResourceList] A ResourceList containing Document objects
|
23
|
+
def documents
|
24
|
+
res = client.connection.get do |req|
|
25
|
+
req.url "formspaces/#{id}/documents"
|
26
|
+
end
|
27
|
+
|
28
|
+
ResourceList.new(JSON.parse(res.body), {
|
29
|
+
'p' => 0,
|
30
|
+
's' => 100
|
31
|
+
}, :documents, Document, self)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get all forms in the form space
|
35
|
+
# @return [ResourceList] A ResourceList containing Form objects
|
36
|
+
def forms(query: {})
|
37
|
+
res = client.connection.get do |req|
|
38
|
+
req.url "formspaces/#{id}/forms"
|
39
|
+
query.each { |k, v| req.params[k] = v }
|
40
|
+
end
|
41
|
+
|
42
|
+
ResourceList.new(JSON.parse(res.body), {
|
43
|
+
'p' => 0,
|
44
|
+
's' => 100
|
45
|
+
}.merge(query), :forms, Form, self)
|
46
|
+
end
|
13
47
|
end
|
14
48
|
end
|
@@ -1,25 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'prontoforms/resource'
|
3
5
|
|
4
6
|
module ProntoForms
|
7
|
+
# A FormSubmission represents submitted form data in ProntoForms. It
|
8
|
+
# includes various metadata about the submission as well.
|
5
9
|
class FormSubmission < Resource
|
6
|
-
def self.resource_name
|
10
|
+
def self.resource_name
|
11
|
+
'data'
|
12
|
+
end
|
7
13
|
|
14
|
+
# @return [String] The FormSubmission identifier
|
8
15
|
property :id, key: 'identifier'
|
16
|
+
# @return [String] Submission reference number
|
9
17
|
property :reference_number, key: 'referenceNumber'
|
18
|
+
# @return [String] Submission state. One of: Complete, Processing,
|
19
|
+
# Dispatched
|
10
20
|
property :state, key: 'state'
|
21
|
+
# @return [String] Submission data state
|
11
22
|
property :data_state, key: 'dataState'
|
23
|
+
# @return [Boolean] Has the submission data been persisted on the server
|
12
24
|
property :data_persisted, key: 'dataPersisted'
|
25
|
+
# @return [String] The form's version identifier
|
13
26
|
property :form_version_id, key: 'formVersionId'
|
27
|
+
# @return [String] The form's identifier
|
14
28
|
property :form_id, key: 'formId'
|
29
|
+
# @return [String] Submitter's user identifier
|
15
30
|
property :user_id, key: 'userId'
|
31
|
+
# @return [String] Submitter's username
|
16
32
|
property :username, key: 'username'
|
17
|
-
# Aliases
|
18
|
-
property :data_persisted?, key: 'dataPersisted'
|
19
|
-
property :submitter_id, key: 'userId'
|
20
|
-
property :submitter_username, key: 'username'
|
21
|
-
property :dispatcher, key: 'dispatcher'
|
22
33
|
|
34
|
+
alias data_persisted? data_persisted
|
35
|
+
alias submitter_id user_id
|
36
|
+
alias submitter_username username
|
37
|
+
|
38
|
+
# @return [DateTime] Timestamp the submission was received by the server
|
23
39
|
property :server_receive_date do
|
24
40
|
str = data.fetch('serverReceiveDate')
|
25
41
|
str.nil? ? nil : DateTime.strptime(str)
|
@@ -34,15 +50,64 @@ module ProntoForms
|
|
34
50
|
# Retrieve the dispatching User, if the form was dispatched
|
35
51
|
# @return [User] The user that dispatched the form, or nil
|
36
52
|
def dispatcher
|
53
|
+
return nil unless dispatched?
|
54
|
+
|
37
55
|
client.user(document.dig('dispatcher', 'identifier'))
|
38
56
|
end
|
39
57
|
|
58
|
+
# Check if the form was dispatched
|
59
|
+
# @return [Boolean] True if the form was dispatched; false otherwise
|
60
|
+
def dispatched?
|
61
|
+
!document.dig('dispatcher', 'identifier').nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
# Retrieve the form space for the form submission
|
65
|
+
# @return [FormSpace] Form space for the submission's form
|
66
|
+
def form_space
|
67
|
+
client.form_space(data.dig('form', 'formSpaceId'))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Retrieve the form for the form submission
|
71
|
+
# @return [Form] Form for the submission
|
72
|
+
def form
|
73
|
+
client.form(data.dig('form', 'formId'))
|
74
|
+
end
|
75
|
+
|
76
|
+
# Retrieve the standard PDF document for the form submission
|
77
|
+
# @return [IO] Readable stream containing the PDF contents
|
78
|
+
def pdf
|
79
|
+
io = StringIO.new
|
80
|
+
client.connection.get do |req|
|
81
|
+
req.url "#{resource_name}/#{id}/documents/#{pdf_document.id}"
|
82
|
+
req.options.on_data = proc do |chunk|
|
83
|
+
io << chunk
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
io.rewind
|
88
|
+
io
|
89
|
+
end
|
90
|
+
|
40
91
|
private
|
41
92
|
|
93
|
+
# Retrieve the standard PDF document for the form submission
|
94
|
+
# @return [Document] PDF document for the form submission
|
95
|
+
# @raises RuntimeError
|
96
|
+
def pdf_document
|
97
|
+
document = form_space.documents.items.find do |doc|
|
98
|
+
doc.type == 'Pdf' && doc.standard?
|
99
|
+
end
|
100
|
+
|
101
|
+
raise "No PDF document found for form space #{fs.id}" if document.nil?
|
102
|
+
|
103
|
+
document
|
104
|
+
end
|
105
|
+
|
42
106
|
# Returns additional data about the submission. Uses cached data,
|
43
107
|
# otherwise it loads and returns the data via #document!
|
44
108
|
def document
|
45
|
-
return @document
|
109
|
+
return @document unless @document.nil?
|
110
|
+
|
46
111
|
document!
|
47
112
|
end
|
48
113
|
|
@@ -51,10 +116,9 @@ module ProntoForms
|
|
51
116
|
res = client.connection.get do |req|
|
52
117
|
req.url "#{resource_name}/#{id}/document.json"
|
53
118
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
119
|
+
|
120
|
+
@document = JSON.parse(res.body)
|
121
|
+
@document
|
58
122
|
end
|
59
123
|
end
|
60
124
|
end
|
data/lib/prontoforms/resource.rb
CHANGED
@@ -1,19 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
|
3
5
|
module ProntoForms
|
6
|
+
# Base class for resource-related classes.
|
4
7
|
class Resource
|
5
|
-
|
8
|
+
# @return [Hash] Retrieve raw JSON data associated with this resource
|
9
|
+
attr_reader :data
|
10
|
+
# @return [Client] API client
|
11
|
+
attr_reader :client
|
12
|
+
# @return [Resource] Parent object (applicable to child resources)
|
13
|
+
attr_reader :parent
|
6
14
|
|
15
|
+
# Defines a property of the resource
|
16
|
+
# @return [nil]
|
17
|
+
# @api private
|
7
18
|
def self.property(name, key: nil, &block)
|
8
|
-
define_method(name)
|
19
|
+
define_method(name) do
|
9
20
|
if block_given?
|
10
21
|
instance_eval(&block)
|
11
22
|
elsif !key.nil?
|
12
23
|
data.fetch(key)
|
13
|
-
else
|
14
|
-
nil
|
15
24
|
end
|
16
|
-
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
def initialize(data, client, parent = nil)
|
@@ -22,11 +31,13 @@ module ProntoForms
|
|
22
31
|
@parent = parent
|
23
32
|
end
|
24
33
|
|
34
|
+
# The resource's identifier
|
25
35
|
def self.resource_name
|
26
|
-
name =
|
36
|
+
name = to_s.split('::').last
|
27
37
|
"#{name.downcase}s"
|
28
38
|
end
|
29
39
|
|
40
|
+
# The resource's identifier
|
30
41
|
def resource_name
|
31
42
|
self.class.resource_name
|
32
43
|
end
|
@@ -1,29 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'prontoforms/resource'
|
2
4
|
|
3
5
|
module ProntoForms
|
6
|
+
# A wrapper for retrieving paged resources.
|
4
7
|
class ResourceList < Resource
|
5
|
-
|
8
|
+
# @return [Hash] Query parameters for this resource list for e.g. filters
|
9
|
+
attr_reader :query
|
10
|
+
# @return [Symbol] Method to send to parent object (usually the client)
|
11
|
+
attr_reader :method
|
12
|
+
# @return [Class] Resource class
|
13
|
+
attr_reader :resource
|
14
|
+
# @return [Client] API client
|
15
|
+
attr_reader :client
|
16
|
+
# @return [Resource] Parent object (for child resources)
|
17
|
+
attr_reader :parent
|
6
18
|
|
19
|
+
# Initialize the resource list
|
20
|
+
# TODO: splat
|
21
|
+
# rubocop:disable Metrics/ParameterLists
|
7
22
|
def initialize(data, query, method, resource, client, parent = nil)
|
8
23
|
super(data, client)
|
9
24
|
@query = query
|
10
25
|
@method = method
|
11
26
|
@resource = resource
|
27
|
+
@parent = parent
|
12
28
|
end
|
29
|
+
# rubocop:enable Metrics/ParameterLists
|
13
30
|
|
14
31
|
# Retrieve the next page of results, using the same number of items per
|
15
32
|
# page as the original request.
|
16
33
|
# @return [ResourceList] A ResourceList with the next set of results
|
17
34
|
def next
|
18
|
-
client.send(method, query: query.merge({ 'p' => query['p'] + 1}))
|
35
|
+
client.send(method, query: query.merge({ 'p' => query['p'] + 1 }))
|
19
36
|
end
|
20
37
|
|
21
38
|
# Retrieve the result set
|
22
39
|
# @return [Array] Array of resource objects
|
23
40
|
def items
|
24
|
-
@data.fetch('pageData').map
|
41
|
+
@data.fetch('pageData').map do |item|
|
25
42
|
resource.new(item, client, parent)
|
26
|
-
|
43
|
+
end
|
27
44
|
end
|
28
45
|
end
|
29
46
|
end
|
data/lib/prontoforms/user.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'prontoforms/resource'
|
2
4
|
|
3
5
|
module ProntoForms
|
6
|
+
# A ProntoForms user account.
|
4
7
|
class User < Resource
|
5
|
-
def self.resource_name
|
8
|
+
def self.resource_name
|
9
|
+
'users'
|
10
|
+
end
|
6
11
|
|
7
12
|
# @return [String] The User identifier
|
8
13
|
property :id, key: 'identifier'
|
data/lib/prontoforms/version.rb
CHANGED
data/prontoforms.gemspec
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/prontoforms/version'
|
2
4
|
|
5
|
+
# rubocop:disable Layout/LineLength
|
3
6
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name
|
5
|
-
spec.version
|
6
|
-
spec.authors
|
7
|
-
spec.email
|
7
|
+
spec.name = 'prontoforms'
|
8
|
+
spec.version = ProntoForms::VERSION
|
9
|
+
spec.authors = ['Paul Holden']
|
10
|
+
spec.email = ['paul@codelunker.com']
|
8
11
|
|
9
|
-
spec.summary
|
10
|
-
spec.description
|
11
|
-
spec.homepage
|
12
|
-
spec.license
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
12
|
+
spec.summary = 'A library for using the ProntoForms REST API in Ruby applications.'
|
13
|
+
spec.description = 'A library for using the ProntoForms REST API in Ruby applications.'
|
14
|
+
spec.homepage = 'https://github.com/paulholden2/prontoforms'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
14
17
|
|
15
18
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
19
|
|
@@ -19,18 +22,27 @@ Gem::Specification.new do |spec|
|
|
19
22
|
spec.metadata['changelog_uri'] = 'https://github.com/paulholden2/prontoforms/blog/master/CHANGELOG.md'
|
20
23
|
|
21
24
|
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
23
|
-
|
24
|
-
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
26
|
+
# into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
30
|
+
end
|
25
31
|
end
|
26
|
-
|
27
|
-
spec.
|
32
|
+
|
33
|
+
spec.bindir = 'exe'
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
35
|
spec.require_paths = ['lib']
|
29
36
|
|
30
37
|
spec.add_dependency 'faraday', '~> 1.0'
|
31
38
|
|
32
39
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
-
spec.add_development_dependency 'rake', '
|
40
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
34
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.82.0'
|
43
|
+
spec.add_development_dependency 'sinatra', '~> 2.0'
|
44
|
+
spec.add_development_dependency 'sinatra-contrib', '~> 2.0'
|
45
|
+
spec.add_development_dependency 'webmock', '~> 3.6'
|
35
46
|
spec.add_development_dependency 'yard', '~> 0.9'
|
36
47
|
end
|
48
|
+
# rubocop:enable Layout/LineLength
|
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: 1.0.1
|
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-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,62 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.82.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.82.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra-contrib
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.6'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.6'
|
69
125
|
- !ruby/object:Gem::Dependency
|
70
126
|
name: yard
|
71
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,13 +138,15 @@ dependencies:
|
|
82
138
|
version: '0.9'
|
83
139
|
description: A library for using the ProntoForms REST API in Ruby applications.
|
84
140
|
email:
|
85
|
-
- paul@
|
141
|
+
- paul@codelunker.com
|
86
142
|
executables: []
|
87
143
|
extensions: []
|
88
144
|
extra_rdoc_files: []
|
89
145
|
files:
|
146
|
+
- ".github/workflows/checks.yml"
|
90
147
|
- ".gitignore"
|
91
148
|
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
92
150
|
- ".travis.yml"
|
93
151
|
- CHANGELOG.md
|
94
152
|
- Gemfile
|
@@ -99,6 +157,8 @@ files:
|
|
99
157
|
- bin/setup
|
100
158
|
- lib/prontoforms.rb
|
101
159
|
- lib/prontoforms/client.rb
|
160
|
+
- lib/prontoforms/document.rb
|
161
|
+
- lib/prontoforms/form.rb
|
102
162
|
- lib/prontoforms/form_space.rb
|
103
163
|
- lib/prontoforms/form_submission.rb
|
104
164
|
- lib/prontoforms/resource.rb
|
@@ -122,14 +182,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
182
|
requirements:
|
123
183
|
- - ">="
|
124
184
|
- !ruby/object:Gem::Version
|
125
|
-
version: 2.
|
185
|
+
version: 2.6.0
|
126
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
187
|
requirements:
|
128
188
|
- - ">="
|
129
189
|
- !ruby/object:Gem::Version
|
130
190
|
version: '0'
|
131
191
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.1.4
|
133
193
|
signing_key:
|
134
194
|
specification_version: 4
|
135
195
|
summary: A library for using the ProntoForms REST API in Ruby applications.
|