class RestPack::Service::Response

Attributes

errors[RW]
result[RW]
status[RW]

Public Class Methods

from_rest(rest_response) click to toggle source
# File lib/restpack_service/response.rb, line 23
def self.from_rest(rest_response)
  response = new
  response.status = Status.from_code(rest_response.code)
  response.result = Yajl::Parser.parse(rest_response.body, :symbolize_keys => true)

  if response.result[:errors]
    response.result[:errors].each do |field, errors|
      response.errors[field.to_sym] = errors
    end

    response.result.delete :errors
  end

  response
end
new() click to toggle source
# File lib/restpack_service/response.rb, line 5
def initialize
  @result = {}
  @errors = {}
end

Public Instance Methods

add_error(field, message) click to toggle source
# File lib/restpack_service/response.rb, line 18
def add_error(field, message)
  @errors[field] ||= []
  @errors[field] << message
end
code() click to toggle source
# File lib/restpack_service/response.rb, line 14
def code
  Status.from_status(status)
end
success?() click to toggle source
# File lib/restpack_service/response.rb, line 10
def success?
  @errors.empty? and @status == :ok
end