respond 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: dfc720a10ed57fba538c3bc65bdbc75253118012
4
- data.tar.gz: 4d5b9f649fa41039943fb7fb16deab20d2404c8d
3
+ metadata.gz: 352adcac52d4b34276f8cd432701327c578d336d
4
+ data.tar.gz: 848d13e7175827ce16723774572abca3b0e0e1cf
5
5
  SHA512:
6
- metadata.gz: 678a8088d959f7f9fbcaf304c32c676ef856e66d03aaf4e36644e1238c5926fe4fdde9e30bf59a1335bb9b657cd9cd28b9a6fc010040394fd707a95c3777c51f
7
- data.tar.gz: 22cc3313fef2e66fd78ad83983580b0f3866f05d8d40de05902eddcbe996347ee8cca26de878226121e8ab94b34bd1677263b9328f3263f6f9845f927c68c841
6
+ metadata.gz: bcc467f8450226252fc93bdc9f0fe6a4763c9cd97bd4ee7f3b7b4cd132f7a2cfde9de55e7205ffb5cd670e06583bacb1b9ee6ecd3e701caede40b6189afa3335
7
+ data.tar.gz: 43e7ef3da39d79d6af8468b81d85118d99499e8c82ca11a22b6430d77a255f931f54eaaffa8f8a5a8536b106b2bb3fb5ef726bf746bb0bf5c557c85dd7e0ff4d
data/lib/Messages.rb CHANGED
@@ -2,27 +2,46 @@ module Anetwork
2
2
 
3
3
  class Messages
4
4
 
5
+ # setter and getter varibules
5
6
  attr_accessor :code , :text , :error , :error_code , :headers , :lang , :config
6
7
 
7
- def initialize
8
+ ##
9
+ # initialize method
10
+ #
11
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
12
+ # @since 1 Dec 2016
13
+ # @return [Object]
14
+ # @param [String] lang
15
+ def initialize(lang = 'en')
8
16
  @lang = I18n.locale
9
- lang = 'en'
10
17
 
11
18
  if @lang != '' || @lang != nil
12
19
  lang = @lang
13
20
  end
14
21
 
15
- @config = eval(File.open(Rails.root.join(
16
- 'config/respond/errors', "#{lang}.rb"
17
- )).read)
22
+ @config = eval(File.open(__dir__ + "/errors/#{lang}.rb").read)
18
23
  end
19
24
 
25
+ ##
26
+ # Request succeeded and contains json result
27
+ #
28
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
29
+ # @since 1 Dec 2016
30
+ # @param [Object] data
31
+ # @return [Object]
20
32
  def succeed(data)
21
33
  self.set_status_code(200)
22
34
  .set_status_text('success')
23
35
  .respond_with_result(data)
24
36
  end
25
37
 
38
+ ##
39
+ # Delete action is succeed
40
+ #
41
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
42
+ # @since 1 Dec 2016
43
+ # @param [String] message
44
+ # @return [Object]
26
45
  def delete_succeeded(message = nil)
27
46
  if message == nil
28
47
  message = @config[:success][:delete]
@@ -33,6 +52,13 @@ module Anetwork
33
52
  .respond_with_message(message)
34
53
  end
35
54
 
55
+ ##
56
+ # Update action is succeed
57
+ #
58
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
59
+ # @since 1 Dec 2016
60
+ # @param [String] message
61
+ # @return [Object]
36
62
  def update_succeeded(message = nil)
37
63
  if message == nil
38
64
  message = @config[:success][:update]
@@ -43,6 +69,13 @@ module Anetwork
43
69
  .respond_with_message(message)
44
70
  end
45
71
 
72
+ ##
73
+ # Insert action is succeed
74
+ #
75
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
76
+ # @since 1 Dec 2016
77
+ # @param [String] message
78
+ # @return [Object]
46
79
  def insert_succeeded(message = nil)
47
80
  if message == nil
48
81
  message = @config[:success][:insert]
@@ -53,6 +86,13 @@ module Anetwork
53
86
  .respond_with_message(message)
54
87
  end
55
88
 
89
+ ##
90
+ # Delete action is faild
91
+ #
92
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
93
+ # @since 1 Dec 2016
94
+ # @param [String] message
95
+ # @return [Object]
56
96
  def delete_faild(message = nil)
57
97
  if message == nil
58
98
  message = @config[:fail][:delete]
@@ -64,6 +104,13 @@ module Anetwork
64
104
  .respond_with_message(message)
65
105
  end
66
106
 
107
+ ##
108
+ # Update action is succeed
109
+ #
110
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
111
+ # @since 1 Dec 2016
112
+ # @param [String] message
113
+ # @return [Object]
67
114
  def update_faild(message = nil)
68
115
  if message == nil
69
116
  message = @config[:fail][:update]
@@ -75,6 +122,13 @@ module Anetwork
75
122
  .respond_with_message(message)
76
123
  end
77
124
 
125
+ ##
126
+ # Insert action is faild
127
+ #
128
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
129
+ # @since 1 Dec 2016
130
+ # @param [String] message
131
+ # @return [Object]
78
132
  def insert_faild(message = nil)
79
133
  if message == nil
80
134
  message = @config[:fail][:insert]
@@ -86,64 +140,105 @@ module Anetwork
86
140
  .respond_with_message(message)
87
141
  end
88
142
 
143
+ ##
144
+ # Database connection is refused
145
+ #
146
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
147
+ # @since 1 Dec 2016
148
+ # @return [Object]
89
149
  def connection_refused
90
-
91
150
  self.set_status_code(445)
92
151
  .set_status_text('fail')
93
152
  .set_error_code(5445)
94
- .respond_with_message()
153
+ .respond_with_message
95
154
  end
96
155
 
156
+ ##
157
+ # Page requested is not found
158
+ #
159
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
160
+ # @since 1 Dec 2016
161
+ # @return [Object]
97
162
  def not_found
98
-
99
163
  self.set_status_code(404)
100
164
  .set_status_text('fail')
101
165
  .set_error_code(5404)
102
166
  .respond_with_message
103
167
  end
104
168
 
169
+ ##
170
+ # Wrong parameters are entered
171
+ #
172
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
173
+ # @since 1 Dec 2016
174
+ # @return [Object]
105
175
  def wrong_parameters
106
-
107
176
  self.set_status_code(406)
108
177
  .set_status_text('fail')
109
178
  .set_error_code(5406)
110
179
  .respond_with_message
111
180
  end
112
181
 
182
+ ##
183
+ # Method is not allowed
184
+ #
185
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
186
+ # @since 1 Dec 2016
187
+ # @return [Object]
113
188
  def method_not_allowed
114
-
115
189
  self.set_status_code(405)
116
190
  .set_status_text('fail')
117
191
  .set_error_code(5405)
118
192
  .respond_with_message
119
193
  end
120
194
 
195
+ ##
196
+ # There ara validation errors
197
+ #
198
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
199
+ # @since 1 Dec 2016
200
+ # @return [Object]
121
201
  def validation_errors(message = nil)
122
-
123
202
  self.set_status_code(420)
124
203
  .set_status_text('fail')
125
204
  .set_error_code(5420)
126
205
  .respond_with_message(message)
127
206
  end
128
207
 
208
+ ##
209
+ # The request field is not found
210
+ #
211
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
212
+ # @since 1 Dec 2016
213
+ # @return [Object]
129
214
  def request_field_notfound
130
-
131
215
  self.set_status_code(446)
132
216
  .set_status_text('fail')
133
217
  .set_error_code(1001)
134
218
  .respond_with_message
135
219
  end
136
220
 
221
+ ##
222
+ # The request field is duplicated
223
+ #
224
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
225
+ # @since 1 Dec 2016
226
+ # @return [Object]
137
227
  def request_field_duplicated
138
-
139
228
  self.set_status_code(400)
140
229
  .set_status_text('fail')
141
230
  .set_error_code(1004)
142
231
  .respond_with_message
143
232
  end
144
233
 
234
+ ##
235
+ # The error message
236
+ #
237
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
238
+ # @since 1 Dec 2016
239
+ # @param [Object] code
240
+ # @return [Object]
145
241
  def error(code)
146
-
147
242
  self.set_status_code(400)
148
243
  .set_status_text('fail')
149
244
  .set_error_code(code)
@@ -1,5 +1,5 @@
1
1
  module Anetwork
2
2
  class Respond
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
data/lib/Respond.rb CHANGED
@@ -4,16 +4,37 @@ module Anetwork
4
4
 
5
5
  class Respond < Messages
6
6
 
7
+ ##
8
+ # set status code of respond
9
+ #
10
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
11
+ # @since 1 Dec 2016
12
+ # @param [Integer] code
13
+ # @return [Object]
7
14
  def set_status_code(code)
8
15
  @code = code
9
16
  self
10
17
  end
11
18
 
19
+ ##
20
+ # set status text of respond
21
+ #
22
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
23
+ # @since 1 Dec 2016
24
+ # @param [String] text
25
+ # @return [Object]
12
26
  def set_status_text(text)
13
27
  @text = text
14
28
  self
15
29
  end
16
30
 
31
+ ##
32
+ # get respond with message
33
+ #
34
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
35
+ # @since 1 Dec 2016
36
+ # @param [String] message
37
+ # @return [Object]
17
38
  def respond_with_message(message = nil)
18
39
  result = { :status => @text , :message => message }
19
40
 
@@ -28,16 +49,37 @@ module Anetwork
28
49
  result
29
50
  end
30
51
 
52
+ ##
53
+ # get respond with result
54
+ #
55
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
56
+ # @since 1 Dec 2016
57
+ # @param [Object] data
58
+ # @return [Object]
31
59
  def respond_with_result(data)
32
60
  { :status => @text, :result => data }
33
61
  end
34
62
 
63
+ ##
64
+ # set error code and get details from lang file
65
+ #
66
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
67
+ # @since 1 Dec 2016
68
+ # @param [Integer] error_code
69
+ # @return [Object]
35
70
  def set_error_code(error_code)
36
71
  @error_code = error_code
37
72
  @error = @config[error_code]
38
73
  self
39
74
  end
40
75
 
76
+ ##
77
+ # set headers for response
78
+ #
79
+ # @author Alireza Josheghani <a.josheghani@anetwork.ir>
80
+ # @since 1 Dec 2016
81
+ # @param [Object] headers
82
+ # @return [Object]
41
83
  def set_headers(headers)
42
84
  @headers = headers
43
85
  end
data/lib/errors/en.rb ADDED
@@ -0,0 +1,185 @@
1
+ {
2
+ :success => {
3
+ :insert => 'The requested parameter is Added successfully!',
4
+ :delete => 'The requested parameter is deleted successfully!',
5
+ :update => 'The requested parameter is updated successfully!'
6
+ },
7
+
8
+ :fail => {
9
+ :insert => 'The requested parameter is not Added!',
10
+ :delete => 'The requested parameter is not deleted!',
11
+ :update => 'The requested parameter is not updated!'
12
+ },
13
+
14
+ 1001 => {
15
+ :message => 'Oops... Requested field is not found!',
16
+ :type => 'error'
17
+ },
18
+
19
+ 1002 => {
20
+ :message => 'Oops... Requested User does not exists!',
21
+ :type => 'error'
22
+ },
23
+
24
+ 1003 => {
25
+ :message => 'Oops... Client type is not entered!',
26
+ :type => 'error'
27
+ },
28
+
29
+ 1004 => {
30
+ :message => 'Failed because of duplicate',
31
+ :type => 'error'
32
+ },
33
+
34
+ 1005 => {
35
+ :message => 'Failed because of dablicated user role',
36
+ :type => 'error'
37
+ },
38
+
39
+ 3001 => {
40
+ :message => 'You are not logged on',
41
+ :type => 'error',
42
+ :cat => 'auth',
43
+ :short => 'not-logged-on'
44
+ },
45
+
46
+ 3002 => {
47
+ :message => 'Application token did not generated successfully',
48
+ :type => 'error',
49
+ :cat => 'auth'
50
+ },
51
+
52
+ 3003 =>{
53
+ :message => 'User token did not generated successfully',
54
+ :type => 'error',
55
+ :cat => 'auth'
56
+ },
57
+
58
+ 3004 => {
59
+ :message => 'Request token have no agency access',
60
+ :type => 'error',
61
+ :cat => 'auth'
62
+ },
63
+
64
+ 3005 => {
65
+ :message => 'Request token did not contains user information',
66
+ :type => 'error',
67
+ :cat => 'auth'
68
+ },
69
+
70
+ 3006 => {
71
+ :message => 'Did not set request token',
72
+ :type => 'error',
73
+ :cat => 'auth'
74
+ },
75
+
76
+ 3007 => {
77
+ :message => 'can not decode the token',
78
+ :type => 'error',
79
+ :cat => 'auth'
80
+ },
81
+
82
+ 3008 => {
83
+ :message => 'can not generate token for authentication',
84
+ :type => 'error',
85
+ :cat => 'auth'
86
+ },
87
+
88
+ 3009 => {
89
+ :message => 'can not create token',
90
+ :type => 'error',
91
+ :cat => 'auth'
92
+ },
93
+
94
+ 3010 => {
95
+ :message => 'Token expired!',
96
+ :type => 'error',
97
+ :cat => 'auth'
98
+ },
99
+
100
+ 3011 => {
101
+ :message => 'Token is invalid!',
102
+ :type => 'error',
103
+ :cat => 'auth'
104
+ },
105
+
106
+ 3012 => {
107
+ :message => 'Token Blacklisted',
108
+ :type => 'error',
109
+ :cat => 'auth'
110
+ },
111
+
112
+ 3013 => {
113
+ :message => 'Payload invalid!',
114
+ :type => 'error',
115
+ :cat => 'auth'
116
+ },
117
+
118
+ 3014 => {
119
+ :message => 'Claim Invalid',
120
+ :type => 'error',
121
+ :cat => 'auth'
122
+ },
123
+
124
+ 3015 => {
125
+ :message => 'An error occurred on token validation',
126
+ :type => 'error',
127
+ :cat => 'auth'
128
+ },
129
+
130
+ 3016 => {
131
+
132
+ :message => 'This domain has been blocked',
133
+ :type => 'error'
134
+ },
135
+
136
+ 5401 => {
137
+ :message => 'Authentication unauthorized...',
138
+ :type => 'error'
139
+ },
140
+
141
+ 5404 => {
142
+ :message => 'Oops... The requested page not found!',
143
+ :type => 'error'
144
+ },
145
+
146
+ 5405 => {
147
+ :message => 'Oops... The method you requested is not allowed!',
148
+ :type => 'error'
149
+ },
150
+
151
+ 5406 => {
152
+ :message => 'Oops... The parameters you entered are wrong!',
153
+ :type => 'error'
154
+ },
155
+
156
+ 5420 => {
157
+ :message => 'Validation Error',
158
+ :type => 'error'
159
+ },
160
+
161
+ 5422 => {
162
+ :message => 'Token is not valid',
163
+ :type => 'error'
164
+ },
165
+
166
+ 5445 => {
167
+ :message => 'Oops... Database connection refused',
168
+ :type => 'error'
169
+ },
170
+
171
+ 5448 => {
172
+ :message => 'Oops... Insert action was not successfully executed',
173
+ :type => 'error'
174
+ },
175
+
176
+ 5447 => {
177
+ :message => 'Oops... Delete action was not successfully executed',
178
+ :type => 'error'
179
+ },
180
+
181
+ 5449 => {
182
+ :message => 'Oops... Update action was not successfully executed',
183
+ :type => 'error'
184
+ }
185
+ }
data/lib/errors/fa.rb ADDED
@@ -0,0 +1,179 @@
1
+ {
2
+ :success => {
3
+ :insert => '.درخواست با موفقیت درج شده است',
4
+ :delete => '.درخواست با موفقیت پاک شده است',
5
+ :update => '.درخواست با موفقیت ویرایش شده است'
6
+ },
7
+
8
+ :fail => {
9
+ :insert => '.درخواست با موفقیت درج نشد',
10
+ :delete => '.درخواست با موفقیت پاک نشد',
11
+ :update => '.درخواست با موفقیت ویرایش نشد'
12
+ },
13
+
14
+ 1001 => {
15
+ :message => '.درخواست مورد نظر پیدا نشده است',
16
+ :type => 'error'
17
+ },
18
+
19
+ 1002 => {
20
+ :message => '.کاربر مورد نظر موجود نیست',
21
+ :type => 'error'
22
+ },
23
+
24
+ 1003 => {
25
+ :message => '.نوع کاربری وارد نشده است',
26
+ :type => 'error'
27
+ },
28
+
29
+ 1004 => {
30
+ :message => '.ورودی مورد نظر تکراری است',
31
+ :type => 'error'
32
+ },
33
+
34
+ 1005 => {
35
+ :message => '.نقش کاربر مورد نظر تکراری است',
36
+ :type => 'error'
37
+ },
38
+
39
+ 3001 => {
40
+ :message => '.شما به سیستم وارد نشده اید',
41
+ :type => 'error',
42
+ :cat => 'auth',
43
+ :short => 'not-logged-on'
44
+ },
45
+
46
+ 3002 => {
47
+ :message => '.نشان شناسایی شما نامعتبر است',
48
+ :type => 'error',
49
+ :cat => 'auth'
50
+ },
51
+
52
+ 3003 =>{
53
+ :message => '.نشان شناسایی شما نامعتبر است',
54
+ :type => 'error',
55
+ :cat => 'auth'
56
+ },
57
+
58
+ 3004 => {
59
+ :message => '.هیچ آژانسی به نشان شناسایی دسترسی ندارد',
60
+ :type => 'error',
61
+ :cat => 'auth'
62
+ },
63
+
64
+ 3005 => {
65
+ :message => '.نشان شناسایی شما نامعتبر است',
66
+ :type => 'error',
67
+ :cat => 'auth'
68
+ },
69
+
70
+ 3006 => {
71
+ :message => '.نشان شناسایی شما نامعتبر است',
72
+ :type => 'error',
73
+ :cat => 'auth'
74
+ },
75
+
76
+ 3007 => {
77
+ :message => '.نشان شناسایی شما نمایش داده نمیشود',
78
+ :type => 'error',
79
+ :cat => 'auth'
80
+ },
81
+
82
+ 3008 => {
83
+ :message => '.نشان شناسایی شما نامعتبر است',
84
+ :type => 'error',
85
+ :cat => 'auth'
86
+ },
87
+
88
+ 3009 => {
89
+ :message => '.نشان شناسایی شما نامعتبر است',
90
+ :type => 'error',
91
+ :cat => 'auth'
92
+ },
93
+
94
+ 3010 => {
95
+ :message => '.زمان استفاده از نشان شناسایی شما گذشته است',
96
+ :type => 'error',
97
+ :cat => 'auth'
98
+ },
99
+
100
+ 3011 => {
101
+ :message => '.نشان شناسایی شما نامعتبر است',
102
+ :type => 'error',
103
+ :cat => 'auth'
104
+ },
105
+
106
+ 3012 => {
107
+ :message => '.نشان شناسایی شما نامعتبر است',
108
+ :type => 'error',
109
+ :cat => 'auth'
110
+ },
111
+
112
+ 3013 => {
113
+ :message => '.Payload معتبر نیست',
114
+ :type => 'error',
115
+ :cat => 'auth'
116
+ },
117
+
118
+ 3014 => {
119
+ :message => '.Claim معتبر نیست',
120
+ :type => 'error',
121
+ :cat => 'auth'
122
+ },
123
+
124
+ 3015 => {
125
+ :message => '.نشان شناسایی شما نامعتبر است',
126
+ :type => 'error',
127
+ :cat => 'auth'
128
+ },
129
+
130
+ 5401 => {
131
+ :message => '.شناسایی کاربر نامعتبر است',
132
+ :type => 'error'
133
+ },
134
+
135
+ 5404 => {
136
+ :message => '.صفحه درخواست شده پیدا نمیشود',
137
+ :type => 'error'
138
+ },
139
+
140
+ 5405 => {
141
+ :message => '.شما به درخواستی که داده اید دسترسی ندارید',
142
+ :type => 'error'
143
+ },
144
+
145
+ 5406 => {
146
+ :message => '.پارامترهایی که شما وارد کرده اید نا معتبر است',
147
+ :type => 'error'
148
+ },
149
+
150
+ 5420 => {
151
+ :message => '.خطای اعتبار سنجی',
152
+ :type => 'error'
153
+ },
154
+
155
+ 5422 => {
156
+ :message => '.نشان شناسایی شما نامعتبر است',
157
+ :type => 'error'
158
+ },
159
+
160
+ 5445 => {
161
+ :message => '.ارتباط با پایگاه داده مشکل دارد',
162
+ :type => 'error'
163
+ },
164
+
165
+ 5448 => {
166
+ :message => '.عملیات درج درست اجرا نشده است',
167
+ :type => 'error'
168
+ },
169
+
170
+ 5447 => {
171
+ :message => '.عملیات پاک کردن درست اجرا نشده است',
172
+ :type => 'error'
173
+ },
174
+
175
+ 5449 => {
176
+ :message => '.عملیات ویرایش درست اجرا نشده است',
177
+ :type => 'error'
178
+ }
179
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: respond
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alireza Josheghani
@@ -54,6 +54,8 @@ files:
54
54
  - lib/Messages.rb
55
55
  - lib/Respond.rb
56
56
  - lib/Respond/version.rb
57
+ - lib/errors/en.rb
58
+ - lib/errors/fa.rb
57
59
  - respond.gemspec
58
60
  homepage: https://github.com/anetwork
59
61
  licenses: