Skip to content

Commit

Permalink
handle multiple xml line response for retrieve_token and retrieve_apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
/k committed Mar 20, 2011
1 parent ae54df9 commit 9a100c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.rdoc
Expand Up @@ -35,15 +35,15 @@ Yet another Ruby interface to Prowl with command line utility
-p, --priority PRIORITY VERY_LOW, MODERATE, NORMAL (default), HIGH, EMERGENCY
-u, --url URL for redirect (v1.2 feature)
-v, --version Print the version number and exit

If you only specify the apikey prowly will use the defaults:

:description => "I am testing Prowly, and it works!"
:event => "Prowly notification"
:application => "Prowly"
:priority => NORMAL
:url => nil

== Handling the Prowl API response

ON SUCCESS
Expand Down
34 changes: 18 additions & 16 deletions lib/prowly/response.rb
Expand Up @@ -4,7 +4,7 @@ module Prowly

#This is a Prowl API response wrapper
class Response

attr_writer :response
attr_accessor :http_response

Expand All @@ -17,28 +17,30 @@ def initialize(xml_response, full_http_response)
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)
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)
end
add_instance_method(key, value)
end
end

add_instance_method(:message, response_info[1].text) unless boolean_status

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

def self.parse_xml(response)
data = REXML::Document.new response
data.root[1]
data.root
end

#define dynamic methods
Expand Down

0 comments on commit 9a100c7

Please sign in to comment.