Module: Jsender::Json

Extended by:
Json
Included in:
Json
Defined in:
lib/jsender/json.rb

Instance Method Summary collapse

Instance Method Details

#error(message: "An error has occurred") ⇒ Object



7
8
9
10
11
12
# File 'lib/jsender/json.rb', line 7

def error(message: "An error has occurred")
  {
    'status' => 'error',
    'message' => message
  }.to_json
end

#failure(message: "A failure has occurred", data: nil) ⇒ Object



14
15
16
17
18
19
# File 'lib/jsender/json.rb', line 14

def failure(message: "A failure has occurred", data: nil)
  {
    'status' => 'fail',
    'data' => data || { 'message' => message }
  }.to_json
end

#success(data: nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/jsender/json.rb', line 21

def success(data: nil)
  {
    'status' => 'success',
    'data' => data
  }.to_json
end