Class: Faxage::ReceiveFax
- Inherits:
-
Object
- Object
- Faxage::ReceiveFax
- Includes:
- HTTParty
- Defined in:
- lib/faxage/receive_fax.rb
Instance Attribute Summary collapse
-
#company ⇒ Object
readonly
Assigned FAXAGE username.
-
#password ⇒ Object
readonly
Assigned FAXAGE username.
-
#username ⇒ Object
readonly
Assigned FAXAGE username.
Instance Method Summary collapse
-
#initialize(username:, company:, password:) ⇒ ReceiveFax
constructor
A new instance of ReceiveFax.
- #listfax(**options) ⇒ Object
Constructor Details
#initialize(username:, company:, password:) ⇒ ReceiveFax
Returns a new instance of ReceiveFax.
12 13 14 15 16 |
# File 'lib/faxage/receive_fax.rb', line 12 def initialize(username:, company:, password:) @username = username @company = company @password = password end |
Instance Attribute Details
#company ⇒ Object (readonly)
Assigned FAXAGE username
8 9 10 |
# File 'lib/faxage/receive_fax.rb', line 8 def company @company end |
#password ⇒ Object (readonly)
Assigned FAXAGE username
8 9 10 |
# File 'lib/faxage/receive_fax.rb', line 8 def password @password end |
#username ⇒ Object (readonly)
Assigned FAXAGE username
8 9 10 |
# File 'lib/faxage/receive_fax.rb', line 8 def username @username end |
Instance Method Details
#listfax(**options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/faxage/receive_fax.rb', line 18 def listfax(**) # This operation is used to gather a list of incoming faxes for your account. subdirectory = "/httpsfax.php" body = { operation: "listfax", username: username, company: company, password: password }.merge!() response = self.class.post(subdirectory, body: body ) if response.parsed_response.nil? raise NoResponseError.new("An empty response was returned from Faxage.") elsif response.parsed_response.include?("ERR01: Database connection failed") raise FaxageInternalError.new("Internal FAXAGE error.") elsif response.parsed_response.include?("ERR02: Login incorrect") raise LoginError.new("One or more of username, company, password is incorrect or your account is disabled for some reason.") elsif response.parsed_response.include?("ERR08: Unknown operation") raise UnknownOperationError.new("Either operation is not correctly hard coded or the POST was bad, the POST contents are returned for debugging purposes. #{response.parsed_response}") elsif response.parsed_response.include?("ERR11: No incoming faxes available") raise NoIncomingFaxesError.new("There are no incoming faxes to list for you.") else data = [] response.parsed_response.split("\n").each do |received_fax| # <recvid><tab><recvdate>(OPTIONAL: # <tab><starttime>) # <tab><CID><tab><DNIS>(OPTIONAL: # <tab><filename>)(OPTIONAL: # <tab><pagecount>)(OPTIONAL: <tab><tsid>) individual_fax = Hash.new received_fax.split("\t").each_with_index do |item, index| if [:starttime].nil? case index when 0 individual_fax[:recvid] = item when 1 individual_fax[:revdate] = item when 2 individual_fax[:cid] = item when 3 individual_fax[:dnis] = item when 4 && ![:filename].nil? individual_fax[:filename] = item when 4 && [:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item when 4 && [:filename].nil? && [:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item when 5 && ![:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item when 5 && ![:filename].nil? && [:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item when 6 && ![:filename].nil? && ![:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item end else case index when 0 individual_fax[:recvid] = item when 1 individual_fax[:revdate] = item when 2 individual_fax[:starttime] = item when 3 individual_fax[:cid] = item when 4 individual_fax[:dnis] = item when 5 && ![:filename].nil? individual_fax[:filename] = item when 5 && [:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item when 5 && [:filename].nil? && [:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item when 6 && ![:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item when 6 && ![:filename].nil? && [:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item when 7 && ![:filename].nil? && ![:pagecount].nil? && ![:tsid].nil? individual_fax[:tsid] = item end end data << individual_fax end end return data end end |