Class: Prowly::Response
- Inherits:
-
Object
- Object
- Prowly::Response
- Defined in:
- lib/prowly/response.rb
Overview
This is a Prowl API response wrapper
Defined Under Namespace
Modules: ErrorCode, SuccessCode
Instance Attribute Summary collapse
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#response ⇒ Object
writeonly
Sets the attribute response.
Class Method Summary collapse
-
.add_instance_method(name, content) ⇒ Object
define dynamic methods.
- .map_xml(response) ⇒ Object
- .parse_xml(response) ⇒ Object
Instance Method Summary collapse
-
#initialize(xml_response, full_http_response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
Instance Attribute Details
#http_response ⇒ Object
Returns the value of attribute http_response.
9 10 11 |
# File 'lib/prowly/response.rb', line 9 def http_response @http_response end |
#response=(value) ⇒ Object (writeonly)
Sets the attribute response
8 9 10 |
# File 'lib/prowly/response.rb', line 8 def response=(value) @response = value end |
Class Method Details
.add_instance_method(name, content) ⇒ Object
define dynamic methods
46 47 48 |
# File 'lib/prowly/response.rb', line 46 def self.add_instance_method(name, content) define_method(name) { content } end |
.map_xml(response) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/prowly/response.rb', line 17 def self.map_xml(response) response_info = parse_xml(response) response_info.elements.each do |r| #define dynamic methods based on the prowl api response #posible methods on success: code, remaining, resetdate #posible methods on error: code r.attributes.each do |key, value| # puts "attribute #{key}: #{value}" if key == "code" add_instance_method(:status, value == "200" ? "success" : "error") #define a method named status and it'll return "success" or "error" boolean_status = value == "200" ? true : false add_instance_method(:succeeded?, boolean_status) add_instance_method(:message, response_info[1].text) unless boolean_status end add_instance_method(key, value) end end true end |
.parse_xml(response) ⇒ Object
40 41 42 43 |
# File 'lib/prowly/response.rb', line 40 def self.parse_xml(response) data = REXML::Document.new response data.root end |