respond 0.1.4 → 0.1.5

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: bf1fc6471fc63f4989a6edf891d352844cabea57
4
- data.tar.gz: e64b04af2becb0aebaa99bb879332896ad0f93f3
3
+ metadata.gz: 9c85bec1fe3de4c10068a71abb5de38a2934dabd
4
+ data.tar.gz: 2746ca1b1abcca6c7d8fd39901ce0ca402a4d222
5
5
  SHA512:
6
- metadata.gz: 0f6d133da8d33e2fd423ff6e42a5ff80f8e1ad86e7b87dcf7ffcd036c07a7c5ffaeee17b49f2b6cc3287512d03f18afdec8788f7b906a1ee60214b2f2736e681
7
- data.tar.gz: e78d207002642ffb997ecae3a425844c551bab0f015a7de25abd49780022bbb54df4af430aeb9d0ad181b179a5dfbca04a8ae9013042341c4e0e50d889adb508
6
+ metadata.gz: 997e419feb8f5db16b499688ce9adb3bdc4230dfa0f178931fface53c552bfe9e05f83040df43e9bf9cf4dc31f32f6b27644e7b62c268d417b8fa4ff16245bb7
7
+ data.tar.gz: b1f83bc604c7114de85011e12b0685eaad176dcc96883a24322e37b295396e0ff2bf19399377621b5aa1e28a14c0cf3880073b2e1b59eb8eed1fd2a9c606d483
@@ -1,5 +1,246 @@
1
1
  module Josh
2
2
 
3
+ class Messages
4
+
5
+ # setter and getter varibules
6
+ attr_accessor :code , :text , :error , :error_code , :headers , :lang , :config
7
+
8
+ ##
9
+ # initialize method
10
+ #
11
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
12
+ # @since 1 Dec 2016
13
+ # @return [Object]
14
+ # @param [String] lang
15
+ def initialize(lang = :en)
16
+ I18n.default_locale = lang
17
+ end
18
+
19
+ ##
20
+ # Request succeeded and contains json result
21
+ #
22
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
23
+ # @since 1 Dec 2016
24
+ # @param [Object] data
25
+ # @return [Object]
26
+ def succeed(data)
27
+ self.set_status_code(200)
28
+ .set_status_text('success')
29
+ .respond_with_result(data)
30
+ end
31
+
32
+ ##
33
+ # Delete action is succeed
34
+ #
35
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
36
+ # @since 1 Dec 2016
37
+ # @param [String] message
38
+ # @return [Object]
39
+ def delete_succeeded(message = nil)
40
+ if message == nil
41
+ message = I18n.t "respond.success.delete"
42
+ end
43
+
44
+ self.set_status_code(200)
45
+ .set_status_text('success')
46
+ .respond_with_message(message)
47
+ end
48
+
49
+ ##
50
+ # Update action is succeed
51
+ #
52
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
53
+ # @since 1 Dec 2016
54
+ # @param [String] message
55
+ # @return [Object]
56
+ def update_succeeded(message = nil)
57
+ if message == nil
58
+ message = I18n.t "respond.success.update"
59
+ end
60
+
61
+ self.set_status_code(200)
62
+ .set_status_text('success')
63
+ .respond_with_message(message)
64
+ end
65
+
66
+ ##
67
+ # Insert action is succeed
68
+ #
69
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
70
+ # @since 1 Dec 2016
71
+ # @param [String] message
72
+ # @return [Object]
73
+ def insert_succeeded(message = nil)
74
+ if message == nil
75
+ message = I18n.t "respond.success.insert"
76
+ end
77
+
78
+ self.set_status_code(200)
79
+ .set_status_text('success')
80
+ .respond_with_message(message)
81
+ end
82
+
83
+ ##
84
+ # Delete action is failed
85
+ #
86
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
87
+ # @since 1 Dec 2016
88
+ # @param [String] message
89
+ # @return [Object]
90
+ def delete_failed(message = nil)
91
+ if message == nil
92
+ message = I18n.t "respond.failed.delete"
93
+ end
94
+
95
+ self.set_status_code(447)
96
+ .set_status_text('failed')
97
+ .set_error_code(5447)
98
+ .respond_with_message(message)
99
+ end
100
+
101
+ ##
102
+ # Update action is succeed
103
+ #
104
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
105
+ # @since 1 Dec 2016
106
+ # @param [String] message
107
+ # @return [Object]
108
+ def update_failed(message = nil)
109
+ if message == nil
110
+ message = I18n.t "respond.failed.update"
111
+ end
112
+
113
+ self.set_status_code(449)
114
+ .set_status_text('failed')
115
+ .set_error_code(5449)
116
+ .respond_with_message(message)
117
+ end
118
+
119
+ ##
120
+ # Insert action is failed
121
+ #
122
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
123
+ # @since 1 Dec 2016
124
+ # @param [String] message
125
+ # @return [Object]
126
+ def insert_failed(message = nil)
127
+ if message == nil
128
+ message = I18n.t "respond.failed.insert"
129
+ end
130
+
131
+ self.set_status_code(448)
132
+ .set_status_text('failed')
133
+ .set_error_code(5448)
134
+ .respond_with_message(message)
135
+ end
136
+
137
+ ##
138
+ # Database connection is refused
139
+ #
140
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
141
+ # @since 1 Dec 2016
142
+ # @return [Object]
143
+ def connection_refused
144
+ self.set_status_code(445)
145
+ .set_status_text('failed')
146
+ .set_error_code(5445)
147
+ .respond_with_message
148
+ end
149
+
150
+ ##
151
+ # Page requested is not found
152
+ #
153
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
154
+ # @since 1 Dec 2016
155
+ # @return [Object]
156
+ def not_found
157
+ self.set_status_code(404)
158
+ .set_status_text('failed')
159
+ .set_error_code(5404)
160
+ .respond_with_message
161
+ end
162
+
163
+ ##
164
+ # Wrong parameters are entered
165
+ #
166
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
167
+ # @since 1 Dec 2016
168
+ # @return [Object]
169
+ def wrong_parameters
170
+ self.set_status_code(406)
171
+ .set_status_text('failed')
172
+ .set_error_code(5406)
173
+ .respond_with_message
174
+ end
175
+
176
+ ##
177
+ # Method is not allowed
178
+ #
179
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
180
+ # @since 1 Dec 2016
181
+ # @return [Object]
182
+ def method_not_allowed
183
+ self.set_status_code(405)
184
+ .set_status_text('failed')
185
+ .set_error_code(5405)
186
+ .respond_with_message
187
+ end
188
+
189
+ ##
190
+ # There ara validation errors
191
+ #
192
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
193
+ # @since 1 Dec 2016
194
+ # @return [Object]
195
+ def validation_errors(message = nil)
196
+ self.set_status_code(420)
197
+ .set_status_text('failed')
198
+ .set_error_code(5420)
199
+ .respond_with_message(message)
200
+ end
201
+
202
+ ##
203
+ # The request field is not found
204
+ #
205
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
206
+ # @since 1 Dec 2016
207
+ # @return [Object]
208
+ def request_field_notfound
209
+ self.set_status_code(446)
210
+ .set_status_text('failed')
211
+ .set_error_code(1001)
212
+ .respond_with_message
213
+ end
214
+
215
+ ##
216
+ # The request field is duplicated
217
+ #
218
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
219
+ # @since 1 Dec 2016
220
+ # @return [Object]
221
+ def request_field_duplicated
222
+ self.set_status_code(400)
223
+ .set_status_text('failed')
224
+ .set_error_code(1004)
225
+ .respond_with_message
226
+ end
227
+
228
+ ##
229
+ # The error message
230
+ #
231
+ # @author Alireza Josheghani <josheghani.dev@gmail.com>
232
+ # @since 1 Dec 2016
233
+ # @param [Object] code
234
+ # @return [Object]
235
+ def error(code)
236
+ self.set_status_code(400)
237
+ .set_status_text('failed')
238
+ .set_error_code(code)
239
+ .respond_with_message
240
+ end
241
+
242
+ end
243
+
3
244
  class Respond < Messages
4
245
 
5
246
  ##
@@ -1,5 +1,5 @@
1
1
  module Josh
2
2
  class Respond
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
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.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alireza Josheghani
@@ -54,7 +54,6 @@ files:
54
54
  - Rakefile
55
55
  - errors/en.yml
56
56
  - errors/fa.yml
57
- - lib/messages.rb
58
57
  - lib/respond.rb
59
58
  - lib/respond/version.rb
60
59
  - respond.gemspec
@@ -1,245 +0,0 @@
1
- module Josh
2
-
3
- class Messages
4
-
5
- # setter and getter varibules
6
- attr_accessor :code , :text , :error , :error_code , :headers , :lang , :config
7
-
8
- ##
9
- # initialize method
10
- #
11
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
12
- # @since 1 Dec 2016
13
- # @return [Object]
14
- # @param [String] lang
15
- def initialize(lang = :en)
16
- I18n.default_locale = lang
17
- end
18
-
19
- ##
20
- # Request succeeded and contains json result
21
- #
22
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
23
- # @since 1 Dec 2016
24
- # @param [Object] data
25
- # @return [Object]
26
- def succeed(data)
27
- self.set_status_code(200)
28
- .set_status_text('success')
29
- .respond_with_result(data)
30
- end
31
-
32
- ##
33
- # Delete action is succeed
34
- #
35
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
36
- # @since 1 Dec 2016
37
- # @param [String] message
38
- # @return [Object]
39
- def delete_succeeded(message = nil)
40
- if message == nil
41
- message = I18n.t "respond.success.delete"
42
- end
43
-
44
- self.set_status_code(200)
45
- .set_status_text('success')
46
- .respond_with_message(message)
47
- end
48
-
49
- ##
50
- # Update action is succeed
51
- #
52
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
53
- # @since 1 Dec 2016
54
- # @param [String] message
55
- # @return [Object]
56
- def update_succeeded(message = nil)
57
- if message == nil
58
- message = I18n.t "respond.success.update"
59
- end
60
-
61
- self.set_status_code(200)
62
- .set_status_text('success')
63
- .respond_with_message(message)
64
- end
65
-
66
- ##
67
- # Insert action is succeed
68
- #
69
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
70
- # @since 1 Dec 2016
71
- # @param [String] message
72
- # @return [Object]
73
- def insert_succeeded(message = nil)
74
- if message == nil
75
- message = I18n.t "respond.success.insert"
76
- end
77
-
78
- self.set_status_code(200)
79
- .set_status_text('success')
80
- .respond_with_message(message)
81
- end
82
-
83
- ##
84
- # Delete action is failed
85
- #
86
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
87
- # @since 1 Dec 2016
88
- # @param [String] message
89
- # @return [Object]
90
- def delete_failed(message = nil)
91
- if message == nil
92
- message = I18n.t "respond.failed.delete"
93
- end
94
-
95
- self.set_status_code(447)
96
- .set_status_text('failed')
97
- .set_error_code(5447)
98
- .respond_with_message(message)
99
- end
100
-
101
- ##
102
- # Update action is succeed
103
- #
104
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
105
- # @since 1 Dec 2016
106
- # @param [String] message
107
- # @return [Object]
108
- def update_failed(message = nil)
109
- if message == nil
110
- message = I18n.t "respond.failed.update"
111
- end
112
-
113
- self.set_status_code(449)
114
- .set_status_text('failed')
115
- .set_error_code(5449)
116
- .respond_with_message(message)
117
- end
118
-
119
- ##
120
- # Insert action is failed
121
- #
122
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
123
- # @since 1 Dec 2016
124
- # @param [String] message
125
- # @return [Object]
126
- def insert_failed(message = nil)
127
- if message == nil
128
- message = I18n.t "respond.failed.insert"
129
- end
130
-
131
- self.set_status_code(448)
132
- .set_status_text('failed')
133
- .set_error_code(5448)
134
- .respond_with_message(message)
135
- end
136
-
137
- ##
138
- # Database connection is refused
139
- #
140
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
141
- # @since 1 Dec 2016
142
- # @return [Object]
143
- def connection_refused
144
- self.set_status_code(445)
145
- .set_status_text('failed')
146
- .set_error_code(5445)
147
- .respond_with_message
148
- end
149
-
150
- ##
151
- # Page requested is not found
152
- #
153
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
154
- # @since 1 Dec 2016
155
- # @return [Object]
156
- def not_found
157
- self.set_status_code(404)
158
- .set_status_text('failed')
159
- .set_error_code(5404)
160
- .respond_with_message
161
- end
162
-
163
- ##
164
- # Wrong parameters are entered
165
- #
166
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
167
- # @since 1 Dec 2016
168
- # @return [Object]
169
- def wrong_parameters
170
- self.set_status_code(406)
171
- .set_status_text('failed')
172
- .set_error_code(5406)
173
- .respond_with_message
174
- end
175
-
176
- ##
177
- # Method is not allowed
178
- #
179
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
180
- # @since 1 Dec 2016
181
- # @return [Object]
182
- def method_not_allowed
183
- self.set_status_code(405)
184
- .set_status_text('failed')
185
- .set_error_code(5405)
186
- .respond_with_message
187
- end
188
-
189
- ##
190
- # There ara validation errors
191
- #
192
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
193
- # @since 1 Dec 2016
194
- # @return [Object]
195
- def validation_errors(message = nil)
196
- self.set_status_code(420)
197
- .set_status_text('failed')
198
- .set_error_code(5420)
199
- .respond_with_message(message)
200
- end
201
-
202
- ##
203
- # The request field is not found
204
- #
205
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
206
- # @since 1 Dec 2016
207
- # @return [Object]
208
- def request_field_notfound
209
- self.set_status_code(446)
210
- .set_status_text('failed')
211
- .set_error_code(1001)
212
- .respond_with_message
213
- end
214
-
215
- ##
216
- # The request field is duplicated
217
- #
218
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
219
- # @since 1 Dec 2016
220
- # @return [Object]
221
- def request_field_duplicated
222
- self.set_status_code(400)
223
- .set_status_text('failed')
224
- .set_error_code(1004)
225
- .respond_with_message
226
- end
227
-
228
- ##
229
- # The error message
230
- #
231
- # @author Alireza Josheghani <josheghani.dev@gmail.com>
232
- # @since 1 Dec 2016
233
- # @param [Object] code
234
- # @return [Object]
235
- def error(code)
236
- self.set_status_code(400)
237
- .set_status_text('failed')
238
- .set_error_code(code)
239
- .respond_with_message
240
- end
241
-
242
- end
243
-
244
- end
245
-