faxage 1.0.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +71 -0
- data/lib/faxage/information_gathering.rb +36 -1
- data/lib/faxage/receive_fax.rb +100 -3
- data/lib/faxage/version.rb +1 -1
- data/lib/faxage.rb +3 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b7534be52991e73089c5258d35d4cd791c2fbd7370c1a005946bb292f3b940
|
4
|
+
data.tar.gz: 076cb60e728a22f1bd7c7b98c761abfcb3c8ec572fb4b041f642260970ff3014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82aa232fd6cdc0ae82adae99df8b661b365c2d27bc66475f0cea96cca5ac89af3a191298618ddd356ac029b1f994ca0328e787e7d720bca735a98dff90c48ebb
|
7
|
+
data.tar.gz: 9b683d9d4de97e2eda7d36953aa9fa96ac1274342f033f5deccbdb1f2927249f60994864affa1855f45936d9e44978e94db348561e0290f9a9ce43fa265d4918
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -56,6 +56,51 @@ Click the link for ‘Q: What types of files can I send?’ on the above URL to
|
|
56
56
|
| HP Printer Control Language | PCL |
|
57
57
|
| Plain Text | TXT |
|
58
58
|
|
59
|
+
#### Error Types
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class LoginError < StandardError
|
63
|
+
# "One or more of username, company, password is incorrect or your account is disabled for some reason."
|
64
|
+
end
|
65
|
+
|
66
|
+
class FaxageInternalError < StandardError
|
67
|
+
# "Internal FAXAGE error."
|
68
|
+
end
|
69
|
+
|
70
|
+
class UnknownOperationError < StandardError
|
71
|
+
# "Either operation is not correctly hard coded or the POST was bad, the POST contents are returned for debugging purposes. #{response.parsed_response}"
|
72
|
+
end
|
73
|
+
|
74
|
+
class NoResponseError < StandardError
|
75
|
+
# "An empty response was returned from Faxage."
|
76
|
+
end
|
77
|
+
|
78
|
+
class InvalidJobIdError < StandardError
|
79
|
+
# "Internal FAXAGE error – the job was not properly inserted into our database."
|
80
|
+
end
|
81
|
+
|
82
|
+
class InvalidFaxNoError < StandardError
|
83
|
+
# "The faxno variable does not contain a 10-digit numeric only string."
|
84
|
+
end
|
85
|
+
|
86
|
+
class NoFilesError < StandardError
|
87
|
+
# "No valid files were found in faxfilenames[] and/or faxfiledata[]."
|
88
|
+
end
|
89
|
+
|
90
|
+
class BlockedNumberError < StandardError
|
91
|
+
# "The number you tried to fax to was blocked (outside of continental US, Canada and Hawaii or a 555, 911, or other invalid/blocked type of number)."
|
92
|
+
end
|
93
|
+
|
94
|
+
class NoIncomingFaxesError < StandardError
|
95
|
+
# "There are no incoming faxes to list for you."
|
96
|
+
end
|
97
|
+
|
98
|
+
class FaxIdNotFoundError < StandardError
|
99
|
+
# The faxid passed in is invalid or is an ID that does not belong to your company.
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
|
59
104
|
#### Sending a fax
|
60
105
|
|
61
106
|
##### sendfax
|
@@ -122,6 +167,32 @@ Faxage::ReceiveFax.new(
|
|
122
167
|
).listfax()
|
123
168
|
```
|
124
169
|
|
170
|
+
##### getfax
|
171
|
+
This operation is used to download a received fax image.
|
172
|
+
```ruby
|
173
|
+
Faxage::ReceiveFax.new(
|
174
|
+
username: # Assigned FAXAGE username
|
175
|
+
company: # Assigned FAXAGE company credential
|
176
|
+
password: # Assigned FAXAGE password
|
177
|
+
).getfax(recvid:) # The numeric ID of the fax to get, retrieved from the listfax operation (the recvid in listfax)
|
178
|
+
|
179
|
+
# The actual data returned will be the binary contents of the fax itself.
|
180
|
+
|
181
|
+
# A practical example of uploading the file to AWS S3 in a Rails application could look like:
|
182
|
+
|
183
|
+
get_fax = Faxage::ReceiveFax.new(
|
184
|
+
username: # Assigned FAXAGE username
|
185
|
+
company: # Assigned FAXAGE company credential
|
186
|
+
password: # Assigned FAXAGE password
|
187
|
+
).getfax(recvid:)
|
188
|
+
|
189
|
+
creds = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
|
190
|
+
s3_resource = Aws::S3::Resource.new(region: ENV['AWS_S3_REGION'], credentials: creds)
|
191
|
+
obj = s3_resource.bucket(ENV['AWS_BUCKET_NAME']).object("path-to-your-file-on-S3/your-file-name.pdf")
|
192
|
+
obj.put(body: get_fax)
|
193
|
+
|
194
|
+
```
|
195
|
+
|
125
196
|
#### Information Gathering Operations
|
126
197
|
|
127
198
|
These operations relate to gathering information that helps with managing and/or
|
@@ -293,5 +293,40 @@ module Faxage
|
|
293
293
|
return response.parsed_response
|
294
294
|
end
|
295
295
|
end
|
296
|
+
|
297
|
+
def dlstatus(jobid:, viewtype: 'pdf')
|
298
|
+
# This operation is used to download a sent fax image.
|
299
|
+
|
300
|
+
subdirectory = "/httpsfax.php"
|
301
|
+
|
302
|
+
body = {
|
303
|
+
operation: "dlstatus",
|
304
|
+
username: username,
|
305
|
+
company: company,
|
306
|
+
password: password,
|
307
|
+
jobid: jobid,
|
308
|
+
viewtype: viewtype
|
309
|
+
}
|
310
|
+
|
311
|
+
response = self.class.post(subdirectory, body: body)
|
312
|
+
|
313
|
+
if response.parsed_response.nil?
|
314
|
+
raise NoResponseError.new("An empty response was returned from Faxage.")
|
315
|
+
elsif response.parsed_response.include?("ERR01: Database connection failed")
|
316
|
+
raise FaxageInternalError.new("Internal FAXAGE error.")
|
317
|
+
elsif response.parsed_response.include?("ERR02: Login incorrect")
|
318
|
+
raise LoginError.new("One or more of username, company, password is incorrect or your account is disabled for some reason.")
|
319
|
+
elsif response.parsed_response.include?("ERR06: No jobs to display or job id specified not found")
|
320
|
+
raise InvalidJobIdError.new("The jobid you passed was not found")
|
321
|
+
elsif response.parsed_response.include?("ERR08: Unknown operation")
|
322
|
+
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}")
|
323
|
+
elsif response.parsed_response.include?("ERR24: File is not yet converted")
|
324
|
+
raise NoFilesError.new("Images can only be retrieved after the file(s) have actually been imaged (I.e.: The fax must either be In Queue or completed to be able to retrieve an image)")
|
325
|
+
elsif response.parsed_response.include?("ERR25: File does not exist")
|
326
|
+
raise NoFilesError.new("This can be either an internal error, or if the status is a ‘Failed Conversion’, then there is no image to retrieve")
|
327
|
+
else
|
328
|
+
return response.parsed_response
|
329
|
+
end
|
330
|
+
end
|
296
331
|
end
|
297
|
-
end
|
332
|
+
end
|
data/lib/faxage/receive_fax.rb
CHANGED
@@ -7,7 +7,7 @@ module Faxage
|
|
7
7
|
|
8
8
|
attr_reader :username, # Assigned FAXAGE username
|
9
9
|
:company, # Assigned FAXAGE company credential
|
10
|
-
:password
|
10
|
+
:password # Assigned FAXAGE password
|
11
11
|
|
12
12
|
def initialize(username:, company:, password:)
|
13
13
|
@username = username
|
@@ -15,6 +15,40 @@ module Faxage
|
|
15
15
|
@password = password
|
16
16
|
end
|
17
17
|
|
18
|
+
def getfax(recvid:, **options)
|
19
|
+
# This operation is used to download a received fax image.
|
20
|
+
|
21
|
+
subdirectory = "/httpsfax.php"
|
22
|
+
|
23
|
+
body = {
|
24
|
+
operation: "getfax",
|
25
|
+
username: username,
|
26
|
+
company: company,
|
27
|
+
password: password,
|
28
|
+
faxid: recvid
|
29
|
+
}.merge!(options.each { |k, v| options[k] = 1 if v } )
|
30
|
+
|
31
|
+
response = self.class.post(subdirectory,
|
32
|
+
body: body
|
33
|
+
)
|
34
|
+
|
35
|
+
if response.parsed_response.nil?
|
36
|
+
raise NoResponseError.new("An empty response was returned from Faxage.")
|
37
|
+
elsif response.parsed_response.include?("ERR01: Database connection failed")
|
38
|
+
raise FaxageInternalError.new("Internal FAXAGE error.")
|
39
|
+
elsif response.parsed_response.include?("ERR02: Login incorrect")
|
40
|
+
raise LoginError.new("One or more of username, company, password is incorrect or your account is disabled for some reason.")
|
41
|
+
elsif response.parsed_response.include?("ERR08: Unknown operation")
|
42
|
+
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}")
|
43
|
+
elsif response.parsed_response.include?("ERR12: FAX ID")
|
44
|
+
raise FaxIdNotFoundError.new("The faxid passed in is invalid or is an ID that does not belong to your company. #{response.parsed_response}")
|
45
|
+
elsif response.parsed_response.include?("ERR13: File could not be opened")
|
46
|
+
raise FaxageInternalError.new("Internal FAXAGE error. #{response.parsed_response}.")
|
47
|
+
else
|
48
|
+
return response.parsed_response
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
18
52
|
def listfax(**options)
|
19
53
|
# This operation is used to gather a list of incoming faxes for your account.
|
20
54
|
|
@@ -25,7 +59,7 @@ module Faxage
|
|
25
59
|
username: username,
|
26
60
|
company: company,
|
27
61
|
password: password
|
28
|
-
}.merge!(options)
|
62
|
+
}.merge!(options.each { |k, v| options[k] = 1 if v } )
|
29
63
|
|
30
64
|
response = self.class.post(subdirectory,
|
31
65
|
body: body
|
@@ -42,7 +76,70 @@ module Faxage
|
|
42
76
|
elsif response.parsed_response.include?("ERR11: No incoming faxes available")
|
43
77
|
raise NoIncomingFaxesError.new("There are no incoming faxes to list for you.")
|
44
78
|
else
|
45
|
-
|
79
|
+
data = []
|
80
|
+
response.parsed_response.split("\n").each do |received_fax|
|
81
|
+
# <recvid><tab><recvdate>(OPTIONAL:
|
82
|
+
# <tab><starttime>)
|
83
|
+
# <tab><CID><tab><DNIS>(OPTIONAL:
|
84
|
+
# <tab><filename>)(OPTIONAL:
|
85
|
+
# <tab><pagecount>)(OPTIONAL: <tab><tsid>)
|
86
|
+
individual_fax = Hash.new
|
87
|
+
received_fax.split("\t").each_with_index do |item, index|
|
88
|
+
if options[:starttime].nil?
|
89
|
+
if index == 0
|
90
|
+
individual_fax[:recvid] = item
|
91
|
+
elsif index == 1
|
92
|
+
individual_fax[:revdate] = item
|
93
|
+
elsif index == 2
|
94
|
+
individual_fax[:cid] = item
|
95
|
+
elsif index == 3
|
96
|
+
individual_fax[:dnis] = item
|
97
|
+
elsif index == 4 && !options[:filename].nil?
|
98
|
+
individual_fax[:filename] = item
|
99
|
+
elsif index == 4 && options[:filename].nil? && !options[:pagecount].nil?
|
100
|
+
individual_fax[:pagecount] = item
|
101
|
+
elsif index == 4 && options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
|
102
|
+
individual_fax[:tsid] = item
|
103
|
+
elsif index == 5 && !options[:filename].nil? && !options[:pagecount].nil?
|
104
|
+
individual_fax[:pagecount] = item
|
105
|
+
elsif index == 5 && !options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
|
106
|
+
individual_fax[:tsid] = item
|
107
|
+
elsif index == 5 && options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
|
108
|
+
individual_fax[:tsid] = item
|
109
|
+
elsif index == 6 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
|
110
|
+
individual_fax[:tsid] = item
|
111
|
+
end
|
112
|
+
else
|
113
|
+
if index == 0
|
114
|
+
individual_fax[:recvid] = item
|
115
|
+
elsif index == 1
|
116
|
+
individual_fax[:revdate] = item
|
117
|
+
elsif index == 2
|
118
|
+
individual_fax[:starttime] = item
|
119
|
+
elsif index == 3
|
120
|
+
individual_fax[:cid] = item
|
121
|
+
elsif index == 4
|
122
|
+
individual_fax[:dnis] = item
|
123
|
+
elsif index == 5 && !options[:filename].nil?
|
124
|
+
individual_fax[:filename] = item
|
125
|
+
elsif index == 5 && options[:filename].nil? && !options[:pagecount].nil?
|
126
|
+
individual_fax[:pagecount] = item
|
127
|
+
elsif index == 5 && options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
|
128
|
+
individual_fax[:tsid] = item
|
129
|
+
elsif index == 6 && !options[:filename].nil? && !options[:pagecount].nil?
|
130
|
+
individual_fax[:pagecount] = item
|
131
|
+
elsif index == 6 && !options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
|
132
|
+
individual_fax[:tsid] = item
|
133
|
+
elsif index == 6 && options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
|
134
|
+
individual_fax[:tsid] = item
|
135
|
+
elsif index == 7 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
|
136
|
+
individual_fax[:tsid] = item
|
137
|
+
end
|
138
|
+
end
|
139
|
+
data << individual_fax
|
140
|
+
end
|
141
|
+
end
|
142
|
+
return data
|
46
143
|
end
|
47
144
|
end
|
48
145
|
end
|
data/lib/faxage/version.rb
CHANGED
data/lib/faxage.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faxage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Dias
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,7 +98,7 @@ homepage: https://github.com/diasks2/faxage
|
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|
101
|
-
post_install_message:
|
101
|
+
post_install_message:
|
102
102
|
rdoc_options: []
|
103
103
|
require_paths:
|
104
104
|
- lib
|
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
116
|
+
rubygems_version: 3.1.6
|
117
|
+
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: Faxage is a Ruby wrapper for the faxage.com API
|
121
120
|
test_files: []
|