Class: Anetwork::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/Messages.rb

Direct Known Subclasses

Respond

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lang = 'en') ⇒ Object

initialize method

Parameters:

  • lang (String) (defaults to: 'en')

Since:

  • 1 Dec 2016



15
16
17
18
19
20
21
22
23
# File 'lib/Messages.rb', line 15

def initialize(lang = 'en')
  @lang = I18n.locale

  if @lang != '' || @lang != nil
    lang = @lang
  end

  @config = eval(File.open(__dir__ + "/errors/#{lang}.rb").read)
end

Instance Attribute Details

#codeObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def code
  @code
end

#configObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def config
  @config
end

#error(code) ⇒ Object

The error message

Parameters:

  • code (Object)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



6
7
8
# File 'lib/Messages.rb', line 6

def error
  @error
end

#error_codeObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def error_code
  @error_code
end

#headersObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def headers
  @headers
end

#langObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def lang
  @lang
end

#textObject

setter and getter varibules



6
7
8
# File 'lib/Messages.rb', line 6

def text
  @text
end

Instance Method Details

#connection_refusedObject

Database connection is refused

Returns:

  • (Object)

Since:

  • 1 Dec 2016



149
150
151
152
153
154
# File 'lib/Messages.rb', line 149

def connection_refused
  self.set_status_code(445)
      .set_status_text('fail')
      .set_error_code(5445)
      .respond_with_message
end

#delete_faild(message = nil) ⇒ Object

Delete action is faild

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



96
97
98
99
100
101
102
103
104
105
# File 'lib/Messages.rb', line 96

def delete_faild(message = nil)
  if message == nil
    message = @config[:fail][:delete]
  end

  self.set_status_code(447)
      .set_status_text('fail')
      .set_error_code(5447)
      .respond_with_message(message)
end

#delete_succeeded(message = nil) ⇒ Object

Delete action is succeed

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



45
46
47
48
49
50
51
52
53
# File 'lib/Messages.rb', line 45

def delete_succeeded(message = nil)
  if message == nil
    message = @config[:success][:delete]
  end

  self.set_status_code(200)
      .set_status_text('success')
      .respond_with_message(message)
end

#insert_faild(message = nil) ⇒ Object

Insert action is faild

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



132
133
134
135
136
137
138
139
140
141
# File 'lib/Messages.rb', line 132

def insert_faild(message = nil)
  if message == nil
    message = @config[:fail][:insert]
  end

  self.set_status_code(448)
      .set_status_text('fail')
      .set_error_code(5448)
      .respond_with_message(message)
end

#insert_succeeded(message = nil) ⇒ Object

Insert action is succeed

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



79
80
81
82
83
84
85
86
87
# File 'lib/Messages.rb', line 79

def insert_succeeded(message = nil)
  if message == nil
    message = @config[:success][:insert]
  end

  self.set_status_code(200)
      .set_status_text('success')
      .respond_with_message(message)
end

#method_not_allowedObject

Method is not allowed

Returns:

  • (Object)

Since:

  • 1 Dec 2016



188
189
190
191
192
193
# File 'lib/Messages.rb', line 188

def method_not_allowed
  self.set_status_code(405)
      .set_status_text('fail')
      .set_error_code(5405)
      .respond_with_message
end

#not_foundObject

Page requested is not found

Returns:

  • (Object)

Since:

  • 1 Dec 2016



162
163
164
165
166
167
# File 'lib/Messages.rb', line 162

def not_found
  self.set_status_code(404)
      .set_status_text('fail')
      .set_error_code(5404)
      .respond_with_message
end

#request_field_duplicatedObject

The request field is duplicated

Returns:

  • (Object)

Since:

  • 1 Dec 2016



227
228
229
230
231
232
# File 'lib/Messages.rb', line 227

def request_field_duplicated
  self.set_status_code(400)
      .set_status_text('fail')
      .set_error_code(1004)
      .respond_with_message
end

#request_field_notfoundObject

The request field is not found

Returns:

  • (Object)

Since:

  • 1 Dec 2016



214
215
216
217
218
219
# File 'lib/Messages.rb', line 214

def request_field_notfound
  self.set_status_code(446)
      .set_status_text('fail')
      .set_error_code(1001)
      .respond_with_message
end

#succeed(data) ⇒ Object

Request succeeded and contains json result

Parameters:

  • data (Object)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



32
33
34
35
36
# File 'lib/Messages.rb', line 32

def succeed(data)
  self.set_status_code(200)
      .set_status_text('success')
      .respond_with_result(data)
end

#update_faild(message = nil) ⇒ Object

Update action is succeed

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



114
115
116
117
118
119
120
121
122
123
# File 'lib/Messages.rb', line 114

def update_faild(message = nil)
  if message == nil
    message = @config[:fail][:update]
  end

  self.set_status_code(449)
      .set_status_text('fail')
      .set_error_code(5449)
      .respond_with_message(message)
end

#update_succeeded(message = nil) ⇒ Object

Update action is succeed

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Object)

Since:

  • 1 Dec 2016



62
63
64
65
66
67
68
69
70
# File 'lib/Messages.rb', line 62

def update_succeeded(message = nil)
  if message == nil
    message = @config[:success][:update]
  end

  self.set_status_code(200)
      .set_status_text('success')
      .respond_with_message(message)
end

#validation_errors(message = nil) ⇒ Object

There ara validation errors

Returns:

  • (Object)

Since:

  • 1 Dec 2016



201
202
203
204
205
206
# File 'lib/Messages.rb', line 201

def validation_errors(message = nil)
  self.set_status_code(420)
      .set_status_text('fail')
      .set_error_code(5420)
      .respond_with_message(message)
end

#wrong_parametersObject

Wrong parameters are entered

Returns:

  • (Object)

Since:

  • 1 Dec 2016



175
176
177
178
179
180
# File 'lib/Messages.rb', line 175

def wrong_parameters
  self.set_status_code(406)
      .set_status_text('fail')
      .set_error_code(5406)
      .respond_with_message
end