Module: Sana::ResponseHelper

Defined in:
lib/sana.rb

Overview

SHIORI Response struct build helper

Class Method Summary collapse

Class Method Details

.bad_requestOpenStruct

400 Bad Request

Returns:

  • (OpenStruct)

    SHIORI Response struct



114
115
116
117
118
# File 'lib/sana.rb', line 114

def bad_request
  OpenStruct.new({
    code: 400,
  })
end

.internal_server_errorOpenStruct

500 Internal Server Error

Returns:

  • (OpenStruct)

    SHIORI Response struct



122
123
124
125
126
# File 'lib/sana.rb', line 122

def internal_server_error
  OpenStruct.new({
    code: 500,
  })
end

.no_contentOpenStruct

204 No Content

Returns:

  • (OpenStruct)

    SHIORI Response struct



106
107
108
109
110
# File 'lib/sana.rb', line 106

def no_content
  OpenStruct.new({
    code: 204,
  })
end

.ok(value = nil, to = nil) ⇒ OpenStruct

normal response (200 OK or 204 No Content)

Parameters:

  • value (String) (defaults to: nil)

    Value header content

  • to (String) (defaults to: nil)

    Reference0 header content (for communication)

Returns:

  • (OpenStruct)

    SHIORI Response struct



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/sana.rb', line 89

def ok(value = nil, to = nil)
  if value.to_s.size != 0
    response = OpenStruct.new({
      code: 200,
      Value: value.to_s,
    })
    if to
      response.Reference0 = to.to_s
    end
    response
  else
    no_content
  end
end

.responseOpenStruct

empty response struct

Returns:

  • (OpenStruct)

    empty SHIORI Response struct



81
82
83
# File 'lib/sana.rb', line 81

def response
  OpenStruct.new
end