respondo 2.1.0 → 2.1.2
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/CHANGELOG.md +168 -0
- data/README.md +267 -712
- data/lib/generators/respondo/install/install_generator.rb +3 -1
- data/lib/respondo/controller_helpers.rb +54 -54
- data/lib/respondo/response_builder.rb +1 -23
- data/lib/respondo/version.rb +1 -1
- data/respondo.gemspec +1 -1
- metadata +3 -3
|
@@ -187,7 +187,9 @@ module Respondo
|
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
def build_content
|
|
190
|
-
meta = { "api_version" => @cfg[:api_version] }.merge(@cfg[:default_meta])
|
|
190
|
+
# meta = { "api_version" => @cfg[:api_version] }.merge(@cfg[:default_meta])
|
|
191
|
+
meta = @cfg[:default_meta].dup
|
|
192
|
+
meta["api_version"] = @cfg[:api_version] unless @cfg[:api_version].to_s.empty?
|
|
191
193
|
b = Lines.new
|
|
192
194
|
|
|
193
195
|
b << "# frozen_string_literal: true"
|
|
@@ -39,59 +39,6 @@ module Respondo
|
|
|
39
39
|
# render_network_authentication_required
|
|
40
40
|
module ControllerHelpers
|
|
41
41
|
|
|
42
|
-
# =========================================================================
|
|
43
|
-
# Core DSL — all helpers delegate to these two
|
|
44
|
-
# =========================================================================
|
|
45
|
-
|
|
46
|
-
# Render a successful JSON response.
|
|
47
|
-
#
|
|
48
|
-
# @param data [Object] payload — AR model, collection, Hash, Array, nil
|
|
49
|
-
# @param message [String] human-readable description
|
|
50
|
-
# @param meta [Hash] extra meta fields merged into the meta block
|
|
51
|
-
# @param pagination [Hash, nil] pagination hash built by the caller, e.g.
|
|
52
|
-
# { current_page: 1, per_page: 25, total_pages: 4,
|
|
53
|
-
# total_count: 100, next_page: 2, prev_page: nil }
|
|
54
|
-
# Pass nil (default) to omit pagination from meta.
|
|
55
|
-
# @param status [Symbol, Integer] HTTP status (default: :ok / 200)
|
|
56
|
-
def render_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok)
|
|
57
|
-
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
58
|
-
|
|
59
|
-
payload = ResponseBuilder.new(
|
|
60
|
-
success: true,
|
|
61
|
-
data: data,
|
|
62
|
-
message: message,
|
|
63
|
-
meta: merged_meta,
|
|
64
|
-
pagination: pagination,
|
|
65
|
-
request: try(:request)
|
|
66
|
-
).build
|
|
67
|
-
|
|
68
|
-
render json: payload, status: status
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Render an error JSON response.
|
|
72
|
-
#
|
|
73
|
-
# @param message [String] human-readable error description
|
|
74
|
-
# @param errors [Hash, ActiveModel::Errors] field-level validation errors
|
|
75
|
-
# @param code [String, nil] machine-readable error code e.g. "AUTH_EXPIRED"
|
|
76
|
-
# @param meta [Hash] extra meta fields
|
|
77
|
-
# @param status [Symbol, Integer] HTTP status (default: :unprocessable_entity / 422)
|
|
78
|
-
|
|
79
|
-
def render_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_entity)
|
|
80
|
-
extracted_errors = extract_errors(errors)
|
|
81
|
-
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
82
|
-
|
|
83
|
-
payload = ResponseBuilder.new(
|
|
84
|
-
success: false,
|
|
85
|
-
data: nil,
|
|
86
|
-
message: message,
|
|
87
|
-
meta: merged_meta,
|
|
88
|
-
errors: extracted_errors,
|
|
89
|
-
request: try(:request)
|
|
90
|
-
).build
|
|
91
|
-
|
|
92
|
-
render json: payload, status: status
|
|
93
|
-
end
|
|
94
|
-
|
|
95
42
|
# =========================================================================
|
|
96
43
|
# 1xx Informational helpers
|
|
97
44
|
# NOTE: 1xx responses are protocol-level and don't carry a body in HTTP/1.1.
|
|
@@ -146,7 +93,7 @@ module Respondo
|
|
|
146
93
|
# 204 No Content — deletions, actions with no response body
|
|
147
94
|
# Note: we still return our standard JSON structure for consistency
|
|
148
95
|
def render_no_content(message: "Deleted successfully", meta: {}, pagination: nil)
|
|
149
|
-
render_success(data: nil, message: message, meta: meta, pagination: pagination, code: 204, status: :
|
|
96
|
+
render_success(data: nil, message: message, meta: meta, pagination: pagination, code: 204, status: :no_content)
|
|
150
97
|
end
|
|
151
98
|
|
|
152
99
|
# 205 Reset Content — tell the client to reset the document view
|
|
@@ -424,6 +371,59 @@ module Respondo
|
|
|
424
371
|
|
|
425
372
|
private
|
|
426
373
|
|
|
374
|
+
# =========================================================================
|
|
375
|
+
# Core DSL — all helpers delegate to these two
|
|
376
|
+
# =========================================================================
|
|
377
|
+
|
|
378
|
+
# Render a successful JSON response.
|
|
379
|
+
#
|
|
380
|
+
# @param data [Object] payload — AR model, collection, Hash, Array, nil
|
|
381
|
+
# @param message [String] human-readable description
|
|
382
|
+
# @param meta [Hash] extra meta fields merged into the meta block
|
|
383
|
+
# @param pagination [Hash, nil] pagination hash built by the caller, e.g.
|
|
384
|
+
# { current_page: 1, per_page: 25, total_pages: 4,
|
|
385
|
+
# total_count: 100, next_page: 2, prev_page: nil }
|
|
386
|
+
# Pass nil (default) to omit pagination from meta.
|
|
387
|
+
# @param status [Symbol, Integer] HTTP status (default: :ok / 200)
|
|
388
|
+
def render_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok)
|
|
389
|
+
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
390
|
+
|
|
391
|
+
payload = ResponseBuilder.new(
|
|
392
|
+
success: true,
|
|
393
|
+
data: data,
|
|
394
|
+
message: message,
|
|
395
|
+
meta: merged_meta,
|
|
396
|
+
pagination: pagination,
|
|
397
|
+
request: try(:request)
|
|
398
|
+
).build
|
|
399
|
+
|
|
400
|
+
render json: payload, status: status
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
# Render an error JSON response.
|
|
404
|
+
#
|
|
405
|
+
# @param message [String] human-readable error description
|
|
406
|
+
# @param errors [Hash, ActiveModel::Errors] field-level validation errors
|
|
407
|
+
# @param code [String, nil] machine-readable error code e.g. "AUTH_EXPIRED"
|
|
408
|
+
# @param meta [Hash] extra meta fields
|
|
409
|
+
# @param status [Symbol, Integer] HTTP status (default: :unprocessable_entity / 422)
|
|
410
|
+
|
|
411
|
+
def render_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_entity)
|
|
412
|
+
extracted_errors = extract_errors(errors)
|
|
413
|
+
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
414
|
+
|
|
415
|
+
payload = ResponseBuilder.new(
|
|
416
|
+
success: false,
|
|
417
|
+
data: nil,
|
|
418
|
+
message: message,
|
|
419
|
+
meta: merged_meta,
|
|
420
|
+
errors: extracted_errors,
|
|
421
|
+
request: try(:request)
|
|
422
|
+
).build
|
|
423
|
+
|
|
424
|
+
render json: payload, status: status
|
|
425
|
+
end
|
|
426
|
+
|
|
427
427
|
# Normalize errors into a plain Hash regardless of source type.
|
|
428
428
|
def extract_errors(errors)
|
|
429
429
|
return nil if errors.nil?
|
|
@@ -97,30 +97,8 @@ module Respondo
|
|
|
97
97
|
meta
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
# def build_meta
|
|
101
|
-
# meta = { timestamp: current_timestamp }
|
|
102
|
-
|
|
103
|
-
# # Only extract pagination when caller has not explicitly disabled it
|
|
104
|
-
# if @pagination
|
|
105
|
-
# pagination = if @pagy
|
|
106
|
-
# Pagination.extract(@pagy)
|
|
107
|
-
# else
|
|
108
|
-
# Pagination.extract(@raw_data)
|
|
109
|
-
# end
|
|
110
|
-
# meta[:pagination] = pagination if pagination
|
|
111
|
-
# end
|
|
112
|
-
|
|
113
|
-
# # Request ID (Rails only, opt-in via config)
|
|
114
|
-
# if Respondo.config.include_request_id && @request&.respond_to?(:request_id)
|
|
115
|
-
# meta[:request_id] = @request.request_id
|
|
116
|
-
# end
|
|
117
|
-
|
|
118
|
-
# # Merge any caller-supplied meta last (allows overriding)
|
|
119
|
-
# meta.merge(@extra_meta)
|
|
120
|
-
# end
|
|
121
|
-
|
|
122
100
|
def current_timestamp
|
|
123
|
-
if
|
|
101
|
+
if Time.respond_to?(:current)
|
|
124
102
|
Time.current.iso8601
|
|
125
103
|
else
|
|
126
104
|
Time.now.utc.iso8601
|
data/lib/respondo/version.rb
CHANGED
data/respondo.gemspec
CHANGED
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
"homepage_uri" => spec.homepage,
|
|
24
24
|
"source_code_uri" => spec.homepage,
|
|
25
25
|
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
|
|
26
|
-
"bug_tracker_uri" => "#{spec.homepage}/
|
|
26
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
|
27
27
|
"rubygems_mfa_required" => "true"
|
|
28
28
|
}
|
|
29
29
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: respondo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- shailendra Kumar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -110,7 +110,7 @@ metadata:
|
|
|
110
110
|
homepage_uri: https://github.com/spatelpatidar/respondo
|
|
111
111
|
source_code_uri: https://github.com/spatelpatidar/respondo
|
|
112
112
|
changelog_uri: https://github.com/spatelpatidar/respondo/blob/main/CHANGELOG.md
|
|
113
|
-
bug_tracker_uri: https://github.com/spatelpatidar/respondo/
|
|
113
|
+
bug_tracker_uri: https://github.com/spatelpatidar/respondo/issues
|
|
114
114
|
rubygems_mfa_required: 'true'
|
|
115
115
|
post_install_message:
|
|
116
116
|
rdoc_options: []
|