respond 0.1.2 → 0.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 +4 -4
- data/README.md +13 -3
- data/Rakefile +7 -2
- data/errors/en.yml +153 -0
- data/errors/fa.yml +149 -0
- data/lib/{Messages.rb → messages.rb} +41 -47
- data/lib/respond/version.rb +5 -0
- data/lib/{Respond.rb → respond.rb} +7 -8
- data/respond.gemspec +5 -5
- metadata +14 -14
- data/lib/Respond/version.rb +0 -5
- data/lib/errors/en.rb +0 -185
- data/lib/errors/fa.rb +0 -179
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719e4d93ca2f060e9a899127cc1aae070b01ad5d
|
4
|
+
data.tar.gz: e4e11b9e05c35c087317fbde99b8aff645004980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 678d422a0222e91c5c0f91f49c6259e627c0eba9d64cc996c1e3638d018e5d8a284d3ccee855a30495e11f34e40f3cef954ecbf94484ef0528cc991b72c8561c
|
7
|
+
data.tar.gz: 2b3b52abe5f2897f5818c5ab4f589cd8b980de6a5f2a58571f31bee614d5d7adce67373061b8219f08bb4f13252323baa22ceb47bc3aa95b888e0b7b764abee2
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ This package is provided to be used on rails framework and it gives clean method
|
|
19
19
|
Add this line to your application's Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem '
|
22
|
+
gem 'respond'
|
23
23
|
```
|
24
24
|
|
25
25
|
And then execute:
|
@@ -28,7 +28,7 @@ And then execute:
|
|
28
28
|
|
29
29
|
Or install it yourself as:
|
30
30
|
|
31
|
-
$ gem install
|
31
|
+
$ gem install respond
|
32
32
|
|
33
33
|
|
34
34
|
## Usage
|
@@ -109,7 +109,7 @@ respond.request_field_notfound
|
|
109
109
|
```
|
110
110
|
|
111
111
|
Validation errors:
|
112
|
-
```
|
112
|
+
```ruby
|
113
113
|
respond.validation_errors(data)
|
114
114
|
```
|
115
115
|
|
@@ -124,6 +124,16 @@ And you can do more:
|
|
124
124
|
respond.set_status_code(200).set_status_text('succeed').respond_with_message('Your custom message')
|
125
125
|
```
|
126
126
|
|
127
|
+
###render
|
128
|
+
for render the json response , you must use the render method
|
129
|
+
```ruby
|
130
|
+
render :json => result
|
131
|
+
```
|
132
|
+
the "result" varibule must be instnace of Respond object for example:
|
133
|
+
```ruby
|
134
|
+
render :json => respond.not_found
|
135
|
+
```
|
136
|
+
|
127
137
|
## License
|
128
138
|
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
129
139
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
# Copy config files
|
4
|
+
task :config do
|
5
|
+
mv(File.join("errors", "en.yml"), Rails.root.join("config", "locales", "respond", "en.yml"), :verbose => true)
|
6
|
+
mv(File.join("errors", "fa.yml"), Rails.root.join("config", "locales", "respond", "fa.yml"), :verbose => true)
|
7
|
+
end
|
data/errors/en.yml
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
en:
|
2
|
+
success: "Success."
|
3
|
+
failed: "Failed!"
|
4
|
+
respond:
|
5
|
+
success:
|
6
|
+
insert: 'The requested parameter is Added successfully!'
|
7
|
+
delete: 'The requested parameter is deleted successfully!'
|
8
|
+
update: 'The requested parameter is updated successfully!'
|
9
|
+
|
10
|
+
failed:
|
11
|
+
insert: 'The requested parameter is not Added!'
|
12
|
+
delete: 'The requested parameter is not deleted!'
|
13
|
+
update: 'The requested parameter is not updated!'
|
14
|
+
|
15
|
+
"1001":
|
16
|
+
message: 'Oops... Requested field is not found!'
|
17
|
+
type: 'error'
|
18
|
+
|
19
|
+
"1002":
|
20
|
+
message: 'Oops... Requested User does not exists!'
|
21
|
+
type: 'error'
|
22
|
+
|
23
|
+
"1003":
|
24
|
+
message: 'Oops... Client type is not entered!'
|
25
|
+
type: 'error'
|
26
|
+
|
27
|
+
"1004":
|
28
|
+
message: 'Failed because of duplicate'
|
29
|
+
type: 'error'
|
30
|
+
|
31
|
+
"1005":
|
32
|
+
message: 'Failed because of dablicated user role'
|
33
|
+
type: 'error'
|
34
|
+
|
35
|
+
"3001":
|
36
|
+
message: 'You are not logged on'
|
37
|
+
type: 'error'
|
38
|
+
cat: 'auth'
|
39
|
+
short: 'not-logged-on'
|
40
|
+
|
41
|
+
"3002":
|
42
|
+
message: 'Application token did not generated successfully'
|
43
|
+
type : 'error'
|
44
|
+
cat: 'auth'
|
45
|
+
|
46
|
+
"3003":
|
47
|
+
message: 'User token did not generated successfully'
|
48
|
+
type: 'error'
|
49
|
+
cat: 'auth'
|
50
|
+
|
51
|
+
"3004":
|
52
|
+
message: 'Request token have no agency access'
|
53
|
+
type: 'error'
|
54
|
+
cat: 'auth'
|
55
|
+
|
56
|
+
"3005":
|
57
|
+
message: 'Request token did not contains user information'
|
58
|
+
type: 'error'
|
59
|
+
cat: 'auth'
|
60
|
+
|
61
|
+
"3006":
|
62
|
+
message: 'Did not set request token'
|
63
|
+
type: 'error'
|
64
|
+
cat: 'auth'
|
65
|
+
|
66
|
+
"3007":
|
67
|
+
message: 'can not decode the token'
|
68
|
+
type: 'error'
|
69
|
+
cat: 'auth'
|
70
|
+
|
71
|
+
"3008":
|
72
|
+
message: 'can not generate token for authentication'
|
73
|
+
type: 'error'
|
74
|
+
cat: 'auth'
|
75
|
+
|
76
|
+
"3009":
|
77
|
+
message: 'can not create token'
|
78
|
+
type: 'error'
|
79
|
+
cat: 'auth'
|
80
|
+
|
81
|
+
"3010":
|
82
|
+
message: 'Token expired!'
|
83
|
+
type: 'error'
|
84
|
+
cat: 'auth'
|
85
|
+
|
86
|
+
"3011":
|
87
|
+
message: 'Token is invalid!'
|
88
|
+
type: 'error'
|
89
|
+
cat: 'auth'
|
90
|
+
|
91
|
+
"3012":
|
92
|
+
message: 'Token Blacklisted'
|
93
|
+
type: 'error'
|
94
|
+
cat: 'auth'
|
95
|
+
|
96
|
+
"3013":
|
97
|
+
message: 'Payload invalid!'
|
98
|
+
type: 'error'
|
99
|
+
cat: 'auth'
|
100
|
+
|
101
|
+
"3014":
|
102
|
+
message: 'Claim Invalid'
|
103
|
+
type: 'error'
|
104
|
+
cat: 'auth'
|
105
|
+
|
106
|
+
"3015":
|
107
|
+
message: 'An error occurred on token validation'
|
108
|
+
type: 'error'
|
109
|
+
cat: 'auth'
|
110
|
+
|
111
|
+
"3016":
|
112
|
+
message: 'This domain has been blocked'
|
113
|
+
type: 'error'
|
114
|
+
|
115
|
+
"5401":
|
116
|
+
message: 'Authentication unauthorized...'
|
117
|
+
type: 'error'
|
118
|
+
|
119
|
+
"5404":
|
120
|
+
message: 'Oops... The requested page not found!'
|
121
|
+
type: 'error'
|
122
|
+
|
123
|
+
"5405":
|
124
|
+
message: 'Oops... The method you requested is not allowed!'
|
125
|
+
type: 'error'
|
126
|
+
|
127
|
+
"5406":
|
128
|
+
message: 'Oops... The parameters you entered are wrong!'
|
129
|
+
type: 'error'
|
130
|
+
|
131
|
+
"5420":
|
132
|
+
message: 'Validation Error'
|
133
|
+
type: 'error'
|
134
|
+
|
135
|
+
"5422":
|
136
|
+
message: 'Token is not valid'
|
137
|
+
type: 'error'
|
138
|
+
|
139
|
+
"5445":
|
140
|
+
message: 'Oops... Database connection refused'
|
141
|
+
type: 'error'
|
142
|
+
|
143
|
+
"5448":
|
144
|
+
message: 'Oops... Insert action was not successfully executed'
|
145
|
+
type: 'error'
|
146
|
+
|
147
|
+
"5447":
|
148
|
+
message: 'Oops... Delete action was not successfully executed'
|
149
|
+
type: 'error'
|
150
|
+
|
151
|
+
"5449":
|
152
|
+
message: 'Oops... Update action was not successfully executed'
|
153
|
+
type: 'error'
|
data/errors/fa.yml
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
fa:
|
2
|
+
success: "موفق."
|
3
|
+
failed: "نا موفق!"
|
4
|
+
respond:
|
5
|
+
success:
|
6
|
+
insert: '.درخواست با موفقیت درج شده است'
|
7
|
+
delete: '.درخواست با موفقیت پاک شده است'
|
8
|
+
update: '.درخواست با موفقیت ویرایش شده است'
|
9
|
+
|
10
|
+
failed:
|
11
|
+
insert: '.درخواست با موفقیت درج نشد'
|
12
|
+
delete: '.درخواست با موفقیت پاک نشد'
|
13
|
+
update: '.درخواست با موفقیت ویرایش نشد'
|
14
|
+
|
15
|
+
"1001":
|
16
|
+
message: '.درخواست مورد نظر پیدا نشده است'
|
17
|
+
type: 'error'
|
18
|
+
|
19
|
+
"1002":
|
20
|
+
message: '.کاربر مورد نظر موجود نیست'
|
21
|
+
type: 'error'
|
22
|
+
|
23
|
+
"1003":
|
24
|
+
message: '.نوع کاربری وارد نشده است'
|
25
|
+
type: 'error'
|
26
|
+
|
27
|
+
"1004":
|
28
|
+
message: '.ورودی مورد نظر تکراری است'
|
29
|
+
type: 'error'
|
30
|
+
|
31
|
+
"1005":
|
32
|
+
message: '.نقش کاربر مورد نظر تکراری است'
|
33
|
+
type: 'error'
|
34
|
+
|
35
|
+
"3001":
|
36
|
+
message: '.شما به سیستم وارد نشده اید'
|
37
|
+
type: 'error'
|
38
|
+
cat: 'auth'
|
39
|
+
short: 'not-logged-on'
|
40
|
+
|
41
|
+
"3002":
|
42
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
43
|
+
type: 'error'
|
44
|
+
cat: 'auth'
|
45
|
+
|
46
|
+
"3003":
|
47
|
+
messag: '.نشان شناسایی شما نامعتبر است'
|
48
|
+
type: 'error'
|
49
|
+
cat: 'auth'
|
50
|
+
|
51
|
+
"3004":
|
52
|
+
message: '.هیچ آژانسی به نشان شناسایی دسترسی ندارد'
|
53
|
+
type: 'error'
|
54
|
+
cat: 'auth'
|
55
|
+
|
56
|
+
"3005":
|
57
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
58
|
+
type: 'error'
|
59
|
+
cat: 'auth'
|
60
|
+
|
61
|
+
"3006":
|
62
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
63
|
+
type: 'error'
|
64
|
+
cat: 'auth'
|
65
|
+
|
66
|
+
"3007":
|
67
|
+
message: '.نشان شناسایی شما نمایش داده نمیشود'
|
68
|
+
type: 'error'
|
69
|
+
cat: 'auth'
|
70
|
+
|
71
|
+
"3008":
|
72
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
73
|
+
type: 'error'
|
74
|
+
cat: 'auth'
|
75
|
+
|
76
|
+
"3009":
|
77
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
78
|
+
type: 'error'
|
79
|
+
cat: 'auth'
|
80
|
+
|
81
|
+
"3010":
|
82
|
+
message: '.زمان استفاده از نشان شناسایی شما گذشته است'
|
83
|
+
type: 'error'
|
84
|
+
cat: 'auth'
|
85
|
+
|
86
|
+
"3011":
|
87
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
88
|
+
type: 'error'
|
89
|
+
cat: 'auth'
|
90
|
+
|
91
|
+
"3012":
|
92
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
93
|
+
type: 'error'
|
94
|
+
cat: 'auth'
|
95
|
+
|
96
|
+
"3013":
|
97
|
+
message: '.Payload معتبر نیست'
|
98
|
+
type: 'error'
|
99
|
+
cat: 'auth'
|
100
|
+
|
101
|
+
"3014":
|
102
|
+
message: '.Claim معتبر نیست'
|
103
|
+
type: 'error'
|
104
|
+
cat: 'auth'
|
105
|
+
|
106
|
+
"3015":
|
107
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
108
|
+
type: 'error'
|
109
|
+
cat: 'auth'
|
110
|
+
|
111
|
+
"5401":
|
112
|
+
message: '.شناسایی کاربر نامعتبر است'
|
113
|
+
type: 'error'
|
114
|
+
|
115
|
+
"5404":
|
116
|
+
message: '.صفحه درخواست شده پیدا نمیشود'
|
117
|
+
type: 'error'
|
118
|
+
|
119
|
+
"5405":
|
120
|
+
message: '.شما به درخواستی که داده اید دسترسی ندارید'
|
121
|
+
type: 'error'
|
122
|
+
|
123
|
+
"5406":
|
124
|
+
message: '.پارامترهایی که شما وارد کرده اید نا معتبر است'
|
125
|
+
type: 'error'
|
126
|
+
|
127
|
+
"5420":
|
128
|
+
message: '.خطای اعتبار سنجی'
|
129
|
+
type: 'error'
|
130
|
+
|
131
|
+
"5422":
|
132
|
+
message: '.نشان شناسایی شما نامعتبر است'
|
133
|
+
type: 'error'
|
134
|
+
|
135
|
+
"5445":
|
136
|
+
message: '.ارتباط با پایگاه داده مشکل دارد'
|
137
|
+
type: 'error'
|
138
|
+
|
139
|
+
"5448":
|
140
|
+
message: '.عملیات درج درست اجرا نشده است'
|
141
|
+
type: 'error'
|
142
|
+
|
143
|
+
"5447":
|
144
|
+
message: '.عملیات پاک کردن درست اجرا نشده است'
|
145
|
+
type: 'error'
|
146
|
+
|
147
|
+
"5449":
|
148
|
+
message: '.عملیات ویرایش درست اجرا نشده است'
|
149
|
+
type: 'error'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Josh
|
2
2
|
|
3
3
|
class Messages
|
4
4
|
|
@@ -8,24 +8,18 @@ module Anetwork
|
|
8
8
|
##
|
9
9
|
# initialize method
|
10
10
|
#
|
11
|
-
# @author Alireza Josheghani <
|
11
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
12
12
|
# @since 1 Dec 2016
|
13
13
|
# @return [Object]
|
14
14
|
# @param [String] lang
|
15
|
-
def initialize(lang =
|
16
|
-
|
17
|
-
|
18
|
-
if @lang != '' || @lang != nil
|
19
|
-
lang = @lang
|
20
|
-
end
|
21
|
-
|
22
|
-
@config = eval(File.open(__dir__ + "/errors/#{lang}.rb").read)
|
15
|
+
def initialize(lang = :en)
|
16
|
+
I18n.default_locale = lang
|
23
17
|
end
|
24
18
|
|
25
19
|
##
|
26
20
|
# Request succeeded and contains json result
|
27
21
|
#
|
28
|
-
# @author Alireza Josheghani <
|
22
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
29
23
|
# @since 1 Dec 2016
|
30
24
|
# @param [Object] data
|
31
25
|
# @return [Object]
|
@@ -38,13 +32,13 @@ module Anetwork
|
|
38
32
|
##
|
39
33
|
# Delete action is succeed
|
40
34
|
#
|
41
|
-
# @author Alireza Josheghani <
|
35
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
42
36
|
# @since 1 Dec 2016
|
43
37
|
# @param [String] message
|
44
38
|
# @return [Object]
|
45
39
|
def delete_succeeded(message = nil)
|
46
40
|
if message == nil
|
47
|
-
message =
|
41
|
+
message = I18n.t "respond.success.delete"
|
48
42
|
end
|
49
43
|
|
50
44
|
self.set_status_code(200)
|
@@ -55,13 +49,13 @@ module Anetwork
|
|
55
49
|
##
|
56
50
|
# Update action is succeed
|
57
51
|
#
|
58
|
-
# @author Alireza Josheghani <
|
52
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
59
53
|
# @since 1 Dec 2016
|
60
54
|
# @param [String] message
|
61
55
|
# @return [Object]
|
62
56
|
def update_succeeded(message = nil)
|
63
57
|
if message == nil
|
64
|
-
message =
|
58
|
+
message = I18n.t "respond.success.update"
|
65
59
|
end
|
66
60
|
|
67
61
|
self.set_status_code(200)
|
@@ -72,13 +66,13 @@ module Anetwork
|
|
72
66
|
##
|
73
67
|
# Insert action is succeed
|
74
68
|
#
|
75
|
-
# @author Alireza Josheghani <
|
69
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
76
70
|
# @since 1 Dec 2016
|
77
71
|
# @param [String] message
|
78
72
|
# @return [Object]
|
79
73
|
def insert_succeeded(message = nil)
|
80
74
|
if message == nil
|
81
|
-
message =
|
75
|
+
message = I18n.t "respond.success.insert"
|
82
76
|
end
|
83
77
|
|
84
78
|
self.set_status_code(200)
|
@@ -87,19 +81,19 @@ module Anetwork
|
|
87
81
|
end
|
88
82
|
|
89
83
|
##
|
90
|
-
# Delete action is
|
84
|
+
# Delete action is failed
|
91
85
|
#
|
92
|
-
# @author Alireza Josheghani <
|
86
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
93
87
|
# @since 1 Dec 2016
|
94
88
|
# @param [String] message
|
95
89
|
# @return [Object]
|
96
|
-
def
|
90
|
+
def delete_failed(message = nil)
|
97
91
|
if message == nil
|
98
|
-
message =
|
92
|
+
message = I18n.t "respond.failed.delete"
|
99
93
|
end
|
100
94
|
|
101
95
|
self.set_status_code(447)
|
102
|
-
.set_status_text('
|
96
|
+
.set_status_text('failed')
|
103
97
|
.set_error_code(5447)
|
104
98
|
.respond_with_message(message)
|
105
99
|
end
|
@@ -107,35 +101,35 @@ module Anetwork
|
|
107
101
|
##
|
108
102
|
# Update action is succeed
|
109
103
|
#
|
110
|
-
# @author Alireza Josheghani <
|
104
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
111
105
|
# @since 1 Dec 2016
|
112
106
|
# @param [String] message
|
113
107
|
# @return [Object]
|
114
|
-
def
|
108
|
+
def update_failed(message = nil)
|
115
109
|
if message == nil
|
116
|
-
message =
|
110
|
+
message = I18n.t "respond.failed.update"
|
117
111
|
end
|
118
112
|
|
119
113
|
self.set_status_code(449)
|
120
|
-
.set_status_text('
|
114
|
+
.set_status_text('failed')
|
121
115
|
.set_error_code(5449)
|
122
116
|
.respond_with_message(message)
|
123
117
|
end
|
124
118
|
|
125
119
|
##
|
126
|
-
# Insert action is
|
120
|
+
# Insert action is failed
|
127
121
|
#
|
128
|
-
# @author Alireza Josheghani <
|
122
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
129
123
|
# @since 1 Dec 2016
|
130
124
|
# @param [String] message
|
131
125
|
# @return [Object]
|
132
|
-
def
|
126
|
+
def insert_failed(message = nil)
|
133
127
|
if message == nil
|
134
|
-
message =
|
128
|
+
message = I18n.t "respond.failed.insert"
|
135
129
|
end
|
136
130
|
|
137
131
|
self.set_status_code(448)
|
138
|
-
.set_status_text('
|
132
|
+
.set_status_text('failed')
|
139
133
|
.set_error_code(5448)
|
140
134
|
.respond_with_message(message)
|
141
135
|
end
|
@@ -143,12 +137,12 @@ module Anetwork
|
|
143
137
|
##
|
144
138
|
# Database connection is refused
|
145
139
|
#
|
146
|
-
# @author Alireza Josheghani <
|
140
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
147
141
|
# @since 1 Dec 2016
|
148
142
|
# @return [Object]
|
149
143
|
def connection_refused
|
150
144
|
self.set_status_code(445)
|
151
|
-
.set_status_text('
|
145
|
+
.set_status_text('failed')
|
152
146
|
.set_error_code(5445)
|
153
147
|
.respond_with_message
|
154
148
|
end
|
@@ -156,12 +150,12 @@ module Anetwork
|
|
156
150
|
##
|
157
151
|
# Page requested is not found
|
158
152
|
#
|
159
|
-
# @author Alireza Josheghani <
|
153
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
160
154
|
# @since 1 Dec 2016
|
161
155
|
# @return [Object]
|
162
156
|
def not_found
|
163
157
|
self.set_status_code(404)
|
164
|
-
.set_status_text('
|
158
|
+
.set_status_text('failed')
|
165
159
|
.set_error_code(5404)
|
166
160
|
.respond_with_message
|
167
161
|
end
|
@@ -169,12 +163,12 @@ module Anetwork
|
|
169
163
|
##
|
170
164
|
# Wrong parameters are entered
|
171
165
|
#
|
172
|
-
# @author Alireza Josheghani <
|
166
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
173
167
|
# @since 1 Dec 2016
|
174
168
|
# @return [Object]
|
175
169
|
def wrong_parameters
|
176
170
|
self.set_status_code(406)
|
177
|
-
.set_status_text('
|
171
|
+
.set_status_text('failed')
|
178
172
|
.set_error_code(5406)
|
179
173
|
.respond_with_message
|
180
174
|
end
|
@@ -182,12 +176,12 @@ module Anetwork
|
|
182
176
|
##
|
183
177
|
# Method is not allowed
|
184
178
|
#
|
185
|
-
# @author Alireza Josheghani <
|
179
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
186
180
|
# @since 1 Dec 2016
|
187
181
|
# @return [Object]
|
188
182
|
def method_not_allowed
|
189
183
|
self.set_status_code(405)
|
190
|
-
.set_status_text('
|
184
|
+
.set_status_text('failed')
|
191
185
|
.set_error_code(5405)
|
192
186
|
.respond_with_message
|
193
187
|
end
|
@@ -195,12 +189,12 @@ module Anetwork
|
|
195
189
|
##
|
196
190
|
# There ara validation errors
|
197
191
|
#
|
198
|
-
# @author Alireza Josheghani <
|
192
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
199
193
|
# @since 1 Dec 2016
|
200
194
|
# @return [Object]
|
201
195
|
def validation_errors(message = nil)
|
202
196
|
self.set_status_code(420)
|
203
|
-
.set_status_text('
|
197
|
+
.set_status_text('failed')
|
204
198
|
.set_error_code(5420)
|
205
199
|
.respond_with_message(message)
|
206
200
|
end
|
@@ -208,12 +202,12 @@ module Anetwork
|
|
208
202
|
##
|
209
203
|
# The request field is not found
|
210
204
|
#
|
211
|
-
# @author Alireza Josheghani <
|
205
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
212
206
|
# @since 1 Dec 2016
|
213
207
|
# @return [Object]
|
214
208
|
def request_field_notfound
|
215
209
|
self.set_status_code(446)
|
216
|
-
.set_status_text('
|
210
|
+
.set_status_text('failed')
|
217
211
|
.set_error_code(1001)
|
218
212
|
.respond_with_message
|
219
213
|
end
|
@@ -221,12 +215,12 @@ module Anetwork
|
|
221
215
|
##
|
222
216
|
# The request field is duplicated
|
223
217
|
#
|
224
|
-
# @author Alireza Josheghani <
|
218
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
225
219
|
# @since 1 Dec 2016
|
226
220
|
# @return [Object]
|
227
221
|
def request_field_duplicated
|
228
222
|
self.set_status_code(400)
|
229
|
-
.set_status_text('
|
223
|
+
.set_status_text('failed')
|
230
224
|
.set_error_code(1004)
|
231
225
|
.respond_with_message
|
232
226
|
end
|
@@ -234,13 +228,13 @@ module Anetwork
|
|
234
228
|
##
|
235
229
|
# The error message
|
236
230
|
#
|
237
|
-
# @author Alireza Josheghani <
|
231
|
+
# @author Alireza Josheghani <josheghani.dev@gmail.com>
|
238
232
|
# @since 1 Dec 2016
|
239
233
|
# @param [Object] code
|
240
234
|
# @return [Object]
|
241
235
|
def error(code)
|
242
236
|
self.set_status_code(400)
|
243
|
-
.set_status_text('
|
237
|
+
.set_status_text('failed')
|
244
238
|
.set_error_code(code)
|
245
239
|
.respond_with_message
|
246
240
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Anetwork
|
1
|
+
module Josh
|
4
2
|
|
5
3
|
class Respond < Messages
|
6
4
|
|
@@ -24,7 +22,7 @@ module Anetwork
|
|
24
22
|
# @param [String] text
|
25
23
|
# @return [Object]
|
26
24
|
def set_status_text(text)
|
27
|
-
@text = text
|
25
|
+
@text = I18n.t text
|
28
26
|
self
|
29
27
|
end
|
30
28
|
|
@@ -46,7 +44,7 @@ module Anetwork
|
|
46
44
|
result['error'] = @error_code
|
47
45
|
end
|
48
46
|
|
49
|
-
result
|
47
|
+
{ :json => result, status: @code, headers: @headers }
|
50
48
|
end
|
51
49
|
|
52
50
|
##
|
@@ -54,10 +52,11 @@ module Anetwork
|
|
54
52
|
#
|
55
53
|
# @author Alireza Josheghani <a.josheghani@anetwork.ir>
|
56
54
|
# @since 1 Dec 2016
|
57
|
-
# @param [
|
55
|
+
# @param [array] data
|
58
56
|
# @return [Object]
|
59
57
|
def respond_with_result(data)
|
60
|
-
|
58
|
+
|
59
|
+
{ :json => { :status => @text, :result => data }, status: @code, headers: @headers }
|
61
60
|
end
|
62
61
|
|
63
62
|
##
|
@@ -69,7 +68,7 @@ module Anetwork
|
|
69
68
|
# @return [Object]
|
70
69
|
def set_error_code(error_code)
|
71
70
|
@error_code = error_code
|
72
|
-
@error =
|
71
|
+
@error = I18n.t "respond.#{error_code}"
|
73
72
|
self
|
74
73
|
end
|
75
74
|
|
data/respond.gemspec
CHANGED
@@ -5,19 +5,19 @@ require 'Respond/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'respond'
|
8
|
-
spec.version =
|
8
|
+
spec.version = Josh::Respond::VERSION
|
9
9
|
spec.authors = ['Alireza Josheghani']
|
10
|
-
spec.email = ['
|
10
|
+
spec.email = ['josheghani.dev@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'Easy peasy json response for ruby on rails!'
|
13
13
|
spec.description = 'This package is provided to be used on rails framework and it gives clean methods to handle json response with specific predetermined messages.'
|
14
|
-
spec.homepage = 'https://github.com/
|
15
|
-
spec.required_ruby_version = '>=
|
14
|
+
spec.homepage = 'https://github.com/iamalirezaj'
|
15
|
+
spec.required_ruby_version = '>= 2.4'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split($/)
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
-
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rake config', '~> 0'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: respond
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alireza Josheghani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,23 +25,23 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
28
|
+
name: rake config
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: This package is provided to be used on rails framework and it gives clean
|
42
42
|
methods to handle json response with specific predetermined messages.
|
43
43
|
email:
|
44
|
-
-
|
44
|
+
- josheghani.dev@gmail.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
@@ -52,13 +52,13 @@ files:
|
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
|
-
-
|
56
|
-
-
|
57
|
-
- lib/
|
58
|
-
- lib/
|
59
|
-
- lib/
|
55
|
+
- errors/en.yml
|
56
|
+
- errors/fa.yml
|
57
|
+
- lib/messages.rb
|
58
|
+
- lib/respond.rb
|
59
|
+
- lib/respond/version.rb
|
60
60
|
- respond.gemspec
|
61
|
-
homepage: https://github.com/
|
61
|
+
homepage: https://github.com/iamalirezaj
|
62
62
|
licenses:
|
63
63
|
- MIT
|
64
64
|
metadata: {}
|
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '2.4'
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.6.
|
81
|
+
rubygems_version: 2.6.14
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Easy peasy json response for ruby on rails!
|
data/lib/Respond/version.rb
DELETED
data/lib/errors/en.rb
DELETED
@@ -1,185 +0,0 @@
|
|
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
DELETED
@@ -1,179 +0,0 @@
|
|
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
|
-
}
|