dina 3.2.0.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: b352cf3c52493540a1f8089e292d1eb5a24e178330796c9d8548ea2fd04a555e
4
- data.tar.gz: 592c57a9d91d6853b5ebf4bf10502f316a31f40c660e9525c83f6f31ab6ec8a4
3
+ metadata.gz: 2eda00f62a4b5a9ef520e5c2ed2a253861a9ce38d1d43f96989d87ca170ffc91
4
+ data.tar.gz: ac9c14b964f24f478cf52bb5157b0c0b70102573dc234c821c56717d0ba52470
5
5
  SHA512:
6
- metadata.gz: 42f07765799ef8bfdf9d04b01b2fea2623f41ded4298e42ab7e53996ba8ed4d30d625c2a23160b4bab7cfe9e63c16498ad04d54d0d7428d4be907489a8a9405c
7
- data.tar.gz: 72d908349ce9f90f07f52135fe44fcb2f2f960bc87cd2acb1f81233508bac9206593568a0a0adf2534586995b0386bfb6dcb79ad6547714c1ac35441a0b9f3c6
6
+ metadata.gz: f1417c9d2bbdc048d03173d7fd6f11fc0a373ef072dcf2e921c41befbc31459904a55537f8a28a0f7388ff5735d035cc3199486a7b115cb23660ad8737c3bffe
7
+ data.tar.gz: 928d1b4c29320ae094a69156c3637b2791acd81ab39b019571ad3aa75ea94e56b865d36c40831bf636266ccb5622ce4fe9ac384f7663e8712fa525b58d4880dd
@@ -1,9 +1,11 @@
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
7
9
 
8
10
  custom_endpoint :download, on: :collection, request_method: :get
9
11
 
@@ -23,8 +23,18 @@ module Dina
23
23
  path = "file" + "/#{params[:group]}/derivative/#{params[:fileId]}"
24
24
  end
25
25
  headers[:content_type] = "application/octet-stream"
26
+
27
+
26
28
  response = @faraday.run_request(request_method, path, body, headers) do |request|
27
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
+ }
28
38
  response
29
39
  else
30
40
  path = path + "/#{body[:data]["attributes"]["group"].downcase}"
@@ -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
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 3
5
5
  MINOR = 2
6
- PATCH = 0
6
+ PATCH = 1
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
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.2.0.0
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: 2025-03-24 00:00:00.000000000 Z
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