apia 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d20a8612da20a33fb3df02632c88c71be48a6bb8741e599257526eb95b8fab8
4
- data.tar.gz: 62b60c3afadb025f22d460bfed84c6fcbae83a9189a51c39d00d4eedde94c72a
3
+ metadata.gz: 3488b6d92d65ff71eff5ec22b944622042981311d6a7505fc09578093a9e4402
4
+ data.tar.gz: aff3ff29a9674a4eb622e91a89e74d380e11728e683407e3e9bc1546641ea483
5
5
  SHA512:
6
- metadata.gz: 861c7382e3a4b0d2f14af9e20379b14338b7aa4acf93e3c0b3ebda438d8c010d371a1c9e088caa1cc321d22261e201d994acc6346a20948f14b10a6edef8fe18
7
- data.tar.gz: 8c8b32ca974212bfaf1df295cd59b3154ef92f810385b772e57b75dced6b0de2cc31d9214382152c255ad06debe40652374c2d94d56d02c1fc5792c5fcd469f4
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
 
@@ -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: 'text/plain', status: status, headers: headers)
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: 'application/json', status: status, headers: headers)
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 = :json,
11
- PLAIN = :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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apia
4
4
 
5
- VERSION = '3.6.0'
5
+ VERSION = '3.7.0'
6
6
 
7
7
  end
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.6.0
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-04-17 00:00:00.000000000 Z
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.26
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.