faxage 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cef925b012340a06484d13804bef6028f9e6947c545c5a704e2c7b7d4b68e278
4
- data.tar.gz: 8aa2da77601b18e6b8fad5f0c0a335e49109fcbd6af028453bd296499639bfd1
3
+ metadata.gz: 7a03e5a557de75e3e23b481552f7dac9d652496ca6a013978c51580f3b88c50d
4
+ data.tar.gz: ce9c8db7811d2c0f587aef771d6a425d4b465f5822f2da339059197524819a52
5
5
  SHA512:
6
- metadata.gz: 05417c5b676dd0b6c7e547bb7f2a96743cd096c7304537f6f463582c5babbd01f644eb011e445734c5b473cf0ef12fa1e4d5e46d924f639a1519672bba7c8174
7
- data.tar.gz: b68dd6c22a01c949a6140688628047c7a069f3be85b2e718634fbb6d39afe40df8ff1f28a883d966c9ac508c728aba6379db21e74ebd9685dd89abd78f9d108a
6
+ metadata.gz: 051ae752d2f1e6a3a8d17df6e3b7c8cefda75c242a846e7619f704cc46ce7637e0483d3ba5c6ed83c5c483b6b5cc73f2d4b7873c420b827ec310b7d23882f7a7
7
+ data.tar.gz: 14eaa675be8861717f7bf9596703adba1a2b8549e1c0e731f9db6980e26bcf661e7cbc8d7dc914f8c1e10b0c201f9255745d535cb868575fb873c11e6f85bb9e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faxage (1.1.1)
4
+ faxage (1.2.1)
5
5
  httparty
6
6
 
7
7
  GEM
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
@@ -28,4 +28,7 @@ class BlockedNumberError < StandardError
28
28
  end
29
29
 
30
30
  class NoIncomingFaxesError < StandardError
31
+ end
32
+
33
+ class FaxIdNotFoundError < StandardError
31
34
  end
@@ -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
@@ -52,51 +86,53 @@ module Faxage
52
86
  individual_fax = Hash.new
53
87
  received_fax.split("\t").each_with_index do |item, index|
54
88
  if options[:starttime].nil?
55
- case index
56
- when 0
89
+ if index == 0
57
90
  individual_fax[:recvid] = item
58
- when 1
91
+ elsif index == 1
59
92
  individual_fax[:revdate] = item
60
- when 2
93
+ elsif index == 2
61
94
  individual_fax[:cid] = item
62
- when 3
95
+ elsif index == 3
63
96
  individual_fax[:dnis] = item
64
- when 4 && !options[:filename].nil?
97
+ elsif index == 4 && !options[:filename].nil?
65
98
  individual_fax[:filename] = item
66
- when 4 && options[:filename].nil? && !options[:pagecount].nil?
99
+ elsif index == 4 && options[:filename].nil? && !options[:pagecount].nil?
67
100
  individual_fax[:pagecount] = item
68
- when 4 && options[:filename].nil? && options[:pagecount].nil? && !options[:tsid].nil?
101
+ elsif index == 4 && options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
69
102
  individual_fax[:tsid] = item
70
- when 5 && !options[:filename].nil? && !options[:pagecount].nil?
103
+ elsif index == 5 && !options[:filename].nil? && !options[:pagecount].nil?
71
104
  individual_fax[:pagecount] = item
72
- when 5 && !options[:filename].nil? && options[:pagecount].nil? && !options[:tsid].nil?
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?
73
108
  individual_fax[:tsid] = item
74
- when 6 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:tsid].nil?
109
+ elsif index == 6 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
75
110
  individual_fax[:tsid] = item
76
111
  end
77
112
  else
78
- case index
79
- when 0
113
+ if index == 0
80
114
  individual_fax[:recvid] = item
81
- when 1
115
+ elsif index == 1
82
116
  individual_fax[:revdate] = item
83
- when 2
117
+ elsif index == 2
84
118
  individual_fax[:starttime] = item
85
- when 3
119
+ elsif index == 3
86
120
  individual_fax[:cid] = item
87
- when 4
121
+ elsif index == 4
88
122
  individual_fax[:dnis] = item
89
- when 5 && !options[:filename].nil?
123
+ elsif index == 5 && !options[:filename].nil?
90
124
  individual_fax[:filename] = item
91
- when 5 && options[:filename].nil? && !options[:pagecount].nil?
125
+ elsif index == 5 && options[:filename].nil? && !options[:pagecount].nil?
92
126
  individual_fax[:pagecount] = item
93
- when 5 && options[:filename].nil? && options[:pagecount].nil? && !options[:tsid].nil?
127
+ elsif index == 5 && options[:filename].nil? && options[:pagecount].nil? && !options[:showtsid].nil?
94
128
  individual_fax[:tsid] = item
95
- when 6 && !options[:filename].nil? && !options[:pagecount].nil?
129
+ elsif index == 6 && !options[:filename].nil? && !options[:pagecount].nil?
96
130
  individual_fax[:pagecount] = item
97
- when 6 && !options[:filename].nil? && options[:pagecount].nil? && !options[:tsid].nil?
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?
98
134
  individual_fax[:tsid] = item
99
- when 7 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:tsid].nil?
135
+ elsif index == 7 && !options[:filename].nil? && !options[:pagecount].nil? && !options[:showtsid].nil?
100
136
  individual_fax[:tsid] = item
101
137
  end
102
138
  end
@@ -1,3 +1,3 @@
1
1
  module Faxage
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faxage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias