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
45 46 47 |
# File 'lib/prowly/response.rb', line 45 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 |
# File 'lib/prowly/response.rb', line 17 def self.map_xml(response) response_info = parse_xml(response) #define dynamic methods based on the prowl api response #posible methods on success: code, remaining, resetdate #posible methods on error: code response_info.attributes.each do |key, value| add_instance_method(key, value) end response_info_name = response_info.name #define a method named status and it'll return "success" or "error" add_instance_method(:status, response_info_name) boolean_status = response_info_name == "success" ? true : false add_instance_method(:message, response_info.text) unless boolean_status add_instance_method(:succeeded?, boolean_status) true end |
.parse_xml(response) ⇒ Object
39 40 41 42 |
# File 'lib/prowly/response.rb', line 39 def self.parse_xml(response) data = REXML::Document.new response data.root[1] end |