reynard 0.0.6 → 0.0.7
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/reynard/context.rb +17 -0
- data/lib/reynard/specification.rb +4 -1
- data/lib/reynard/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 464bcfde66e61c85b7dd949995fc3acd2db91048b80828bb4c8161c1bd5170d8
|
4
|
+
data.tar.gz: e219398e59d21c45e42ece44f1cadcbdb6c0ef4b5a5927cb627bafa249138b6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3fb63f88b99b653541e92e948ba5e8cadb6edbbdb45bf6d939452d98663b7d40bf9782f5cb816665d847a0c807777e3604fef279430e30025e0228600c280e9
|
7
|
+
data.tar.gz: 616c0ad91e77e8d69fa66d48000079cfc530563f276e85c4bdca96a83f17e9a273a8f88ff5d8d2b5bef60160d1241263f30a83fb3be2ff065ef87974d997fadd
|
data/lib/reynard/context.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'ostruct'
|
4
|
+
|
3
5
|
class Reynard
|
4
6
|
# Exposes a public interface to build a request context.
|
5
7
|
class Context
|
@@ -67,11 +69,26 @@ class Reynard
|
|
67
69
|
http_response.code,
|
68
70
|
http_response.content_type
|
69
71
|
)
|
72
|
+
if media_type
|
73
|
+
build_object_with_media_type(http_response, media_type)
|
74
|
+
else
|
75
|
+
build_object_without_media_type(http_response)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_object_with_media_type(http_response, media_type)
|
70
80
|
ObjectBuilder.new(
|
71
81
|
media_type: media_type,
|
72
82
|
schema: @specification.schema(media_type.node),
|
73
83
|
http_response: http_response
|
74
84
|
).call
|
75
85
|
end
|
86
|
+
|
87
|
+
def build_object_without_media_type(http_response)
|
88
|
+
# Try to parse the response as JSON and give up otherwise.
|
89
|
+
OpenStruct.new(MultiJson.load(http_response.body))
|
90
|
+
rescue StandardError
|
91
|
+
http_response.body
|
92
|
+
end
|
76
93
|
end
|
77
94
|
end
|
@@ -61,7 +61,10 @@ class Reynard
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def media_type_response(responses, response_code, media_type)
|
64
|
-
responses.dig(response_code, 'content')
|
64
|
+
defined_responses = responses.dig(response_code, 'content')
|
65
|
+
return unless defined_responses&.any?
|
66
|
+
|
67
|
+
defined_responses.each do |expression, response|
|
65
68
|
return response, expression if self.class.media_type_matches?(media_type, expression)
|
66
69
|
end
|
67
70
|
nil
|
data/lib/reynard/version.rb
CHANGED