base-api-io 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +47 -0
- data/base-api-io.gemspec +1 -0
- data/lib/base.rb +1 -0
- data/lib/base/client.rb +10 -0
- data/lib/base/endpoints/forms.rb +111 -0
- data/lib/base/version.rb +1 -1
- 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: 2f086dfdafe3a95bac7eeae96906a961d0384c0f084362764b36255e88ef020c
|
4
|
+
data.tar.gz: 8a2e73d49677a5fa9abf2ab1361c5c0d3533cf70e26a3e13553321cae5643e23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 065f852cf4e48ac7ef6a535c804b8658e2948fd474e902d7d3160ef48da0c19ffb1fbc4941fffd369dcfd7e71fa7cea61ca01b60c1b9926d528375cc988af09f
|
7
|
+
data.tar.gz: ee36bec80f5c6940b9e24382da0355dcdd6eee658112bb4e2e8e8fb310347e900b0d5e4fc01e96229f7a3ffd0259dce9cc7f5d3a9c2236ef6685ea6f9789e9ac
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
base-api-io (1.
|
4
|
+
base-api-io (1.4.0)
|
5
5
|
faraday (~> 0.15.4)
|
6
|
+
mimetype-fu (~> 0.1.2)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -17,6 +18,7 @@ GEM
|
|
17
18
|
multipart-post (>= 1.2, < 3)
|
18
19
|
hashdiff (1.0.0)
|
19
20
|
jaro_winkler (1.5.3)
|
21
|
+
mimetype-fu (0.1.2)
|
20
22
|
multipart-post (2.1.1)
|
21
23
|
parallel (1.17.0)
|
22
24
|
parser (2.6.3.0)
|
data/README.md
CHANGED
@@ -232,6 +232,53 @@ results =
|
|
232
232
|
text: 'Text')
|
233
233
|
```
|
234
234
|
|
235
|
+
### Forms
|
236
|
+
|
237
|
+
A project can have many forms and those form can have many submissions.
|
238
|
+
|
239
|
+
The `forms` endpoint allows you to programatically create, submit and manage forms.
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
# List forms
|
243
|
+
forms = client.forms.list(page: 1, per_page: 10)
|
244
|
+
forms.items # The array of forms
|
245
|
+
forms.metadata # The metadata object containing the total count
|
246
|
+
|
247
|
+
# Create a form
|
248
|
+
form =
|
249
|
+
client.forms.create(name: 'Form')
|
250
|
+
|
251
|
+
# Get a form
|
252
|
+
form =
|
253
|
+
client.forms.get('form_id')
|
254
|
+
|
255
|
+
# Delete a form (and it's submissions)
|
256
|
+
form =
|
257
|
+
client.forms.delete('form_id')
|
258
|
+
|
259
|
+
# Submit a form
|
260
|
+
submission =
|
261
|
+
client.forms.submit(
|
262
|
+
id: 'form_id',
|
263
|
+
form: {
|
264
|
+
file: File.open('description.txt'),
|
265
|
+
key: 'value'
|
266
|
+
})
|
267
|
+
|
268
|
+
# List form submissions
|
269
|
+
submissions = client.forms.submissions(id: 'form_id', page: 1, per_page: 10)
|
270
|
+
submissions.items # The array of forms submissions
|
271
|
+
submissions.metadata # The metadata object containing the total count
|
272
|
+
|
273
|
+
# Get a submission
|
274
|
+
submission =
|
275
|
+
client.forms.get_submission('form_id', 'submission_id')
|
276
|
+
|
277
|
+
# Delete a submission
|
278
|
+
submission =
|
279
|
+
client.forms.delete_submission('form_id', 'submission_id')
|
280
|
+
```
|
281
|
+
|
235
282
|
## Development
|
236
283
|
|
237
284
|
This library uses [Faraday](https://lostisland.github.io/faraday/), you can run the
|
data/base-api-io.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
28
|
spec.add_dependency 'faraday', '~> 0.15.4'
|
29
|
+
spec.add_dependency 'mimetype-fu', '~> 0.1.2'
|
29
30
|
|
30
31
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
31
32
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/lib/base.rb
CHANGED
data/lib/base/client.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative 'endpoints/images'
|
|
11
11
|
require_relative 'endpoints/emails'
|
12
12
|
require_relative 'endpoints/users'
|
13
13
|
require_relative 'endpoints/files'
|
14
|
+
require_relative 'endpoints/forms'
|
14
15
|
|
15
16
|
module Base
|
16
17
|
# A client containing all the endpoints.
|
@@ -36,6 +37,9 @@ module Base
|
|
36
37
|
# Endpoint for the files.
|
37
38
|
attr_reader :files
|
38
39
|
|
40
|
+
# Endpoint for the files.
|
41
|
+
attr_reader :forms
|
42
|
+
|
39
43
|
# Initializes a new client with an access_token and optional url.
|
40
44
|
def initialize(access_token:, url: 'https://api.base-api.io')
|
41
45
|
@users =
|
@@ -79,6 +83,12 @@ module Base
|
|
79
83
|
access_token: access_token,
|
80
84
|
url: url
|
81
85
|
)
|
86
|
+
|
87
|
+
@forms =
|
88
|
+
Endpoints::Forms.new(
|
89
|
+
access_token: access_token,
|
90
|
+
url: url
|
91
|
+
)
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Base
|
4
|
+
module Endpoints
|
5
|
+
# This endpoint contains methods for forms.
|
6
|
+
class Forms < Endpoint
|
7
|
+
# Initializes this endpoint.
|
8
|
+
def initialize(access_token:, url:)
|
9
|
+
@path = 'forms'
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# Lists the forms of a project
|
14
|
+
def list(page: 1, per_page: 10)
|
15
|
+
request do
|
16
|
+
response =
|
17
|
+
connection.get('', per_page: per_page, page: page)
|
18
|
+
|
19
|
+
parse(response.body)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a form with the given name
|
24
|
+
def create(name:)
|
25
|
+
request do
|
26
|
+
response =
|
27
|
+
connection.post('', 'name' => name)
|
28
|
+
|
29
|
+
parse(response.body)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the form with the given ID.
|
34
|
+
def get(id)
|
35
|
+
request do
|
36
|
+
response =
|
37
|
+
connection.get id
|
38
|
+
|
39
|
+
parse(response.body)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Deletes the form with the given ID.
|
44
|
+
def delete(id)
|
45
|
+
request do
|
46
|
+
response =
|
47
|
+
connection.delete id
|
48
|
+
|
49
|
+
parse(response.body)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Submits a new submission for the form with the given ID.
|
54
|
+
def submit(id:, form:)
|
55
|
+
request do
|
56
|
+
payload =
|
57
|
+
form.each_with_object({}) do |(key, value), memo|
|
58
|
+
memo[key] =
|
59
|
+
case value
|
60
|
+
when File, Tempfile
|
61
|
+
Faraday::UploadIO.new(
|
62
|
+
value.path,
|
63
|
+
File.mime_type?(value),
|
64
|
+
File.basename(value)
|
65
|
+
)
|
66
|
+
else
|
67
|
+
value
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
response =
|
72
|
+
connection.post("#{id}/submit", payload)
|
73
|
+
|
74
|
+
parse(response.body)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the submission for the form with the given ID.
|
79
|
+
def submissions(id:,
|
80
|
+
page: 1,
|
81
|
+
per_page: 10)
|
82
|
+
request do
|
83
|
+
response =
|
84
|
+
connection.get("#{id}/submissions", per_page: per_page, page: page)
|
85
|
+
|
86
|
+
parse(response.body)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns the submission with the given ID of the form with the given ID.
|
91
|
+
def get_submission(id, submission_id)
|
92
|
+
request do
|
93
|
+
response =
|
94
|
+
connection.get "#{id}/submissions/#{submission_id}"
|
95
|
+
|
96
|
+
parse(response.body)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Deletes the submission with the given ID of the form with the given ID.
|
101
|
+
def delete_submission(id, submission_id)
|
102
|
+
request do
|
103
|
+
response =
|
104
|
+
connection.delete "#{id}/submissions/#{submission_id}"
|
105
|
+
|
106
|
+
parse(response.body)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/base/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base-api-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gusztáv Szikszai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.15.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mimetype-fu
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +132,7 @@ files:
|
|
118
132
|
- lib/base/endpoint.rb
|
119
133
|
- lib/base/endpoints/emails.rb
|
120
134
|
- lib/base/endpoints/files.rb
|
135
|
+
- lib/base/endpoints/forms.rb
|
121
136
|
- lib/base/endpoints/images.rb
|
122
137
|
- lib/base/endpoints/mailing_lists.rb
|
123
138
|
- lib/base/endpoints/passwords.rb
|