Class: RestPack::Service::Response
- Inherits:
-
Object
- Object
- RestPack::Service::Response
- Defined in:
- lib/restpack_service/response.rb
Defined Under Namespace
Classes: Status
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#result ⇒ Object
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(field, message) ⇒ Object
- #code ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
5 6 7 8 |
# File 'lib/restpack_service/response.rb', line 5 def initialize @result = {} @errors = {} end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/restpack_service/response.rb', line 3 def errors @errors end |
#result ⇒ Object
Returns the value of attribute result.
3 4 5 |
# File 'lib/restpack_service/response.rb', line 3 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/restpack_service/response.rb', line 3 def status @status end |
Class Method Details
.from_rest(rest_response) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |
Instance Method Details
#add_error(field, message) ⇒ Object
18 19 20 21 |
# File 'lib/restpack_service/response.rb', line 18 def add_error(field, ) @errors[field] ||= [] @errors[field] << end |
#code ⇒ Object
14 15 16 |
# File 'lib/restpack_service/response.rb', line 14 def code Status.from_status(status) end |
#success? ⇒ Boolean
10 11 12 |
# File 'lib/restpack_service/response.rb', line 10 def success? @errors.empty? and @status == :ok end |