Messages.request_field_notfound()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
1
module Anetwork
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 <[email protected]>
12
    # @since 1 Dec 2016
13
    # @return [Object]
14
    # @param [String] lang
15
    def initialize(lang = 'en')
16
      @lang = I18n.locale
17
18
      if @lang != '' || @lang != nil
19
        lang = @lang
20
      end
21
22
      @config = eval(File.open(__dir__ + "/errors/#{lang}.rb").read)
0 ignored issues
show
Security introduced by
The use of eval poses a security risk, because eval will execute arbitratry code. Consider using another way to achieve your goal.
Loading history...
Coding Style introduced by
Consider using the block version of File.open. It does automatic clean-up once the block is finished.
Loading history...
23
    end
24
25
    ##
26
    # Request succeeded and contains json result
27
    #
28
    # @author Alireza Josheghani <[email protected]>
29
    # @since 1 Dec 2016
30
    # @param [Object] data
31
    # @return [Object]
32
    def succeed(data)
33
      self.set_status_code(200)
34
          .set_status_text('success')
35
          .respond_with_result(data)
36
    end
37
38
    ##
39
    # Delete action is succeed
40
    #
41
    # @author Alireza Josheghani <[email protected]>
42
    # @since 1 Dec 2016
43
    # @param [String] message
44
    # @return [Object]
45
    def delete_succeeded(message = nil)
46
      if message == nil
47
        message = @config[:success][:delete]
48
      end
49
50
      self.set_status_code(200)
51
          .set_status_text('success')
52
          .respond_with_message(message)
53
    end
54
55
    ##
56
    # Update action is succeed
57
    #
58
    # @author Alireza Josheghani <[email protected]>
59
    # @since 1 Dec 2016
60
    # @param [String] message
61
    # @return [Object]
62
    def update_succeeded(message = nil)
63
      if message == nil
64
        message = @config[:success][:update]
65
      end
66
67
      self.set_status_code(200)
68
          .set_status_text('success')
69
          .respond_with_message(message)
70
    end
71
72
    ##
73
    # Insert action is succeed
74
    #
75
    # @author Alireza Josheghani <[email protected]>
76
    # @since 1 Dec 2016
77
    # @param [String] message
78
    # @return [Object]
79
    def insert_succeeded(message = nil)
80
      if message == nil
81
        message = @config[:success][:insert]
82
      end
83
84
      self.set_status_code(200)
85
          .set_status_text('success')
86
          .respond_with_message(message)
87
    end
88
89
    ##
90
    # Delete action is faild
91
    #
92
    # @author Alireza Josheghani <[email protected]>
93
    # @since 1 Dec 2016
94
    # @param [String] message
95
    # @return [Object]
96 View Code Duplication
    def delete_faild(message = nil)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
97
      if message == nil
98
        message = @config[:fail][:delete]
99
      end
100
101
      self.set_status_code(447)
102
          .set_status_text('fail')
103
          .set_error_code(5447)
104
          .respond_with_message(message)
105
    end
106
107
    ##
108
    # Update action is succeed
109
    #
110
    # @author Alireza Josheghani <[email protected]>
111
    # @since 1 Dec 2016
112
    # @param [String] message
113
    # @return [Object]
114 View Code Duplication
    def update_faild(message = nil)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
115
      if message == nil
116
        message = @config[:fail][:update]
117
      end
118
119
      self.set_status_code(449)
120
          .set_status_text('fail')
121
          .set_error_code(5449)
122
          .respond_with_message(message)
123
    end
124
125
    ##
126
    # Insert action is faild
127
    #
128
    # @author Alireza Josheghani <[email protected]>
129
    # @since 1 Dec 2016
130
    # @param [String] message
131
    # @return [Object]
132 View Code Duplication
    def insert_faild(message = nil)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
133
      if message == nil
134
        message = @config[:fail][:insert]
135
      end
136
137
      self.set_status_code(448)
138
          .set_status_text('fail')
139
          .set_error_code(5448)
140
          .respond_with_message(message)
141
    end
142
143
    ##
144
    # Database connection is refused
145
    #
146
    # @author Alireza Josheghani <[email protected]>
147
    # @since 1 Dec 2016
148
    # @return [Object]
149
    def connection_refused
150
      self.set_status_code(445)
151
          .set_status_text('fail')
152
          .set_error_code(5445)
153
          .respond_with_message
154
    end
155
156
    ##
157
    # Page requested is not found
158
    #
159
    # @author Alireza Josheghani <[email protected]>
160
    # @since 1 Dec 2016
161
    # @return [Object]
162
    def not_found
163
      self.set_status_code(404)
164
          .set_status_text('fail')
165
          .set_error_code(5404)
166
          .respond_with_message
167
    end
168
169
    ##
170
    # Wrong parameters are entered
171
    #
172
    # @author Alireza Josheghani <[email protected]>
173
    # @since 1 Dec 2016
174
    # @return [Object]
175
    def wrong_parameters
176
      self.set_status_code(406)
177
          .set_status_text('fail')
178
          .set_error_code(5406)
179
          .respond_with_message
180
    end
181
182
    ##
183
    # Method is not allowed
184
    #
185
    # @author Alireza Josheghani <[email protected]>
186
    # @since 1 Dec 2016
187
    # @return [Object]
188
    def method_not_allowed
189
      self.set_status_code(405)
190
          .set_status_text('fail')
191
          .set_error_code(5405)
192
          .respond_with_message
193
    end
194
195
    ##
196
    # There ara validation errors
197
    #
198
    # @author Alireza Josheghani <[email protected]>
199
    # @since 1 Dec 2016
200
    # @return [Object]
201
    def validation_errors(message = nil)
202
      self.set_status_code(420)
203
          .set_status_text('fail')
204
          .set_error_code(5420)
205
          .respond_with_message(message)
206
    end
207
208
    ##
209
    # The request field is not found
210
    #
211
    # @author Alireza Josheghani <[email protected]>
212
    # @since 1 Dec 2016
213
    # @return [Object]
214
    def request_field_notfound
215
      self.set_status_code(446)
216
          .set_status_text('fail')
217
          .set_error_code(1001)
218
          .respond_with_message
219
    end
220
221
    ##
222
    # The request field is duplicated
223
    #
224
    # @author Alireza Josheghani <[email protected]>
225
    # @since 1 Dec 2016
226
    # @return [Object]
227
    def request_field_duplicated
228
      self.set_status_code(400)
229
          .set_status_text('fail')
230
          .set_error_code(1004)
231
          .respond_with_message
232
    end
233
234
    ##
235
    # The error message
236
    #
237
    # @author Alireza Josheghani <[email protected]>
238
    # @since 1 Dec 2016
239
    # @param [Object] code
240
    # @return [Object]
241
    def error(code)
242
      self.set_status_code(400)
243
          .set_status_text('fail')
244
          .set_error_code(code)
245
          .respond_with_message
246
    end
247
248
  end
249
250
end
251
252