apia 3.6.0 → 3.7.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/definitions/endpoint.rb +2 -0
- data/lib/apia/dsls/endpoint.rb +4 -0
- data/lib/apia/rack.rb +2 -2
- data/lib/apia/response.rb +6 -7
- data/lib/apia/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3488b6d92d65ff71eff5ec22b944622042981311d6a7505fc09578093a9e4402
|
4
|
+
data.tar.gz: aff3ff29a9674a4eb622e91a89e74d380e11728e683407e3e9bc1546641ea483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 749d596efa11efc2965952a4ae2fc6af4c62fb9189e1839675ca3e00040fb4c4a99ab888d2e1589b546b002434e019735c1896398d494404d8cc7bd8a7e6f944
|
7
|
+
data.tar.gz: 682ff1cf40fe2399ae2754ef9e78388282cfe8c28b38b7153425565ab568084826d7d49fccdbaf5a539e80bd4b4cfa79e1b968258ebb5e23525f14b4d3051c58
|
@@ -14,6 +14,7 @@ module Apia
|
|
14
14
|
attr_accessor :authenticator
|
15
15
|
attr_accessor :action
|
16
16
|
attr_accessor :http_status
|
17
|
+
attr_accessor :response_type
|
17
18
|
attr_accessor :paginated_field
|
18
19
|
attr_reader :fields
|
19
20
|
attr_reader :scopes
|
@@ -21,6 +22,7 @@ module Apia
|
|
21
22
|
def setup
|
22
23
|
@fields = FieldSet.new
|
23
24
|
@http_status = 200
|
25
|
+
@response_type = Apia::Response::JSON
|
24
26
|
@scopes = []
|
25
27
|
end
|
26
28
|
|
data/lib/apia/dsls/endpoint.rb
CHANGED
@@ -40,6 +40,10 @@ module Apia
|
|
40
40
|
@definition.http_status = status
|
41
41
|
end
|
42
42
|
|
43
|
+
def response_type(type)
|
44
|
+
@definition.response_type = type
|
45
|
+
end
|
46
|
+
|
43
47
|
def field(name, *args, type: nil, **options, &block)
|
44
48
|
if @definition.fields_overriden?
|
45
49
|
raise Apia::StandardError, 'Cannot add fields to an endpoint that has a separate fieldset'
|
data/lib/apia/rack.rb
CHANGED
@@ -159,7 +159,7 @@ module Apia
|
|
159
159
|
# @param headers [Hash]
|
160
160
|
# @return [Array]
|
161
161
|
def plain_triplet(body, status: 200, headers: {})
|
162
|
-
response_triplet(body, content_type:
|
162
|
+
response_triplet(body, content_type: Apia::Response::PLAIN, status: status, headers: headers)
|
163
163
|
end
|
164
164
|
|
165
165
|
# Return a JSON-ready triplet for the given body.
|
@@ -169,7 +169,7 @@ module Apia
|
|
169
169
|
# @param headers [Hash]
|
170
170
|
# @return [Array]
|
171
171
|
def json_triplet(body, status: 200, headers: {})
|
172
|
-
response_triplet(body.to_json, content_type:
|
172
|
+
response_triplet(body.to_json, content_type: Apia::Response::JSON, status: status, headers: headers)
|
173
173
|
end
|
174
174
|
|
175
175
|
# Return a triplet for the given body.
|
data/lib/apia/response.rb
CHANGED
@@ -7,8 +7,8 @@ module Apia
|
|
7
7
|
class Response
|
8
8
|
|
9
9
|
TYPES = [
|
10
|
-
JSON =
|
11
|
-
PLAIN =
|
10
|
+
JSON = 'application/json',
|
11
|
+
PLAIN = 'text/plain'
|
12
12
|
].freeze
|
13
13
|
|
14
14
|
attr_accessor :status
|
@@ -21,11 +21,14 @@ module Apia
|
|
21
21
|
@endpoint = endpoint
|
22
22
|
|
23
23
|
@status = @endpoint.definition.http_status_code
|
24
|
+
@type = @endpoint.definition.response_type
|
24
25
|
@fields = {}
|
25
26
|
@headers = {}
|
26
27
|
end
|
27
28
|
|
28
29
|
def plain_text_body(body)
|
30
|
+
warn '[DEPRECATION] `plain_text_body` is deprecated. Please set use `response_type` in the endpoint definition, and set the response `body` directly instead.'
|
31
|
+
|
29
32
|
@type = PLAIN
|
30
33
|
@body = body
|
31
34
|
end
|
@@ -63,15 +66,11 @@ module Apia
|
|
63
66
|
@body || hash
|
64
67
|
end
|
65
68
|
|
66
|
-
def type
|
67
|
-
@type || JSON
|
68
|
-
end
|
69
|
-
|
70
69
|
# Return the rack triplet for this response
|
71
70
|
#
|
72
71
|
# @return [Array]
|
73
72
|
def rack_triplet
|
74
|
-
case type
|
73
|
+
case @type
|
75
74
|
when JSON
|
76
75
|
Rack.json_triplet(body, headers: headers, status: status)
|
77
76
|
when PLAIN
|
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.7.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: 2024-
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
rubygems_version: 3.3.
|
188
|
+
rubygems_version: 3.3.27
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: This gem provides a friendly DSL for constructing HTTP APIs.
|