Class: Abrio::Url
- Inherits:
-
Object
- Object
- Abrio::Url
- Defined in:
- lib/abrio/url.rb
Overview
Represents Abrio API response.
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#short_url ⇒ Object
readonly
Returns the value of attribute short_url.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
-
.parse(xml_body) ⇒ Object
Parses xml from Abrio API.
- .validates_xml(xml) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Url
constructor
Initialize all read-only atributes with Hash.
Constructor Details
#initialize(attrs = {}) ⇒ Url
Initialize all read-only atributes with Hash.
10 11 12 13 14 |
# File 'lib/abrio/url.rb', line 10 def initialize(attrs = {}) attrs.each_pair do |attr, value| self.instance_variable_set("@#{attr}", value) end end |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
6 7 8 |
# File 'lib/abrio/url.rb', line 6 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
6 7 8 |
# File 'lib/abrio/url.rb', line 6 def @error_message end |
#short_url ⇒ Object (readonly)
Returns the value of attribute short_url.
7 8 9 |
# File 'lib/abrio/url.rb', line 7 def short_url @short_url end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/abrio/url.rb', line 6 def status_code @status_code end |
Class Method Details
.parse(xml_body) ⇒ Object
Parses xml from Abrio API.
See documentation at abr.io/pages/api
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/abrio/url.rb', line 19 def self.parse(xml_body) validates_xml(xml_body) doc = REXML::Document.new(xml_body) attributes = {:status_code => doc.elements["*/statusCode"].text, :error_message => doc.elements["*/errorMessage"].text, :error_code => doc.elements["*/errorCode"].text} if (result = doc.elements["*/results/nodeKeyVal"]) attributes.merge!({:short_url => result.elements["shortUrl"].text}) end self.new(attributes) end |