class Siresta::Response

Public Class Methods

_error(s, msg) click to toggle source

add error to state

# File lib/siresta/response.rb, line 56
def self._error(s, msg)
  s.clone(status: ResponseError(msg))
end
_on_done(s, &b) click to toggle source

call block with error state if done

# File lib/siresta/response.rb, line 66
def self._on_done(s, &b)
  b[_error(s, 'cannot continue when done')] \
    if s.status.is_a? ResponseDone
end
_on_empty(s, &b) click to toggle source

call block with error state if empty

# File lib/siresta/response.rb, line 72
def self._on_empty(s, &b)
  b[_error(s, 'cannot use empty body')] \
    if s.response.data.is_a? ResponseEmpty
end
_on_error(s, &b) click to toggle source

call block with state if error (to short-circuit)

# File lib/siresta/response.rb, line 61
def self._on_error(s, &b)
  b[s] if s.status.is_a? ResponseError
end
_on_stream(s, &b) click to toggle source

call block with error state if stream

# File lib/siresta/response.rb, line 78
def self._on_stream(s, &b)
  b[_error(s, 'cannot use body response')] \
    if s.response.data.is_a? ResponseStream
end
authorize(handler) click to toggle source

authorization

# File lib/siresta/response.rb, line 131
def self.authorize(handler)
  # TODO
end
choose_request_format(handler, formats) click to toggle source

convert request body from appropriate format

# File lib/siresta/response.rb, line 153
def self.choose_request_format(handler, formats)
  modify -> s {
    _on_error(s)  { |t| return t }
    _on_done(s)   { |t| return t }
    b = s.api_obj.convert_from(handler, formats, s.request.body)
    s.clone(request: s.request.clone(body: b))
  }
end
choose_response_format(handler, formats) click to toggle source

convert response body to appropriate format

# File lib/siresta/response.rb, line 163
def self.choose_response_format(handler, formats)
  modify -> s {
    _on_error(s)  { |t| return t }
    _on_done(s)   { |t| return t }
    _on_empty(s)  { |t| return t }
    _on_stream(s) { |t| return t }
    b = s.api_obj.convert_to(handler, formats, s.response.data.data)
    s.clone(response: s.response.clone(data: ResponseBody(b)))
  }
end
convert_params(handler) click to toggle source

convert parameters

# File lib/siresta/response.rb, line 136
def self.convert_params(handler)
  # TODO
end
error(msg) click to toggle source

error!

# File lib/siresta/response.rb, line 112
def self.error(msg)
  modify { |s| _error s, msg }
end
get_data(k, &b) click to toggle source

get atom data

# File lib/siresta/response.rb, line 121
def self.get_data(k, &b)
  x = get >> -> s { mreturn s.api_obj.data[k]._ }; b ? x >> b : x
end
ok(body, headers = {}, status = 200) click to toggle source

everything ok

# File lib/siresta/response.rb, line 86
def self.ok(body, headers = {}, status = 200)
  modify -> s {
    _on_error(s)  { |t| return t }
    _on_done(s)   { |t| return t }
    _on_stream(s) { |t| return t }
    s.clone(
      response: s.response.clone(
        status: status, headers: s.response.headers.merge(headers),
        data: ResponseBody(body)
      ),
      status: ResponseContinue()
    )
  }
end
set_data(k, v) click to toggle source

set atom data

# File lib/siresta/response.rb, line 126
def self.set_data(k, v)
  get >> -> s { s.api_obj.data[k].swap! { |_| v }; mreturn nil }
end
stream(data, headers = {}, status = 200) click to toggle source

everyting ok, stream data

# File lib/siresta/response.rb, line 102
def self.stream(data, headers = {}, status = 200)
  # TODO
end
stream_keep_open() click to toggle source

everything ok, stream data (keep open)

# File lib/siresta/response.rb, line 107
def self.stream_keep_open
  # TODO
end
validate_body(handler) click to toggle source

validate body

# File lib/siresta/response.rb, line 141
def self.validate_body(handler)
  # TODO
end
validate_params(handler) click to toggle source

validate parameters

# File lib/siresta/response.rb, line 146
def self.validate_params(handler)
  # TODO
end