apia 3.5.1 → 3.6.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 +4 -4
- data/lib/apia/rack.rb +26 -3
- data/lib/apia/response.rb +20 -1
- data/lib/apia/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d20a8612da20a33fb3df02632c88c71be48a6bb8741e599257526eb95b8fab8
|
4
|
+
data.tar.gz: 62b60c3afadb025f22d460bfed84c6fcbae83a9189a51c39d00d4eedde94c72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861c7382e3a4b0d2f14af9e20379b14338b7aa4acf93e3c0b3ebda438d8c010d371a1c9e088caa1cc321d22261e201d994acc6346a20948f14b10a6edef8fe18
|
7
|
+
data.tar.gz: 8c8b32ca974212bfaf1df295cd59b3154ef92f810385b772e57b75dced6b0de2cc31d9214382152c255ad06debe40652374c2d94d56d02c1fc5792c5fcd469f4
|
data/lib/apia/rack.rb
CHANGED
@@ -152,6 +152,16 @@ module Apia
|
|
152
152
|
|
153
153
|
class << self
|
154
154
|
|
155
|
+
# Return a plain text triplet for the given body.
|
156
|
+
#
|
157
|
+
# @param body [String]
|
158
|
+
# @param status [Integer]
|
159
|
+
# @param headers [Hash]
|
160
|
+
# @return [Array]
|
161
|
+
def plain_triplet(body, status: 200, headers: {})
|
162
|
+
response_triplet(body, content_type: 'text/plain', status: status, headers: headers)
|
163
|
+
end
|
164
|
+
|
155
165
|
# Return a JSON-ready triplet for the given body.
|
156
166
|
#
|
157
167
|
# @param body [Hash, Array]
|
@@ -159,11 +169,24 @@ module Apia
|
|
159
169
|
# @param headers [Hash]
|
160
170
|
# @return [Array]
|
161
171
|
def json_triplet(body, status: 200, headers: {})
|
162
|
-
|
172
|
+
response_triplet(body.to_json, content_type: 'application/json', status: status, headers: headers)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Return a triplet for the given body.
|
176
|
+
#
|
177
|
+
# @param body [Hash, Array]
|
178
|
+
# @param content_type [String]
|
179
|
+
# @param status [Integer]
|
180
|
+
# @param headers [Hash]
|
181
|
+
# @return [Array]
|
182
|
+
def response_triplet(body, content_type:, status: 200, headers: {})
|
183
|
+
content_length = body.bytesize.to_s
|
184
|
+
body = [body] unless body.respond_to?(:each)
|
185
|
+
|
163
186
|
[
|
164
187
|
status,
|
165
|
-
headers.merge('content-type' =>
|
166
|
-
|
188
|
+
headers.merge('content-type' => content_type, 'content-length' => content_length),
|
189
|
+
body
|
167
190
|
]
|
168
191
|
end
|
169
192
|
|
data/lib/apia/response.rb
CHANGED
@@ -6,6 +6,11 @@ require 'apia/rack'
|
|
6
6
|
module Apia
|
7
7
|
class Response
|
8
8
|
|
9
|
+
TYPES = [
|
10
|
+
JSON = :json,
|
11
|
+
PLAIN = :plain
|
12
|
+
].freeze
|
13
|
+
|
9
14
|
attr_accessor :status
|
10
15
|
attr_reader :fields
|
11
16
|
attr_reader :headers
|
@@ -20,6 +25,11 @@ module Apia
|
|
20
25
|
@headers = {}
|
21
26
|
end
|
22
27
|
|
28
|
+
def plain_text_body(body)
|
29
|
+
@type = PLAIN
|
30
|
+
@body = body
|
31
|
+
end
|
32
|
+
|
23
33
|
# Add a field value for this endpoint
|
24
34
|
#
|
25
35
|
# @param name [Symbol]
|
@@ -53,11 +63,20 @@ module Apia
|
|
53
63
|
@body || hash
|
54
64
|
end
|
55
65
|
|
66
|
+
def type
|
67
|
+
@type || JSON
|
68
|
+
end
|
69
|
+
|
56
70
|
# Return the rack triplet for this response
|
57
71
|
#
|
58
72
|
# @return [Array]
|
59
73
|
def rack_triplet
|
60
|
-
|
74
|
+
case type
|
75
|
+
when JSON
|
76
|
+
Rack.json_triplet(body, headers: headers, status: status)
|
77
|
+
when PLAIN
|
78
|
+
Rack.plain_triplet(body, headers: headers, status: status)
|
79
|
+
end
|
61
80
|
end
|
62
81
|
|
63
82
|
end
|
data/lib/apia/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|