Module: Hyperender

Defined in:
lib/hyperender.rb,
lib/hyperender/version.rb

Defined Under Namespace

Modules: Action

Constant Summary collapse

HATEOAS_MSG =
{
  100 => "Continue",
  101 => "Switching Protocols",
  200 => "OK",
  201 => "Created",
  202 => "Accepted",
  203 => "Non-Authoritative Information",
  204 => "No Content",
  205 => "Reset Content",
  206 => "Partial Content",
  300 => "Multiple Choices",
  301 => "Moved Permanently",
  302 => "Found",
  303 => "See Other",
  304 => "Not Modified",
  307 => "Temporary Redirect",
  308 => "Permanent Redirect",
  400 => "Bad Request",
  401 => "Unauthorized",
  403 => "Forbidden",
  404 => "Not Found",
  405 => "Method Not Allowed",
  406 => "Not Acceptable",
  407 => "Proxy Authentication Required",
  408 => "Request Timeout",
  409 => "Conflict",
  410 => "Gone",
  411 => "Length Required",
  412 => "Precondition Failed",
  413 => "Payload Too Large",
  414 => "URI Too Long",
  415 => "Unsupported Media Type",
  416 => "Range Not Satisfiable",
  417 => "Expectation Failed",
  426 => "Upgrade Required",
  428 => "Precondition Required",
  429 => "Too Many Requests",
  431 => "Request Header Fields Too Large",
  451 => "Unavailable For Legal Reasons",
  500 => "Internal Server Error",
  501 => "Not Implemented",
  502 => "Bad Gateway",
  503 => "Service Unavailable",
  504 => "Gateway Timeout",
  505 => "HTTP Version Not Supported",
  511 => "Network Authentication Required"
}
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.generated_data(data, errors) ⇒ Object



69
70
71
72
# File 'lib/hyperender.rb', line 69

def self.generated_data data, errors
  data[:errors] = errors unless errors.blank?
  data
end

.generated_headers(request) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hyperender.rb', line 74

def self.generated_headers request
  enviroment = [
    #Server specific variables
    # "SERVER_SOFTWARE", "SERVER_NAME", "GATEWAY_INTERFACE",
    #Request specific variables
   "SERVER_PROTOCOL", "SERVER_PORT", "REQUEST_METHOD", "PATH_INFO", "PATH_TRANSLATED", "SCRIPT_NAME", "QUERY_STRING", "REMOTE_HOST", "REMOTE_ADDR", "AUTH_TYPE", "REMOTE_USER", "REMOTE_IDENT", "CONTENT_TYPE", "CONTENT_LENGTH", "HTTP_USER_AGENT", "X_CUSTOM_HEADER"
  ]
  headers = {}
  enviroment.each do |env|
    attribute = request.headers[env]
    headers[env.downcase] = attribute unless attribute.blank?
  end
  headers
end

.render(data, errors, parameters, message, status, request) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hyperender.rb', line 53

def self.render data, errors, parameters, message, status, request
  {
    data:               (Hyperender.generated_data data, errors),
    query_parameters:   parameters,
    response: {
      message:          message,
      status:           status
    },
    request: {
      url:              request.original_url,
      method:           request.request_method,
      headers:          (Hyperender.generated_headers request),
    }
  }
end