dina 3.1.3.0 → 3.2.1.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2eda00f62a4b5a9ef520e5c2ed2a253861a9ce38d1d43f96989d87ca170ffc91
|
|
4
|
+
data.tar.gz: ac9c14b964f24f478cf52bb5157b0c0b70102573dc234c821c56717d0ba52470
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1417c9d2bbdc048d03173d7fd6f11fc0a373ef072dcf2e921c41befbc31459904a55537f8a28a0f7388ff5735d035cc3199486a7b115cb23660ad8737c3bffe
|
|
7
|
+
data.tar.gz: 928d1b4c29320ae094a69156c3637b2791acd81ab39b019571ad3aa75ea94e56b865d36c40831bf636266ccb5622ce4fe9ac384f7663e8712fa525b58d4880dd
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
require_rel '../base_model'
|
|
2
2
|
require_rel 'file_connection'
|
|
3
|
+
require_rel 'file_parser'
|
|
3
4
|
|
|
4
5
|
module Dina
|
|
5
6
|
class File < BaseModel
|
|
6
7
|
self.connection_class = FileConnection
|
|
8
|
+
self.parser = FileParser
|
|
9
|
+
|
|
10
|
+
custom_endpoint :download, on: :collection, request_method: :get
|
|
7
11
|
|
|
8
12
|
property :id, type: :string, default: SecureRandom.uuid_v7
|
|
9
13
|
property :group, type: :string
|
|
@@ -17,33 +17,54 @@ module Dina
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def run(request_method, path, params: nil, headers: {}, body: nil)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
body[:file] = Faraday::Multipart::FilePart.new(
|
|
29
|
-
file_path,
|
|
30
|
-
mime_type,
|
|
31
|
-
file_name
|
|
32
|
-
)
|
|
20
|
+
if request_method == :get && path == "file/download"
|
|
21
|
+
path = "file" + "/#{params[:group]}/#{params[:fileId]}"
|
|
22
|
+
if params[:isDerivative]
|
|
23
|
+
path = "file" + "/#{params[:group]}/derivative/#{params[:fileId]}"
|
|
24
|
+
end
|
|
25
|
+
headers[:content_type] = "application/octet-stream"
|
|
26
|
+
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
response = @faraday.run_request(request_method, path, body, headers) do |request|
|
|
29
|
+
end
|
|
30
|
+
response.body["meta"] = {}
|
|
31
|
+
response.body["errors"] = []
|
|
32
|
+
response.body["data"] = {
|
|
33
|
+
"id" => params[:fileId],
|
|
34
|
+
"type" => "file",
|
|
35
|
+
"relationships" => {},
|
|
36
|
+
"attributes" => response.headers
|
|
37
|
+
}
|
|
38
|
+
response
|
|
39
|
+
else
|
|
40
|
+
path = path + "/#{body[:data]["attributes"]["group"].downcase}"
|
|
41
|
+
if body[:data]["attributes"].key?("isDerivative")
|
|
42
|
+
path = path + "/derivative"
|
|
43
|
+
end
|
|
44
|
+
file_path = body[:data]["attributes"]["filePath"]
|
|
45
|
+
mime_type = body[:data]["attributes"]["dcFormat"]
|
|
46
|
+
file_name = body[:data]["attributes"]["fileName"]
|
|
47
|
+
|
|
48
|
+
body[:file] = Faraday::Multipart::FilePart.new(
|
|
49
|
+
file_path,
|
|
50
|
+
mime_type,
|
|
51
|
+
file_name
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
response = @faraday.run_request(request_method, path, body, headers) do |request|
|
|
55
|
+
request.params.update(params) if params
|
|
56
|
+
end
|
|
57
|
+
attributes = response.body.dup
|
|
58
|
+
response.body["meta"] = {}
|
|
59
|
+
response.body["errors"] = []
|
|
60
|
+
response.body["data"] = {
|
|
61
|
+
"id" => attributes["uuid"],
|
|
62
|
+
"type" => "file",
|
|
63
|
+
"relationships" => {},
|
|
64
|
+
"attributes" => attributes
|
|
65
|
+
}
|
|
66
|
+
response
|
|
36
67
|
end
|
|
37
|
-
attributes = response.body.dup
|
|
38
|
-
response.body["meta"] = {}
|
|
39
|
-
response.body["errors"] = []
|
|
40
|
-
response.body["data"] = {
|
|
41
|
-
"id" => attributes["uuid"],
|
|
42
|
-
"type" => "file",
|
|
43
|
-
"relationships" => {},
|
|
44
|
-
"attributes" => attributes
|
|
45
|
-
}
|
|
46
|
-
response
|
|
47
68
|
end
|
|
48
69
|
|
|
49
70
|
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require_rel '../base_model'
|
|
2
|
+
|
|
3
|
+
module Dina
|
|
4
|
+
class FileParser
|
|
5
|
+
class << self
|
|
6
|
+
def parse(klass, response)
|
|
7
|
+
data = response.body.present? ? response.body : {}
|
|
8
|
+
|
|
9
|
+
return data if !data.respond_to?(:fetch)
|
|
10
|
+
|
|
11
|
+
::JsonApiClient::ResultSet.new.tap do |result_set|
|
|
12
|
+
result_set.record_class = klass
|
|
13
|
+
result_set.uri = response.env[:url]
|
|
14
|
+
handle_json_api(result_set, data)
|
|
15
|
+
handle_data(result_set, data)
|
|
16
|
+
handle_errors(result_set, data)
|
|
17
|
+
handle_meta(result_set, data)
|
|
18
|
+
handle_links(result_set, data)
|
|
19
|
+
handle_relationships(result_set, data)
|
|
20
|
+
handle_pagination(result_set, data)
|
|
21
|
+
handle_included(result_set, data)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
# Given a resource hash, returns a Resource.new friendly hash
|
|
27
|
+
# which flattens the attributes in w/ id and type.
|
|
28
|
+
#
|
|
29
|
+
# Example:
|
|
30
|
+
#
|
|
31
|
+
# Given:
|
|
32
|
+
# {
|
|
33
|
+
# id: 1.
|
|
34
|
+
# type: 'person',
|
|
35
|
+
# attributes: {
|
|
36
|
+
# first_name: 'Jeff',
|
|
37
|
+
# last_name: 'Ching'
|
|
38
|
+
# },
|
|
39
|
+
# links: {...},
|
|
40
|
+
# relationships: {...}
|
|
41
|
+
# }
|
|
42
|
+
#
|
|
43
|
+
# Returns:
|
|
44
|
+
# {
|
|
45
|
+
# id: 1,
|
|
46
|
+
# type: 'person',
|
|
47
|
+
# first_name: 'Jeff',
|
|
48
|
+
# last_name: 'Ching'
|
|
49
|
+
# links: {...},
|
|
50
|
+
# relationships: {...}
|
|
51
|
+
# }
|
|
52
|
+
#
|
|
53
|
+
#
|
|
54
|
+
def parameters_from_resource(params)
|
|
55
|
+
attrs = params.slice('id', 'links', 'meta', 'type', 'relationships')
|
|
56
|
+
attrs.merge(params.fetch('attributes', {}))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def handle_json_api(result_set, data)
|
|
62
|
+
result_set.implementation = ::JsonApiClient::Implementation.new(data.fetch("jsonapi", {}))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def handle_data(result_set, data)
|
|
66
|
+
# all data lives under the "data" attribute
|
|
67
|
+
results = data.fetch("data", [])
|
|
68
|
+
|
|
69
|
+
# we will treat everything as an Array
|
|
70
|
+
results = [results] unless results.is_a?(Array)
|
|
71
|
+
resources = results.compact.map do |res|
|
|
72
|
+
resource = result_set.record_class.load(parameters_from_resource(res))
|
|
73
|
+
resource.last_result_set = result_set
|
|
74
|
+
resource
|
|
75
|
+
end
|
|
76
|
+
result_set.concat(resources)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def handle_errors(result_set, data)
|
|
80
|
+
result_set.errors = ErrorCollector.new(data.fetch("errors", []))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def handle_meta(result_set, data)
|
|
84
|
+
result_set.meta = MetaData.new(data.fetch("meta", {}), result_set.record_class)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def handle_links(result_set, data)
|
|
88
|
+
result_set.links = Linking::TopLevelLinks.new(result_set.record_class, data.fetch("links", {}))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def handle_relationships(result_set, data)
|
|
92
|
+
result_set.relationships = Relationships::TopLevelRelations.new(result_set.record_class, data.fetch("relationships", {}))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def handle_pagination(result_set, data)
|
|
96
|
+
result_set.pages = result_set.record_class.paginator.new(result_set, data)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def handle_included(result_set, data)
|
|
100
|
+
result_set.included = IncludedData.new(result_set, data.fetch("included", []))
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
data/lib/dina/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dina
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.
|
|
4
|
+
version: 3.2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David P. Shorthouse
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2025-03-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json_api_client
|
|
@@ -188,6 +188,7 @@ files:
|
|
|
188
188
|
- lib/dina/models/object_store/derivative.rb
|
|
189
189
|
- lib/dina/models/object_store/file.rb
|
|
190
190
|
- lib/dina/models/object_store/file_connection.rb
|
|
191
|
+
- lib/dina/models/object_store/file_parser.rb
|
|
191
192
|
- lib/dina/models/object_store/object_store.rb
|
|
192
193
|
- lib/dina/models/object_store/object_store_managed_attribute.rb
|
|
193
194
|
- lib/dina/models/object_store/object_subtype.rb
|
|
@@ -230,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
230
231
|
requirements:
|
|
231
232
|
- - ">="
|
|
232
233
|
- !ruby/object:Gem::Version
|
|
233
|
-
version: '3.
|
|
234
|
+
version: '3.1'
|
|
234
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
236
|
requirements:
|
|
236
237
|
- - ">="
|