Class: Clockwork::XML::Credit
- Inherits:
-
Object
- Object
- Clockwork::XML::Credit
- Defined in:
- lib/clockwork/xml/credit.rb
Overview
XML building and parsing for checking credit.
Class Method Summary collapse
-
.build(api) ⇒ string
Build the XML data to check the credit from the XML API.
-
.parse(response) ⇒ string
Parse the XML response.
Class Method Details
.build(api) ⇒ string
Build the XML data to check the credit from the XML API.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/clockwork/xml/credit.rb', line 11 def self.build api builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.Credit { if api.api_key xml.Key api.api_key else xml.Username api.username xml.Password api.password end } end builder.to_xml end |
.parse(response) ⇒ string
Parse the XML response.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/clockwork/xml/credit.rb', line 31 def self.parse response if response.code.to_i == 200 doc = Nokogiri.parse( response.body ) if doc.css('ErrDesc').empty? doc.css('Credit').inner_html.to_i elsif doc.css('ErrNo').inner_html.to_i == 2 raise Clockwork::Error::Authentication, doc.css('ErrDesc').inner_html else raise Clockwork::Error::Generic, doc.css('ErrDesc').inner_html end else raise Clockwork::Error::HTTP, "Could not connect to the Clockwork API to check credit." end end |