docuseal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cdbe565c37f9a94a278e42dcb4369380c467ab5f06e9cdaf0c693904869c5bc5
4
+ data.tar.gz: 1986099e7e5af342564dda635432a8ba17f8ce765b4da27483fd23193b27f8c2
5
+ SHA512:
6
+ metadata.gz: 878910faa3dfc3b4450985c204fabfb2f930280cf24bac6dd999c52a2e282a1341fdb83e11612db81bffb1be0288366e121f7430503c4513c90479ee712f6426
7
+ data.tar.gz: 202328030706802a4d898831063a2e835c3c98797e233dad29f3feffbd3c6af03579e4bafccdb6bad3a09533d490134d7ff7db735918566bd7b985a86441aa78
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-22
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at martin.mochetti@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in docuseal.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
13
+
14
+ group :development, :test do
15
+ gem "webmock", "~> 3.19.1"
16
+ gem "byebug", "~> 11.1"
17
+ gem "pry", "~> 0.14.2"
18
+ gem "pry-byebug", "~> 3.10"
19
+ gem "pry-rescue", "~> 1.5"
20
+ gem "pry-stack_explorer", "~> 0.6.1"
21
+ end
22
+
23
+ group :test do
24
+ gem "simplecov"
25
+ gem "simplecov-cobertura"
26
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ docuseal (0.1.0)
5
+ faraday (>= 1)
6
+ faraday_middleware (>= 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.6)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ binding_of_caller (1.0.0)
15
+ debug_inspector (>= 0.0.1)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ debug_inspector (1.2.0)
21
+ diff-lcs (1.5.0)
22
+ docile (1.4.0)
23
+ faraday (1.10.3)
24
+ faraday-em_http (~> 1.0)
25
+ faraday-em_synchrony (~> 1.0)
26
+ faraday-excon (~> 1.1)
27
+ faraday-httpclient (~> 1.0)
28
+ faraday-multipart (~> 1.0)
29
+ faraday-net_http (~> 1.0)
30
+ faraday-net_http_persistent (~> 1.0)
31
+ faraday-patron (~> 1.0)
32
+ faraday-rack (~> 1.0)
33
+ faraday-retry (~> 1.0)
34
+ ruby2_keywords (>= 0.0.4)
35
+ faraday-em_http (1.0.0)
36
+ faraday-em_synchrony (1.0.0)
37
+ faraday-excon (1.1.0)
38
+ faraday-httpclient (1.0.1)
39
+ faraday-multipart (1.0.4)
40
+ multipart-post (~> 2)
41
+ faraday-net_http (1.0.1)
42
+ faraday-net_http_persistent (1.2.0)
43
+ faraday-patron (1.0.0)
44
+ faraday-rack (1.0.0)
45
+ faraday-retry (1.0.3)
46
+ faraday_middleware (1.2.0)
47
+ faraday (~> 1.0)
48
+ hashdiff (1.1.0)
49
+ interception (0.5)
50
+ json (2.7.1)
51
+ language_server-protocol (3.17.0.3)
52
+ lint_roller (1.1.0)
53
+ method_source (1.0.0)
54
+ multipart-post (2.3.0)
55
+ parallel (1.24.0)
56
+ parser (3.2.2.4)
57
+ ast (~> 2.4.1)
58
+ racc
59
+ pry (0.14.2)
60
+ coderay (~> 1.1)
61
+ method_source (~> 1.0)
62
+ pry-byebug (3.10.1)
63
+ byebug (~> 11.0)
64
+ pry (>= 0.13, < 0.15)
65
+ pry-rescue (1.5.2)
66
+ interception (>= 0.5)
67
+ pry (>= 0.12.0)
68
+ pry-stack_explorer (0.6.1)
69
+ binding_of_caller (~> 1.0)
70
+ pry (~> 0.13)
71
+ public_suffix (5.0.4)
72
+ racc (1.7.3)
73
+ rainbow (3.1.1)
74
+ rake (13.1.0)
75
+ regexp_parser (2.8.3)
76
+ rexml (3.2.6)
77
+ rspec (3.12.0)
78
+ rspec-core (~> 3.12.0)
79
+ rspec-expectations (~> 3.12.0)
80
+ rspec-mocks (~> 3.12.0)
81
+ rspec-core (3.12.2)
82
+ rspec-support (~> 3.12.0)
83
+ rspec-expectations (3.12.3)
84
+ diff-lcs (>= 1.2.0, < 2.0)
85
+ rspec-support (~> 3.12.0)
86
+ rspec-mocks (3.12.6)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.12.0)
89
+ rspec-support (3.12.1)
90
+ rubocop (1.57.2)
91
+ json (~> 2.3)
92
+ language_server-protocol (>= 3.17.0)
93
+ parallel (~> 1.10)
94
+ parser (>= 3.2.2.4)
95
+ rainbow (>= 2.2.2, < 4.0)
96
+ regexp_parser (>= 1.8, < 3.0)
97
+ rexml (>= 3.2.5, < 4.0)
98
+ rubocop-ast (>= 1.28.1, < 2.0)
99
+ ruby-progressbar (~> 1.7)
100
+ unicode-display_width (>= 2.4.0, < 3.0)
101
+ rubocop-ast (1.30.0)
102
+ parser (>= 3.2.1.0)
103
+ rubocop-performance (1.19.1)
104
+ rubocop (>= 1.7.0, < 2.0)
105
+ rubocop-ast (>= 0.4.0)
106
+ ruby-progressbar (1.13.0)
107
+ ruby2_keywords (0.0.5)
108
+ simplecov (0.21.2)
109
+ docile (~> 1.1)
110
+ simplecov-html (~> 0.11)
111
+ simplecov_json_formatter (~> 0.1)
112
+ simplecov-cobertura (2.1.0)
113
+ rexml
114
+ simplecov (~> 0.19)
115
+ simplecov-html (0.12.3)
116
+ simplecov_json_formatter (0.1.4)
117
+ standard (1.32.0)
118
+ language_server-protocol (~> 3.17.0.2)
119
+ lint_roller (~> 1.0)
120
+ rubocop (~> 1.57.2)
121
+ standard-custom (~> 1.0.0)
122
+ standard-performance (~> 1.2)
123
+ standard-custom (1.0.2)
124
+ lint_roller (~> 1.0)
125
+ rubocop (~> 1.50)
126
+ standard-performance (1.2.1)
127
+ lint_roller (~> 1.1)
128
+ rubocop-performance (~> 1.19.1)
129
+ unicode-display_width (2.5.0)
130
+ webmock (3.19.1)
131
+ addressable (>= 2.8.0)
132
+ crack (>= 0.3.2)
133
+ hashdiff (>= 0.4.0, < 2.0.0)
134
+
135
+ PLATFORMS
136
+ x86_64-darwin-23
137
+
138
+ DEPENDENCIES
139
+ byebug (~> 11.1)
140
+ docuseal!
141
+ pry (~> 0.14.2)
142
+ pry-byebug (~> 3.10)
143
+ pry-rescue (~> 1.5)
144
+ pry-stack_explorer (~> 0.6.1)
145
+ rake (~> 13.0)
146
+ rspec (~> 3.0)
147
+ simplecov
148
+ simplecov-cobertura
149
+ standard (~> 1.3)
150
+ webmock (~> 3.19.1)
151
+
152
+ BUNDLED WITH
153
+ 2.4.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Martin Mochetti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # Docuseal API Connector
2
+
3
+ A lightweight API connector for docuseal. Docuseal API docs: https://www.docuseal.co/docs/api
4
+
5
+ :warning: The extracted API objects don't do input parameters validations. It's a simple faraday wrapper that allows you to send as many inputs as you want. The docuseal API might fail when passing a wrong set of parameters.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `docuseal` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add docuseal
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install docuseal
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+
23
+ You'll need to set the Docuseal API key in the configuration.
24
+
25
+ ```rb
26
+ Docuseal.configure do |config|
27
+ config.api_key = "{DOCUSEAL_API_KEY}"
28
+ end
29
+ ```
30
+
31
+ You can also set some other configurations like:
32
+
33
+ ```rb
34
+ Docuseal.configure do |config|
35
+ config.api_key = "{DOCUSEAL_API_KEY}"
36
+
37
+ # Set the docuseal API request timeout, the default is 120 seconds
38
+ config.request_timeout = 20
39
+
40
+ # Set extra headers that will get attached to every docuseal api request.
41
+ # Useful for observability tools like Helicone: https://www.helicone.ai/
42
+ config.global_headers = {
43
+ "Helicone-Auth": "Bearer HELICONE_API_KEY"
44
+ "helicone-stream-force-format" => "true",
45
+ }
46
+
47
+ # Set the base_uri to use the docuseal EU servers if you're account was registered there.
48
+ # The default is https://api.docuseal.co/
49
+ config.base_uri = "https://api.docuseal.eu/"
50
+ end
51
+ ```
52
+
53
+ ### Submissions
54
+
55
+ #### List
56
+
57
+ Reference: https://www.docuseal.co/docs/api#list-all-submissions
58
+
59
+ ```rb
60
+ submissions = Docuseal::Submission.list
61
+ ```
62
+
63
+ #### Find
64
+
65
+ Reference: https://www.docuseal.co/docs/api#get-a-submission
66
+
67
+ ```rb
68
+ submission = Docuseal::Submission.find(1)
69
+ ```
70
+
71
+ #### Create
72
+
73
+ Reference: https://www.docuseal.co/docs/api#create-a-submission
74
+
75
+ ```rb
76
+ submission = Docuseal::Submission.create(
77
+ template_id: 1000001,
78
+ send_email: true,
79
+ submitters: [{role: 'First Party', email: 'john.doe@example.com'}]
80
+ )
81
+ ```
82
+
83
+ #### Create From Email
84
+
85
+ Reference: https://www.docuseal.co/docs/api#create-submissions-from-emails
86
+
87
+ ```rb
88
+ submission = Docuseal::Submission.create(
89
+ from: :emails
90
+ template_id: 1000001,
91
+ emails: 'hi@docuseal.co, example@docuseal.co'
92
+ )
93
+ ```
94
+
95
+ #### Archive
96
+
97
+ Reference: https://www.docuseal.co/docs/api#archive-a-submission
98
+
99
+ ```rb
100
+ submission = Docuseal::Submission.archive(1)
101
+ ```
102
+
103
+ ### Submitters
104
+
105
+ #### List
106
+
107
+ Reference: https://www.docuseal.co/docs/api#list-all-submitters
108
+
109
+ ```rb
110
+ submitters = Docuseal::Submitter.list
111
+ ```
112
+
113
+ #### Find
114
+
115
+ Reference: https://www.docuseal.co/docs/api#get-a-submitter
116
+
117
+ ```rb
118
+ submitter = Docuseal::Submitter.find(1)
119
+ ```
120
+
121
+ #### Update
122
+
123
+ Reference: https://www.docuseal.co/docs/api#update-a-submitter
124
+
125
+ ```rb
126
+ submitter = Docuseal::Submitter.update(1,
127
+ email: 'john.doe@example.com',
128
+ fields: [{name: 'First Name', default_value: 'Acme'}]
129
+ )
130
+ ```
131
+
132
+ ### Templates
133
+
134
+ #### List
135
+
136
+ Reference: https://www.docuseal.co/docs/api#list-all-templates
137
+
138
+ ```rb
139
+ templates = Docuseal::Template.list
140
+ ```
141
+
142
+ #### Find
143
+
144
+ Reference: https://www.docuseal.co/docs/api#get-a-template
145
+
146
+ ```rb
147
+ template = Docuseal::Template.find(1)
148
+ ```
149
+
150
+ #### Create From DOCX
151
+
152
+ Reference: https://www.docuseal.co/docs/api#create-a-template-from-word-docx
153
+
154
+ ```rb
155
+ template = Docuseal::Template.create(
156
+ from: :docx,
157
+ name: 'Demo DOCX',
158
+ documents: [{ name: 'Demo DOCX', file: 'base64' }]
159
+ )
160
+ ```
161
+
162
+ #### Create From HTML
163
+
164
+ Reference: https://www.docuseal.co/docs/api#create-a-template-from-html
165
+
166
+ ```rb
167
+ template = Docuseal::Template.create(
168
+ from: :html,
169
+ html: '<p>Lorem Ipsum is simply dummy text of the\n<text-field\n name="Industry"\n role="First Party"\n required="false"\n style="width: 80px; height: 16px; display: inline-block; margin-bottom: -4px">\n</text-field>\nand typesetting industry</p>\n',
170
+ name: 'Test Template'
171
+ )
172
+ ```
173
+
174
+ #### Create From PDf
175
+
176
+ Reference: https://www.docuseal.co/docs/api#create-a-template-from-existing-pdf
177
+
178
+ ```rb
179
+ template = Docuseal::Template.create(
180
+ from: :pdf,
181
+ name: 'Test PDF',
182
+ documents: [
183
+ {
184
+ name: 'string',
185
+ file: 'base64',
186
+ fields: [{name: 'string', areas: [{x: 0, y: 0, w: 0, h: 0, page: 0}]}]
187
+ }
188
+ ]
189
+ )
190
+ ```
191
+
192
+ #### Clone
193
+
194
+ Reference: https://www.docuseal.co/docs/api#clone-a-template
195
+
196
+ ```rb
197
+ template = Docuseal::Template.clone(1,
198
+ name: 'Clone of Test',
199
+ )
200
+ ```
201
+
202
+ #### Update
203
+
204
+ Reference: https://www.docuseal.co/docs/api#update-a-template
205
+
206
+ ```rb
207
+ template = Docuseal::Template.update(1,
208
+ name: 'New Document Name',
209
+ folder_name: 'New Folder'
210
+ )
211
+ ```
212
+
213
+ #### Update Documents
214
+
215
+ Reference: https://www.docuseal.co/docs/api#update-template-documents
216
+
217
+ ```rb
218
+ template = Docuseal::Template.update_documents(1,
219
+ documents: [{file: 'base64'}]
220
+ )
221
+ ```
222
+
223
+ #### Archive
224
+
225
+ Reference: https://www.docuseal.co/docs/api#archive-a-template
226
+
227
+ ```rb
228
+ template = Docuseal::Template.archive(1)
229
+ ```
230
+
231
+ ## Development
232
+
233
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
234
+
235
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
236
+
237
+ You can test any of the endpoints lively if using the following bash command:
238
+
239
+ ```bash
240
+ DOCUSEAL_API_KEY={YOUR API KEY} DOCUSEAL_BASE_URI={YOUR BASE URI} bin/console
241
+ ```
242
+
243
+ Then do
244
+
245
+ ```bash
246
+ irb(main):002> Docuseal::Template.list
247
+ ```
248
+
249
+ ## Contributing
250
+
251
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/docuseal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/docuseal/blob/main/CODE_OF_CONDUCT.md).
252
+
253
+ ## License
254
+
255
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
256
+
257
+ ## Code of Conduct
258
+
259
+ Everyone interacting in the Docuseal project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/docuseal/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,25 @@
1
+ module Docuseal
2
+ class Client
3
+ include Docuseal::HTTP
4
+
5
+ CONFIG_KEYS = %i[
6
+ api_key request_timeout base_uri global_headers
7
+ ].freeze
8
+
9
+ attr_reader(*CONFIG_KEYS)
10
+
11
+ def self.instance
12
+ @instance ||= new
13
+ end
14
+
15
+ private
16
+
17
+ def initialize
18
+ CONFIG_KEYS.each do |key|
19
+ # Set instance variables like api_type & access_token. Fall back to global config
20
+ # if not present.
21
+ instance_variable_set("@#{key}", Docuseal.configuration.send(key))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ module Docuseal
2
+ module HTTP
3
+ def get(path, headers: {}, **query)
4
+ full_uri = uri(path:, query:)
5
+
6
+ conn.get(full_uri) do |req|
7
+ req.headers = all_headers(headers)
8
+ end
9
+ end
10
+
11
+ def post(path, data: {}, headers: {}, **query)
12
+ full_uri = uri(path:, query:)
13
+
14
+ conn.post(full_uri) do |req|
15
+ req.body = data.to_json if data.any?
16
+ req.headers = all_headers(headers)
17
+ end
18
+ end
19
+
20
+ def put(path, data: {}, headers: {}, **query)
21
+ full_uri = uri(path:, query:)
22
+
23
+ conn.put(full_uri) do |req|
24
+ req.body = data.to_json if data.any?
25
+ req.headers = all_headers(headers)
26
+ end
27
+ end
28
+
29
+ def delete(path, headers: {}, **query)
30
+ full_uri = uri(path:, query:)
31
+
32
+ conn.delete(full_uri) do |req|
33
+ req.headers = all_headers(headers)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def conn
40
+ connection = Faraday.new do |f|
41
+ f.options[:timeout] = request_timeout
42
+ f.request :json
43
+ f.response :json
44
+ f.response :raise_error
45
+ end
46
+
47
+ @faraday_middleware&.call(connection)
48
+
49
+ connection
50
+ end
51
+
52
+ def uri(path:, query: {})
53
+ File.join(base_uri, path) + "?#{URI.encode_www_form(query)}"
54
+ end
55
+
56
+ def all_headers(request_headers = {})
57
+ {
58
+ "X-Auth-Token" => api_key
59
+ }.merge(global_headers).merge(request_headers)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,85 @@
1
+ module Docuseal
2
+ class Model
3
+ class << self
4
+ def create(path: self.path, **attrs)
5
+ raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:create)
6
+
7
+ response = Docuseal::Client.instance.post(path, data: attrs)
8
+ body = response.body
9
+
10
+ return body.map(&self) if body.is_a?(Array)
11
+
12
+ new(body)
13
+ end
14
+
15
+ def find(id)
16
+ raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:find)
17
+
18
+ response = Docuseal::Client.instance.get("#{path}/#{id}")
19
+ new(response.body)
20
+ end
21
+
22
+ def update(id, **attrs)
23
+ raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:update)
24
+
25
+ response = Docuseal::Client.instance.put("#{path}/#{id}", data: attrs)
26
+ new(response.body)
27
+ end
28
+
29
+ def list(**)
30
+ raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:list)
31
+
32
+ response = Docuseal::Client.instance.get(path, **)
33
+ response.body["data"].map(&self)
34
+ end
35
+
36
+ def archive(id)
37
+ raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:archive)
38
+
39
+ response = Docuseal::Client.instance.delete("#{path}/#{id}")
40
+ new(response.body)
41
+ end
42
+
43
+ # Auxiliary methods
44
+
45
+ def to_proc
46
+ ->(attrs) { new(attrs) }
47
+ end
48
+
49
+ def skip_coertion_for(attrs = [])
50
+ @skip_coertion_for ||= attrs
51
+ end
52
+
53
+ def not_allowed_to(attrs = [])
54
+ @not_allowed_to ||= attrs
55
+ end
56
+ end
57
+
58
+ def to_json
59
+ @_raw.to_json
60
+ end
61
+
62
+ protected
63
+
64
+ def initialize(attrs = {})
65
+ @_raw = attrs
66
+
67
+ attrs.each do |key, value|
68
+ if self.class.skip_coertion_for.include?(key.to_sym)
69
+ instance_variable_set("@#{key}", value)
70
+ else
71
+ coerced_value = if value.is_a?(Hash)
72
+ Docuseal::Model.new(value)
73
+ elsif value.is_a?(Array)
74
+ value.map { |v| Docuseal::Model.new(v) }
75
+ else
76
+ value
77
+ end
78
+ instance_variable_set("@#{key}", coerced_value)
79
+ end
80
+ end
81
+
82
+ instance_variables.each { |iv| self.class.send(:attr_reader, iv.to_s[1..].to_sym) }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,18 @@
1
+ module Docuseal
2
+ class Submission < Model
3
+ skip_coertion_for [:values]
4
+ not_allowed_to [:update]
5
+
6
+ def self.path
7
+ "/submissions"
8
+ end
9
+
10
+ def self.create(from: nil, **attrs)
11
+ if from
12
+ super(path: "#{path}/#{from}", **attrs)
13
+ else
14
+ super(**attrs)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Docuseal
2
+ class Submitter < Model
3
+ not_allowed_to %i[create archive]
4
+
5
+ def self.path
6
+ "/submitters"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Docuseal
2
+ class Template < Model
3
+ def self.path
4
+ "/templates"
5
+ end
6
+
7
+ # from: :html, :docx or :pdf
8
+ #
9
+ # https://www.docuseal.co/docs/api#create-a-template-from-html
10
+ # https://www.docuseal.co/docs/api#create-a-template-from-word-docx
11
+ # https://www.docuseal.co/docs/api#create-a-template-from-existing-pdf
12
+ def self.create(from:, **attrs)
13
+ super(path: "#{path}/#{from}", **attrs)
14
+ end
15
+
16
+ # https://www.docuseal.co/docs/api#update-template-documents
17
+ def self.update_documents(id, documents: [])
18
+ return if documents.empty?
19
+ response = Docuseal::Client.instance.put("#{path}/#{id}/documents", data: {documents:})
20
+ new(response.body)
21
+ end
22
+
23
+ # https://www.docuseal.co/docs/api#clone-a-template
24
+ def self.clone(id, **attrs)
25
+ response = Docuseal::Client.instance.post("#{path}/#{id}/clone", data: attrs)
26
+ new(response.body)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Docuseal
4
+ VERSION = "0.1.0"
5
+ end
data/lib/docuseal.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "faraday"
2
+
3
+ require_relative "docuseal/http"
4
+ require_relative "docuseal/client"
5
+ require_relative "docuseal/model"
6
+ require_relative "docuseal/submission"
7
+ require_relative "docuseal/submitter"
8
+ require_relative "docuseal/template"
9
+
10
+ module Docuseal
11
+ class Error < StandardError; end
12
+
13
+ class ConfigurationError < Error; end
14
+
15
+ class Configuration
16
+ attr_accessor :request_timeout, :base_uri, :global_headers
17
+ attr_writer :api_key
18
+
19
+ DEFAULT_BASE_URI = "https://api.docuseal.co/".freeze
20
+ DEFAULT_REQUEST_TIMEOUT = 120
21
+
22
+ def initialize
23
+ @api_key = ENV["DOCUSEAL_API_KEY"]
24
+ @request_timeout = DEFAULT_REQUEST_TIMEOUT
25
+ @base_uri = ENV.fetch("DOCUSEAL_BASE_URI", DEFAULT_BASE_URI)
26
+ @global_headers = {}
27
+ end
28
+
29
+ def api_key
30
+ @api_key || (raise ConfigurationError, "Docuseal api_key missing!")
31
+ end
32
+ end
33
+
34
+ class << self
35
+ attr_writer :configuration
36
+ end
37
+
38
+ def self.configuration
39
+ @configuration ||= Docuseal::Configuration.new
40
+ end
41
+
42
+ def self.configure
43
+ yield(configuration)
44
+ end
45
+ end
data/sig/docuseal.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Docuseal
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docuseal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Mochetti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description: A lightway, simple and non-official docuseal API connector.
42
+ email:
43
+ - martin.mochetti@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".ruby-version"
50
+ - ".standard.yml"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/docuseal.rb
59
+ - lib/docuseal/client.rb
60
+ - lib/docuseal/http.rb
61
+ - lib/docuseal/model.rb
62
+ - lib/docuseal/submission.rb
63
+ - lib/docuseal/submitter.rb
64
+ - lib/docuseal/template.rb
65
+ - lib/docuseal/version.rb
66
+ - sig/docuseal.rbs
67
+ homepage: https://github.com/moraki-finance/docuseal
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/moraki-finance/docuseal
72
+ source_code_uri: https://github.com/moraki-finance/docuseal
73
+ changelog_uri: https://github.com/moraki-finance/docuseal/blob/main/CHANGELOG.md
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.5.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: A lightweight docuseal API connector.
93
+ test_files: []