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
- #getfax(recvid:, **options) ⇒ Object
-
#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
#getfax(recvid:, **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 |
# File 'lib/faxage/receive_fax.rb', line 18 def getfax(recvid:, **) # This operation is used to download a received fax image. subdirectory = "/httpsfax.php" body = { operation: "getfax", username: username, company: company, password: password, faxid: recvid }.merge!(.each { |k, v| [k] = 1 if v } ) 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?("ERR12: FAX ID") raise FaxIdNotFoundError.new("The faxid passed in is invalid or is an ID that does not belong to your company. #{response.parsed_response}") elsif response.parsed_response.include?("ERR13: File could not be opened") raise FaxageInternalError.new("Internal FAXAGE error. #{response.parsed_response}.") else return response.parsed_response end end |
#listfax(**options) ⇒ Object
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/faxage/receive_fax.rb', line 52 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!(.each { |k, v| [k] = 1 if v } ) 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? if index == 0 individual_fax[:recvid] = item elsif index == 1 individual_fax[:revdate] = item elsif index == 2 individual_fax[:cid] = item elsif index == 3 individual_fax[:dnis] = item elsif index == 4 && ![:filename].nil? individual_fax[:filename] = item elsif index == 4 && [:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item elsif index == 4 && [:filename].nil? && [:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 5 && ![:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item elsif index == 5 && ![:filename].nil? && [:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 5 && [:filename].nil? && ![:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 6 && ![:filename].nil? && ![:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item end else if index == 0 individual_fax[:recvid] = item elsif index == 1 individual_fax[:revdate] = item elsif index == 2 individual_fax[:starttime] = item elsif index == 3 individual_fax[:cid] = item elsif index == 4 individual_fax[:dnis] = item elsif index == 5 && ![:filename].nil? individual_fax[:filename] = item elsif index == 5 && [:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item elsif index == 5 && [:filename].nil? && [:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 6 && ![:filename].nil? && ![:pagecount].nil? individual_fax[:pagecount] = item elsif index == 6 && ![:filename].nil? && [:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 6 && [:filename].nil? && ![:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item elsif index == 7 && ![:filename].nil? && ![:pagecount].nil? && ![:showtsid].nil? individual_fax[:tsid] = item end end data << individual_fax end end return data end end |