Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ericdfields master #2

Merged
merged 6 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"

gemspec
gem "rake"
gem "rake"
21 changes: 17 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ PATH
remote: .
specs:
efax (1.4.2)
builder (~> 3.0.0)
hpricot (~> 0.8.1)
builder (~> 3.1)
nokogiri (~> 1.6)

GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
hpricot (0.8.6)
builder (3.2.2)
coderay (1.1.0)
method_source (0.8.2)
mini_portile2 (2.0.0)
mocha (0.9.12)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rake (0.9.2)
slop (3.6.0)
test-unit (2.3.2)

PLATFORMS
Expand All @@ -20,5 +29,9 @@ PLATFORMS
DEPENDENCIES
efax!
mocha (~> 0.9.12)
pry
rake
test-unit (~> 2.3.2)

BUNDLED WITH
1.10.6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ See `EFax::RequestStatus` class for details on status codes.
Having ID of your request, you can get its current status:

```ruby
response = OutboundRequestStatus.post(doc_id)
response = EFax::OutboundStatus.post(doc_id)
```

The status response has the following attributes:
Expand Down
3 changes: 2 additions & 1 deletion efax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Gem::Specification.new do |gem|
gem.version = EFax::VERSION

gem.add_runtime_dependency "builder", "~> 3.1"
gem.add_runtime_dependency "hpricot", "~> 0.8.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"
gem.add_development_dependency "pry"
end
35 changes: 18 additions & 17 deletions lib/efax/inbound.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'hpricot'
require 'nokogiri'
require 'base64'
require 'tempfile'
require 'date'
require 'pry'

module EFax
class InboundPostStatus
Expand All @@ -28,22 +29,22 @@ 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 }
@number_dialed = doc.at(:numberdialed).inner_text
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 }
@number_dialed = !doc.at(:NumberDialed).nil? ? doc.at(:NumberDialed).inner_text : nil
end

def file_contents
Expand Down
20 changes: 10 additions & 10 deletions lib/efax/outbound.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'net/http'
require 'net/https'
require 'builder'
require 'hpricot'
require 'nokogiri'
require 'base64'

module Net #:nodoc:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down