Class: Swicky::ApiResult
Overview
Helper class to encode API result codes for the controller
Constant Summary collapse
- RESULTS =
{ :success => 200, :illegal_parameter => 400, :error => 500 }
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #http_status ⇒ Object
-
#initialize(result, message) ⇒ ApiResult
constructor
A new instance of ApiResult.
- #to_html ⇒ Object
- #to_json ⇒ Object
- #to_xml ⇒ Object
Constructor Details
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/swicky/api_result.rb', line 8 def @message end |
#result ⇒ Object
Returns the value of attribute result.
8 9 10 |
# File 'lib/swicky/api_result.rb', line 8 def result @result end |
Instance Method Details
#http_status ⇒ Object
21 22 23 |
# File 'lib/swicky/api_result.rb', line 21 def http_status RESULTS[result] end |
#to_html ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/swicky/api_result.rb', line 40 def to_html html = '' builder = Builder::XmlMarkup.new(:target => html, :indent => 2) builder.declare! :DOCTYPE, :html, :PUBLIC, "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" builder.html do builder.head { builder.title("Swicky request result") } builder.body do builder.h1("Result Code") builder.p(result.to_s) builder.h1("Message") builder.p() end end html end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/swicky/api_result.rb', line 36 def to_json { :result => result, :message => }.to_json end |
#to_xml ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/swicky/api_result.rb', line 25 def to_xml xml = '' builder = Builder::XmlMarkup.new(:target => xml, :indent => 2) builder.instruct! builder.swicky_api do builder.result(result.to_s) builder.() end xml end |