fulcrum 0.8.1 → 0.8.2
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 +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +16 -0
- data/fulcrum.gemspec +1 -1
- data/lib/fulcrum.rb +1 -0
- data/lib/fulcrum/attachment.rb +46 -0
- data/lib/fulcrum/client.rb +4 -0
- data/lib/fulcrum/version.rb +1 -1
- data/spec/data/test.pdf +56 -0
- data/spec/lib/attachment_spec.rb +93 -0
- metadata +13 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a74d4e0476b8350803713e7372bb9d98a439ece325338a921c7fd36d0bb389e3
|
|
4
|
+
data.tar.gz: 0d44ecdad6ea4865ab0fc354a4ee62fa11f1ac119f57d6f4342a349393258257
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d6103a9947ba826ed6d6cea1d821fa435e43bb9045db246c9577c921f3ec66360708a485f9179ccac563ba7ed97b3f98acc82ed2ef84367c083675e9808549f
|
|
7
|
+
data.tar.gz: a63327b930c34b0c07bdcfbc83cf565df9f8aaae74d87e3d5577f6fa5080957988e2ec2f9e6883e57a13ff21957a315bce733a5b83962c597f29e022aba675d2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -291,6 +291,22 @@ Format can be 'json', 'geojson', 'gpx', or 'kml'.
|
|
|
291
291
|
|
|
292
292
|
|
|
293
293
|
|
|
294
|
+
## Attachments
|
|
295
|
+
|
|
296
|
+
### client.attachments.all(params = {})
|
|
297
|
+
|
|
298
|
+
### client.attachments.find(id)
|
|
299
|
+
|
|
300
|
+
### client.attachments.create(file_or_path, attributes = {})
|
|
301
|
+
|
|
302
|
+
Suggestion pass a File.open(file) to this as parameter
|
|
303
|
+
|
|
304
|
+
### client.attachments.finalize(id)
|
|
305
|
+
|
|
306
|
+
### client.attachments.delete(id)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
294
310
|
## Changesets
|
|
295
311
|
|
|
296
312
|
### client.changesets.all(params = {})
|
data/fulcrum.gemspec
CHANGED
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
|
16
16
|
gem.require_paths = ["lib"]
|
|
17
17
|
gem.version = Fulcrum::VERSION
|
|
18
18
|
|
|
19
|
-
gem.add_development_dependency 'rake',
|
|
19
|
+
gem.add_development_dependency 'rake', ">= 12.3.3"
|
|
20
20
|
gem.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
|
21
21
|
gem.add_development_dependency 'webmock', '~> 1.12', '>= 1.12.0'
|
|
22
22
|
|
data/lib/fulcrum.rb
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Fulcrum
|
|
2
|
+
class Attachment < MediaResource
|
|
3
|
+
include Actions::Delete
|
|
4
|
+
|
|
5
|
+
def finalize(id)
|
|
6
|
+
call(:post, "#{collection}/finalize", {id: id})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def collection
|
|
10
|
+
resources_name
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def member(id)
|
|
14
|
+
"#{resources_name}/#{id}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def find(id)
|
|
18
|
+
call(:get, member(id))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def all(params = {})
|
|
22
|
+
call(:get, collection, params)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(file, attrs = {})
|
|
26
|
+
response = call(:post, create_action, attrs)
|
|
27
|
+
binary_upload(file, response['url'], attrs[:file_size])
|
|
28
|
+
{ name: attrs[:name], attachment_id: response['id'] }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def binary_upload(file, url, file_size)
|
|
34
|
+
connection = Faraday.new(url: url) do |faraday|
|
|
35
|
+
faraday.request :multipart
|
|
36
|
+
faraday.adapter :net_http
|
|
37
|
+
end
|
|
38
|
+
connection.put do |req|
|
|
39
|
+
req.headers['Content-Type'] = 'octet/stream'
|
|
40
|
+
req.headers['Content-Length'] = "#{file_size}"
|
|
41
|
+
req.headers['Content-Transfer-Encoding'] = 'binary'
|
|
42
|
+
req.body = Faraday::UploadIO.new(file, 'octet/stream')
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/fulcrum/client.rb
CHANGED
data/lib/fulcrum/version.rb
CHANGED
data/spec/data/test.pdf
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
%PDF-1.7
|
|
2
|
+
%����
|
|
3
|
+
1 0 obj
|
|
4
|
+
<</Pages 2 0 R /Type/Catalog>>
|
|
5
|
+
endobj
|
|
6
|
+
2 0 obj
|
|
7
|
+
<</Count 2/Kids[ 4 0 R 8 0 R ]/Type/Pages>>
|
|
8
|
+
endobj
|
|
9
|
+
3 0 obj
|
|
10
|
+
<</CreationDate(D:20210803100643)/Creator(PDFium)/Producer(PDFium)>>
|
|
11
|
+
endobj
|
|
12
|
+
4 0 obj
|
|
13
|
+
<</Contents 5 0 R /MediaBox[ 0 0 612 792]/Parent 2 0 R /Resources<</Font<</F1 6 0 R >>/ProcSet 7 0 R >>/Type/Page>>
|
|
14
|
+
endobj
|
|
15
|
+
5 0 obj
|
|
16
|
+
<</Filter/FlateDecode/Length 311>>stream
|
|
17
|
+
x����j�0����[h������ɡ(��.b�Q��`ɥ��k'$�@�J��;}�β�a�(a�}���EIF�,a�8'.CQ��
|
|
18
|
+
�����Ryz������9s_S�G��V�sNrNy��r���>�d��hv}nr���A;�T�q ��V� �o�/,��
|
|
19
|
+
endstream
|
|
20
|
+
endobj
|
|
21
|
+
6 0 obj
|
|
22
|
+
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Name/F1/Subtype/Type1/Type/Font>>
|
|
23
|
+
endobj
|
|
24
|
+
7 0 obj
|
|
25
|
+
[/PDF/Text]
|
|
26
|
+
endobj
|
|
27
|
+
8 0 obj
|
|
28
|
+
<</Contents 9 0 R /MediaBox[ 0 0 612 792]/Parent 2 0 R /Resources<</Font<</F1 6 0 R >>/ProcSet 7 0 R >>/Type/Page>>
|
|
29
|
+
endobj
|
|
30
|
+
9 0 obj
|
|
31
|
+
<</Filter/FlateDecode/Length 274>>stream
|
|
32
|
+
x����j�0����[X�1��+��Bi�^z�k�,E#v߾YE��"%�̐��f�p��^���e
|
|
33
|
+
V�Z³)n�{�R���&��ۙ�ъ�$7�
|
|
34
|
+
����?ݠM{�#F;�%!�,Lg���%=֗x�7�$#�y�\�b8�����2r3����z�����
|
|
35
|
+
endstream
|
|
36
|
+
endobj
|
|
37
|
+
xref
|
|
38
|
+
0 10
|
|
39
|
+
0000000000 65535 f
|
|
40
|
+
0000000017 00000 n
|
|
41
|
+
0000000066 00000 n
|
|
42
|
+
0000000129 00000 n
|
|
43
|
+
0000000216 00000 n
|
|
44
|
+
0000000350 00000 n
|
|
45
|
+
0000000733 00000 n
|
|
46
|
+
0000000832 00000 n
|
|
47
|
+
0000000862 00000 n
|
|
48
|
+
0000000996 00000 n
|
|
49
|
+
trailer
|
|
50
|
+
<<
|
|
51
|
+
/Root 1 0 R
|
|
52
|
+
/Info 3 0 R
|
|
53
|
+
/Size 10/ID[<06CD5B1232D77C2A68B8A7743652C304><06CD5B1232D77C2A68B8A7743652C304>]>>
|
|
54
|
+
startxref
|
|
55
|
+
1342
|
|
56
|
+
%%EOF
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
include Support::ResourceExamples
|
|
4
|
+
|
|
5
|
+
describe Fulcrum::Attachment do
|
|
6
|
+
let(:test_file) { './spec/data/test.pdf' }
|
|
7
|
+
|
|
8
|
+
include_context 'with client'
|
|
9
|
+
include_context 'with media resource'
|
|
10
|
+
include_context 'with resource parameters'
|
|
11
|
+
|
|
12
|
+
let(:resource) { client.attachments }
|
|
13
|
+
|
|
14
|
+
include_examples 'finds resource'
|
|
15
|
+
include_examples 'deletes resource'
|
|
16
|
+
|
|
17
|
+
let(:create_url) do
|
|
18
|
+
"#{client.url}/#{resource.create_action}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '#all' do
|
|
22
|
+
let(:list_response) do
|
|
23
|
+
data = {}
|
|
24
|
+
data["form_id"] = {}
|
|
25
|
+
data.to_json
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'lists all attachments' do
|
|
29
|
+
stub_request(:get, create_url)
|
|
30
|
+
.to_return(status: 200, body: list_response,
|
|
31
|
+
headers: {"Content-Type" => "application/json"})
|
|
32
|
+
|
|
33
|
+
resources = resource.all
|
|
34
|
+
|
|
35
|
+
expect(client.response.status).to eq(200)
|
|
36
|
+
|
|
37
|
+
expect(resources).to be_a(Hash)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe '#create' do
|
|
42
|
+
let(:ws_url) do
|
|
43
|
+
'https://fulcrumapp.s3.amazonaws.com/attachments/example'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
let(:attrs) do
|
|
47
|
+
{ "name": "Test",
|
|
48
|
+
"owners": [ {
|
|
49
|
+
"type": "form",
|
|
50
|
+
"id": "12345"
|
|
51
|
+
} ] }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let(:response) do
|
|
55
|
+
data = {}
|
|
56
|
+
data['url'] = ws_url
|
|
57
|
+
data['id'] = "123"
|
|
58
|
+
data.to_json
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
let(:create_parameters) { [ File.open(test_file) , attrs ] }
|
|
62
|
+
|
|
63
|
+
it 'creates attachment data' do
|
|
64
|
+
stub_request(:post, create_url)
|
|
65
|
+
.with(body: attrs)
|
|
66
|
+
.to_return(status: 200, body: response,
|
|
67
|
+
headers: {"Content-Type" => "application/json"})
|
|
68
|
+
stub_request(:put, ws_url)
|
|
69
|
+
.to_return(status: 200,
|
|
70
|
+
headers: {"Content-Type" => "application/json"})
|
|
71
|
+
|
|
72
|
+
object = resource.create(*create_parameters)
|
|
73
|
+
|
|
74
|
+
expect(client.response.status).to eq(200)
|
|
75
|
+
|
|
76
|
+
expect(object[:name]).to eq(attrs[:name])
|
|
77
|
+
|
|
78
|
+
expect(object[:attachment_id]).to eq(JSON.parse(response)['id'])
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#finalize' do
|
|
83
|
+
it 'finalizes the attachment' do
|
|
84
|
+
stub_request(:post, "#{create_url}/finalize")
|
|
85
|
+
.to_return(status: 201,
|
|
86
|
+
headers: {"Content-Type" => "application/json"})
|
|
87
|
+
|
|
88
|
+
object = resource.finalize(resource_id)
|
|
89
|
+
|
|
90
|
+
expect(client.response.status).to eq(201)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
metadata
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fulcrum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fulcrum
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '10.4'
|
|
20
17
|
- - ">="
|
|
21
18
|
- !ruby/object:Gem::Version
|
|
22
|
-
version:
|
|
19
|
+
version: 12.3.3
|
|
23
20
|
type: :development
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
|
-
- - "~>"
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: '10.4'
|
|
30
24
|
- - ">="
|
|
31
25
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
26
|
+
version: 12.3.3
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: rspec
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -147,6 +141,7 @@ files:
|
|
|
147
141
|
- lib/fulcrum/actions/list.rb
|
|
148
142
|
- lib/fulcrum/actions/media_versions.rb
|
|
149
143
|
- lib/fulcrum/actions/update.rb
|
|
144
|
+
- lib/fulcrum/attachment.rb
|
|
150
145
|
- lib/fulcrum/audio.rb
|
|
151
146
|
- lib/fulcrum/audit_log.rb
|
|
152
147
|
- lib/fulcrum/authorization.rb
|
|
@@ -172,7 +167,9 @@ files:
|
|
|
172
167
|
- spec/data/test.jpg
|
|
173
168
|
- spec/data/test.m4a
|
|
174
169
|
- spec/data/test.mp4
|
|
170
|
+
- spec/data/test.pdf
|
|
175
171
|
- spec/data/test.png
|
|
172
|
+
- spec/lib/attachment_spec.rb
|
|
176
173
|
- spec/lib/audio_spec.rb
|
|
177
174
|
- spec/lib/audit_log_spec.rb
|
|
178
175
|
- spec/lib/authorization_spec.rb
|
|
@@ -195,7 +192,7 @@ homepage: https://github.com/fulcrumapp/fulcrum-ruby
|
|
|
195
192
|
licenses:
|
|
196
193
|
- MIT
|
|
197
194
|
metadata: {}
|
|
198
|
-
post_install_message:
|
|
195
|
+
post_install_message:
|
|
199
196
|
rdoc_options: []
|
|
200
197
|
require_paths:
|
|
201
198
|
- lib
|
|
@@ -210,9 +207,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
210
207
|
- !ruby/object:Gem::Version
|
|
211
208
|
version: '0'
|
|
212
209
|
requirements: []
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
signing_key:
|
|
210
|
+
rubygems_version: 3.2.22
|
|
211
|
+
signing_key:
|
|
216
212
|
specification_version: 4
|
|
217
213
|
summary: Fulcrum API client for ruby
|
|
218
214
|
test_files:
|
|
@@ -220,7 +216,9 @@ test_files:
|
|
|
220
216
|
- spec/data/test.jpg
|
|
221
217
|
- spec/data/test.m4a
|
|
222
218
|
- spec/data/test.mp4
|
|
219
|
+
- spec/data/test.pdf
|
|
223
220
|
- spec/data/test.png
|
|
221
|
+
- spec/lib/attachment_spec.rb
|
|
224
222
|
- spec/lib/audio_spec.rb
|
|
225
223
|
- spec/lib/audit_log_spec.rb
|
|
226
224
|
- spec/lib/authorization_spec.rb
|