Module: Platanus::InstanceMethods

Defined in:
lib/platanus/api_base.rb

Instance Method Summary collapse

Instance Method Details

#api_respond_empty(_options = {}) ⇒ Object

Renders an empty response



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

def api_respond_empty(_options={})
  _options[:json] = {}
  api_respond_with(_options)
end

#api_respond_error(_status, _error_obj = {}) ⇒ Object

Renders an error response

Parameters:

  • _status (String, Fixnum)

    Response error code.

  • _error_obj (object) (defaults to: {})

    Error object to serialize in response.



87
88
89
90
91
# File 'lib/platanus/api_base.rb', line 87

def api_respond_error(_status, _error_obj={})
  respond_with do |format|
    format.json { render :status => _status, :json => _error_obj }
  end
end

#api_respond_with(_resource, _options = {}) ⇒ Object

Renders a regular response



76
77
78
79
80
# File 'lib/platanus/api_base.rb', line 76

def api_respond_with(_resource, _options={})
  respond_with(_resource) do |format|
    format.json { render _options }
  end
end