repres-dosser 1.2 → 1.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f36fbda1d513150d66f62df418774c8094c260
|
4
|
+
data.tar.gz: 115f2058adb44eaf85ef31e020a8a23e581e15b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1c8e66c84d9f274da7573d7ca37beaa6f8d9f555f4ab5f547c94e30f3345d09bc7e5cc06e04ba35140842efd96cced2d4ebfdc7cfd106611d313ad53ea4d9d8
|
7
|
+
data.tar.gz: 13a471c003090e390242aac6f10a13035de8fa041f485a4b439456a90ebb6b030f138cdc2a409d2aa73ceedb6541a0fac2c120118cc849b9f8beb12bbb90b120
|
@@ -5,6 +5,7 @@ module Repres::Dosser::Concerns::ResourcePresentation
|
|
5
5
|
CODE_SUCCESS = 'success'.freeze
|
6
6
|
CODE_FAILURE = 'failure'.freeze
|
7
7
|
|
8
|
+
CODE_FAILURE_FORBIDDEN = 'failure-forbidden'.freeze
|
8
9
|
CODE_FAILURE_NOT_FOUND = 'failure-not-found'.freeze
|
9
10
|
CODE_FAILURE_WRONG_PARAMETER = 'failure-wrong-parameter'.freeze
|
10
11
|
CODE_FAILURE_WRONG_STATE = 'failure-wrong-state'.freeze
|
@@ -13,70 +14,131 @@ module Repres::Dosser::Concerns::ResourcePresentation
|
|
13
14
|
|
14
15
|
attr_writer :criteria
|
15
16
|
|
17
|
+
# https://httpstatuses.com/
|
18
|
+
# http://www.restapitutorial.com/httpstatuscodes.html
|
19
|
+
# http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
|
20
|
+
|
16
21
|
# 200
|
17
|
-
def render_ok(
|
18
|
-
|
22
|
+
def render_ok(
|
23
|
+
success: true,
|
24
|
+
code: self.class::CODE_SUCCESS,
|
25
|
+
message: '成功',
|
26
|
+
collection: [],
|
27
|
+
size: collection.size,
|
28
|
+
errors: {})
|
29
|
+
respond_result :ok,
|
19
30
|
success: success,
|
20
31
|
code: code,
|
21
32
|
message: message,
|
22
33
|
collection: collection,
|
23
34
|
size: size,
|
24
35
|
errors: errors
|
25
|
-
}
|
26
|
-
respond_result :ok, result
|
27
36
|
end
|
28
37
|
|
29
38
|
# 201
|
30
|
-
def render_created(
|
31
|
-
|
39
|
+
def render_created(
|
40
|
+
success: true,
|
41
|
+
code: self.class::CODE_SUCCESS,
|
42
|
+
message: '成功',
|
43
|
+
collection: [],
|
44
|
+
size: collection.size,
|
45
|
+
errors: {})
|
46
|
+
respond_result :created,
|
47
|
+
success: success,
|
48
|
+
code: code,
|
49
|
+
message: message,
|
50
|
+
collection: collection,
|
51
|
+
size: size,
|
52
|
+
errors: errors
|
53
|
+
end
|
54
|
+
|
55
|
+
=begin
|
56
|
+
# 204
|
57
|
+
def render_no_content(
|
58
|
+
success: true,
|
59
|
+
code: self.class::CODE_SUCCESS,
|
60
|
+
message: '成功',
|
61
|
+
collection: [],
|
62
|
+
size: collection.size,
|
63
|
+
errors: {})
|
64
|
+
respond_result :no_content,
|
32
65
|
success: success,
|
33
66
|
code: code,
|
34
67
|
message: message,
|
35
68
|
collection: collection,
|
36
69
|
size: size,
|
37
70
|
errors: errors
|
38
|
-
}
|
39
|
-
respond_result :created, result
|
40
71
|
end
|
72
|
+
=end
|
41
73
|
|
42
74
|
# 400
|
43
|
-
def render_bad_request(
|
44
|
-
|
75
|
+
def render_bad_request(
|
76
|
+
success: false,
|
77
|
+
code: self.class::CODE_FAILURE_WRONG_PARAMETER,
|
78
|
+
message: '参数错误',
|
79
|
+
collection: [],
|
80
|
+
size: collection.size,
|
81
|
+
errors: {})
|
82
|
+
respond_result :bad_request,
|
45
83
|
success: success,
|
46
84
|
code: code,
|
47
85
|
message: message,
|
48
86
|
collection: collection,
|
49
87
|
size: size,
|
50
88
|
errors: errors
|
51
|
-
}
|
52
|
-
respond_result :bad_request, result
|
53
89
|
end
|
54
|
-
|
55
|
-
#
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
90
|
+
|
91
|
+
# 401
|
92
|
+
def render_unauthorized(
|
93
|
+
success: false,
|
94
|
+
code: self.class::CODE_FAILURE,
|
95
|
+
message: '请先登录',
|
96
|
+
collection: [],
|
97
|
+
size: collection.size,
|
98
|
+
errors: {})
|
99
|
+
respond_result :unauthorized,
|
100
|
+
success: success,
|
101
|
+
code: code,
|
102
|
+
message: message,
|
103
|
+
collection: collection,
|
104
|
+
size: size,
|
105
|
+
errors: errors
|
66
106
|
end
|
67
|
-
|
107
|
+
|
108
|
+
# 403 forbidden
|
109
|
+
def render_forbidden(
|
110
|
+
success: false,
|
111
|
+
code: self.class::CODE_FAILURE_FORBIDDEN,
|
112
|
+
message: '无权访问',
|
113
|
+
collection: [],
|
114
|
+
size: collection.size,
|
115
|
+
errors: {})
|
116
|
+
respond_result :forbidden,
|
117
|
+
success: success,
|
118
|
+
code: code,
|
119
|
+
message: message,
|
120
|
+
collection: collection,
|
121
|
+
size: size,
|
122
|
+
errors: errors
|
123
|
+
end
|
124
|
+
|
68
125
|
# 404
|
69
|
-
def render_not_found(
|
70
|
-
|
126
|
+
def render_not_found(
|
127
|
+
success: false,
|
128
|
+
code: self.class::CODE_FAILURE_NOT_FOUND,
|
129
|
+
message: '没有找到符合条件的信息',
|
130
|
+
collection: [],
|
131
|
+
size: collection.size,
|
132
|
+
errors: {})
|
133
|
+
respond_result :not_found,
|
71
134
|
success: success,
|
72
135
|
code: code,
|
73
136
|
message: message,
|
74
137
|
collection: collection,
|
75
138
|
size: size,
|
76
139
|
errors: errors
|
77
|
-
}
|
78
|
-
respond_result :not_found, result
|
79
140
|
end
|
141
|
+
|
80
142
|
=begin
|
81
143
|
# 404 not found - inexistent
|
82
144
|
def render_inexistent(parameter_name, message)
|
@@ -91,19 +153,25 @@ module Repres::Dosser::Concerns::ResourcePresentation
|
|
91
153
|
respond_result :not_found, result
|
92
154
|
end
|
93
155
|
=end
|
156
|
+
|
94
157
|
# 409
|
95
|
-
def render_conflict(
|
96
|
-
|
158
|
+
def render_conflict(
|
159
|
+
success: false,
|
160
|
+
code: self.class::CODE_FAILURE_WRONG_STATE,
|
161
|
+
message: '',
|
162
|
+
collection: [],
|
163
|
+
size: collection.size,
|
164
|
+
errors: {})
|
165
|
+
respond_result :conflict,
|
97
166
|
success: success,
|
98
167
|
code: code,
|
99
168
|
message: message,
|
100
169
|
collection: collection,
|
101
170
|
size: size,
|
102
171
|
errors: errors
|
103
|
-
}
|
104
|
-
respond_result :conflict, result
|
105
172
|
end
|
106
173
|
|
174
|
+
=begin
|
107
175
|
# 409 conflict - wrong parameter
|
108
176
|
def render_wrong_parameter(success: false, code: self.class::CODE_FAILURE_WRONG_PARAMETER, message: '', collection: [], size: 0, errors: {})
|
109
177
|
result = {
|
@@ -116,9 +184,22 @@ module Repres::Dosser::Concerns::ResourcePresentation
|
|
116
184
|
}
|
117
185
|
respond_result :conflict, result
|
118
186
|
end
|
187
|
+
=end
|
119
188
|
|
120
|
-
def render_internal_server_error(
|
121
|
-
|
189
|
+
def render_internal_server_error(
|
190
|
+
success: false,
|
191
|
+
code: self.class::CODE_FAILURE,
|
192
|
+
message: '出现临时网络故障,请稍后重试。',
|
193
|
+
collection: [],
|
194
|
+
size: collection.size,
|
195
|
+
errors: {})
|
196
|
+
respond_result :internal_server_error,
|
197
|
+
success: success,
|
198
|
+
code: code,
|
199
|
+
message: message,
|
200
|
+
collection: collection,
|
201
|
+
size: size,
|
202
|
+
errors: errors
|
122
203
|
end
|
123
204
|
|
124
205
|
def respond_result(status, result)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repres-dosser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|