diff --git a/Gemfile b/Gemfile index 0334463..1d1e8e3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source "http://rubygems.org" gemspec -gem "rake" +gem "rake" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index e6c33b5..8557767 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,14 +3,16 @@ PATH specs: efax (1.4.2) builder (~> 3.0.0) - hpricot (~> 0.8.1) + nokogiri (~> 1.6) GEM remote: http://rubygems.org/ specs: - builder (3.0.0) - hpricot (0.8.6) + builder (3.0.4) + mini_portile2 (2.0.0) mocha (0.9.12) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) rake (0.9.2) test-unit (2.3.2) @@ -22,3 +24,6 @@ DEPENDENCIES mocha (~> 0.9.12) rake test-unit (~> 2.3.2) + +BUNDLED WITH + 1.10.6 diff --git a/efax.gemspec b/efax.gemspec index 82f8e72..44ec53d 100644 --- a/efax.gemspec +++ b/efax.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.version = EFax::VERSION - gem.add_runtime_dependency "builder", "~> 3.0.0" - gem.add_runtime_dependency "hpricot", "~> 0.8.1" + gem.add_runtime_dependency "builder", "~> 3.1" + gem.add_runtime_dependency "nokogiri", "~> 1.6" gem.add_development_dependency "test-unit", "~> 2.3.2" gem.add_development_dependency "mocha", "~> 0.9.12" diff --git a/lib/efax/inbound.rb b/lib/efax/inbound.rb index 5f23d93..1ba106d 100644 --- a/lib/efax/inbound.rb +++ b/lib/efax/inbound.rb @@ -1,4 +1,4 @@ -require 'hpricot' +require 'nokogiri' require 'base64' require 'tempfile' require 'date' @@ -27,21 +27,21 @@ class InboundPostRequest alias_method :sender_fax_number, :ani def initialize(xml) - doc = Hpricot(xml) - @encoded_file_contents = doc.at(:filecontents).inner_text - @file_type = doc.at(:filetype).inner_text.to_sym - @ani = doc.at(:ani).inner_text - @account_id = doc.at(:accountid).inner_text - @fax_name = doc.at(:faxname).inner_text - @csid = doc.at(:csid).inner_text - @status = doc.at(:status).inner_text.to_i - @mcfid = doc.at(:mcfid).inner_text.to_i - @page_count = doc.at(:pagecount).inner_text.to_i - @request_type = doc.at(:requesttype).inner_text - @date_received = datetime_to_time(DateTime.strptime("#{doc.at(:datereceived).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z")) - @request_date = datetime_to_time(DateTime.strptime("#{doc.at(:requestdate).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z")) - @barcodes = doc.search("//barcode/key").map { |key| key.inner_html } - @barcode_pages = doc.search("//barcode/AdditionalInfo/CodeLocation/PageNumber").map { |key| key.inner_html } + doc = Nokogiri::XML(xml) + @encoded_file_contents = doc.at(:FileContents).inner_text + @file_type = doc.at(:FileType).inner_text.to_sym + @ani = doc.at(:ANI).inner_text + @account_id = doc.at(:AccountID).inner_text + @fax_name = doc.at(:FaxName).inner_text + @csid = doc.at(:CSID).inner_text + @status = doc.at(:Status).inner_text.to_i + @mcfid = doc.at(:MCFID).inner_text.to_i + @page_count = doc.at(:PageCount).inner_text.to_i + @request_type = doc.at(:RequestType).inner_text + @date_received = datetime_to_time(DateTime.strptime("#{doc.at(:DateReceived).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z")) + @request_date = datetime_to_time(DateTime.strptime("#{doc.at(:RequestDate).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z")) + @barcodes = doc.xpath("//Barcode/Key").map { |key| key.inner_html } + @barcode_pages = doc.xpath("//Barcode/AdditionalInfo/CodeLocation/PageNumber").map { |key| key.inner_html } end def file_contents diff --git a/lib/efax/outbound.rb b/lib/efax/outbound.rb index cd52e2c..fe4b218 100644 --- a/lib/efax/outbound.rb +++ b/lib/efax/outbound.rb @@ -1,7 +1,7 @@ require 'net/http' require 'net/https' require 'builder' -require 'hpricot' +require 'nokogiri' require 'base64' module Net #:nodoc: @@ -118,13 +118,13 @@ class OutboundResponse def initialize(response) #:nodoc: if response.is_a? Net::HTTPOK - doc = Hpricot(response.body) - @status_code = doc.at(:statuscode).inner_text.to_i - @error_message = doc.at(:errormessage) + doc = Nokogiri::XML(response.body) + @status_code = doc.at(:StatusCode).inner_text.to_i + @error_message = doc.at(:ErrorMessage) @error_message = @error_message.inner_text if @error_message - @error_level = doc.at(:errorlevel) + @error_level = doc.at(:ErrorLevel) @error_level = @error_level.inner_text if @error_level - @doc_id = doc.at(:docid).inner_text + @doc_id = doc.at(:DOCID).inner_text @doc_id = @doc_id.empty? ? nil : @doc_id else @status_code = RequestStatus::HTTP_FAILURE @@ -178,10 +178,10 @@ class OutboundStatusResponse def initialize(response) #:nodoc: 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('"') + doc = Nokogiri::XML(response.body) + @message = doc.at(:Message).inner_text + @classification = doc.at(:Classification).inner_text.delete('"') + @outcome = doc.at(:Outcome).inner_text.delete('"') if !sent_yet?(classification, outcome) || busy_signal?(classification) @status_code = QueryStatus::PENDING elsif @classification == "Success" && @outcome == "Success"