lutaml-hal 0.2.6 → 0.2.8
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 +4 -4
- data/lib/lutaml/hal/client.rb +34 -6
- data/lib/lutaml/hal/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52d9c041e59d984d0e6711728d2194dfc207d3e3811b3319154ac815c63eff44
|
|
4
|
+
data.tar.gz: 436627f70c40d535fefe318820ddfda1ed8f702fc6c950a9612ffa93d06bbdca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93e81bc49269ec14fea673492e62e83b504eb7c5222e917a7fd5f42d284fc6ddc3601502d5574e12a93bcbad418361a906cbe81b5d7bd9ca1005f52961c856a9
|
|
7
|
+
data.tar.gz: b8477baf0a40a9ff6d34df9e3f9c056b6e0b075c1832abfefe216943147c2b5235acb543bb0c501655221f3b7863063ecb34742feb64aeab341bd89b87b9018f
|
data/lib/lutaml/hal/client.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'faraday'
|
|
4
4
|
require 'faraday/follow_redirects'
|
|
5
|
-
require '
|
|
5
|
+
require 'yeptris'
|
|
6
6
|
require 'rainbow'
|
|
7
7
|
|
|
8
8
|
module Lutaml
|
|
@@ -59,7 +59,9 @@ module Lutaml
|
|
|
59
59
|
def get(url, params = {})
|
|
60
60
|
with_faraday_errors do
|
|
61
61
|
@rate_limiter.with_rate_limiting do
|
|
62
|
-
|
|
62
|
+
response = @connection.get(url, params)
|
|
63
|
+
parse_json_body(response)
|
|
64
|
+
handle_response(record_response(response), url)
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
end
|
|
@@ -70,6 +72,7 @@ module Lutaml
|
|
|
70
72
|
response = @connection.get(url) do |req|
|
|
71
73
|
headers.each { |key, value| req.headers[key] = value }
|
|
72
74
|
end
|
|
75
|
+
parse_json_body(response)
|
|
73
76
|
handle_response(record_response(response), url)
|
|
74
77
|
end
|
|
75
78
|
end
|
|
@@ -100,12 +103,37 @@ module Lutaml
|
|
|
100
103
|
def create_connection
|
|
101
104
|
Faraday.new(url: @api_url) do |conn|
|
|
102
105
|
conn.use Faraday::FollowRedirects::Middleware
|
|
103
|
-
conn.request :json
|
|
104
|
-
conn.response :json, content_type: /\bjson$/
|
|
105
106
|
conn.adapter Faraday.default_adapter
|
|
106
107
|
end
|
|
107
108
|
end
|
|
108
109
|
|
|
110
|
+
# The Faraday `response :json` middleware is deliberately not installed:
|
|
111
|
+
# it parses with `::JSON.parse(body, @parser_options || {})` — a
|
|
112
|
+
# positional options hash json 3.0 rejects — which used to force a
|
|
113
|
+
# json < 3 pin on every dependent bundle. JSON bodies are parsed here,
|
|
114
|
+
# with yeptris, under the same content-type matcher the middleware
|
|
115
|
+
# used, so the parsed/unparsed split does not move.
|
|
116
|
+
def parse_json_body(response)
|
|
117
|
+
# Only String bodies are parsed — the middleware this replaces parsed
|
|
118
|
+
# nothing else (a Hash body arrives already materialized, as from a
|
|
119
|
+
# Faraday test adapter).
|
|
120
|
+
return response unless response.body.is_a?(String)
|
|
121
|
+
|
|
122
|
+
# The matcher applies to the bare type: parameters split off before
|
|
123
|
+
# it, exactly as the middleware did
|
|
124
|
+
# ("application/hal+json;version=1.0" parses).
|
|
125
|
+
content_type = response.headers['Content-Type'].to_s.split(';', 2).first.to_s
|
|
126
|
+
return response unless content_type.match?(/\bjson$/)
|
|
127
|
+
|
|
128
|
+
# Faraday::Response exposes body read-only; env is where the
|
|
129
|
+
# middleware itself wrote it, so the parsed value stays visible to
|
|
130
|
+
# #last_response consumers exactly as it was under the middleware.
|
|
131
|
+
response.env.body = Yeptris::JSON.load(response.body)
|
|
132
|
+
response
|
|
133
|
+
rescue Yeptris::JSON::ParseError => e
|
|
134
|
+
raise ParsingError, "Response parsing error: #{e.message}"
|
|
135
|
+
end
|
|
136
|
+
|
|
109
137
|
def handle_response(response, url)
|
|
110
138
|
debug_api_log(response, url) if @debug
|
|
111
139
|
|
|
@@ -147,11 +175,11 @@ module Lutaml
|
|
|
147
175
|
|
|
148
176
|
puts "\nHeaders:"
|
|
149
177
|
headers_hash = response.headers.to_h
|
|
150
|
-
puts JSON.
|
|
178
|
+
puts Yeptris::JSON.dump(headers_hash, pretty: true)
|
|
151
179
|
|
|
152
180
|
puts "\nResponse body:"
|
|
153
181
|
if response.body.is_a?(Hash) || response.body.is_a?(Array)
|
|
154
|
-
puts JSON.
|
|
182
|
+
puts Yeptris::JSON.dump(response.body, pretty: true)
|
|
155
183
|
else
|
|
156
184
|
puts response.body.inspect
|
|
157
185
|
end
|
data/lib/lutaml/hal/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-hal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -42,16 +42,16 @@ dependencies:
|
|
|
42
42
|
name: lutaml-model
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
47
|
+
version: 0.8.114
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
54
|
+
version: 0.8.114
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: lutaml-store
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: yeptris
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
83
97
|
description: Hypertext Application Language (HAL) implementation for Lutaml model
|
|
84
98
|
email:
|
|
85
99
|
- open.source@ribose.com
|