lib/efax/outbound.rb in efax-1.3.2 vs lib/efax/outbound.rb in efax-1.3.3

- old
+ new

@@ -15,11 +15,11 @@ end end module EFax # URL of eFax web service - Url = "https://secure.efaxdeveloper.com/EFax_WebFax.serv" + Url = "https://secure.efaxdeveloper.com/EFax_WebFax.serv" # URI of eFax web service Uri = URI.parse(Url) # Prefered content type HEADERS = {'Content-Type' => 'text/xml'} @@ -43,28 +43,28 @@ @@account_id end def self.account_id=(id) @@account_id = id end - + def self.params(content) escaped_xml = ::URI.escape(content, Regexp.new("[^#{::URI::PATTERN::UNRESERVED}]")) "id=#{account_id}&xml=#{escaped_xml}&respond=XML" end private_class_method :params end - + class OutboundRequest < Request def self.post(name, company, fax_number, subject, content, content_type = :html) xml_request = xml(name, company, fax_number, subject, content, content_type) response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https| https.post(EFax::Uri.path, params(xml_request), EFax::HEADERS) end OutboundResponse.new(response) end - + def self.xml(name, company, fax_number, subject, content, content_type = :html) xml_request = "" xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 ) xml.instruct! :xml, :version => '1.0' xml.OutboundRequest do @@ -139,11 +139,11 @@ response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https| https.post(EFax::Uri.path, data, EFax::HEADERS) end OutboundStatusResponse.new(response) end - + def self.xml(doc_id) xml_request = "" xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 ) xml.instruct! :xml, :version => '1.0' xml.OutboundStatus do @@ -180,11 +180,11 @@ if response.is_a? Net::HTTPOK doc = Hpricot(response.body) @message = doc.at(:message).innerText @classification = doc.at(:classification).innerText.delete('"') @outcome = doc.at(:outcome).innerText.delete('"') - if @classification.empty? && @outcome.empty? + if !sent_yet?(classification, outcome) || busy_signal?(classification) @status_code = QueryStatus::PENDING elsif @classification == "Success" && @outcome == "Success" @status_code = QueryStatus::SENT else @status_code = QueryStatus::FAILURE @@ -192,7 +192,16 @@ else @status_code = QueryStatus::HTTP_FAILURE @message = "HTTP request failed (#{response.code})" end end + + def busy_signal?(classification) + classification == "Busy" + end + + def sent_yet?(classification, outcome) + !classification.empty? || !outcome.empty? + end + end -end \ No newline at end of file +end