sr_fax 0.4.1 → 0.5.3
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.md +5 -5
- data/Rakefile +31 -1
- data/bin/console +3 -3
- data/lib/srfax.rb +148 -177
- data/lib/srfax/version.rb +3 -0
- data/srfax.gemspec +17 -17
- metadata +30 -23
- data/lib/version.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fb3aa28e640ae1db6b0dad66d2b12f3b05690e3
|
4
|
+
data.tar.gz: 6d12eab4fe174c2c75f9f21722c742fd44d97798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 889c220eebfa3a1e1fd97b0ffa5fd38d925081e4ae31cdb20d9a2fac1b84508bc233dfcd7b42e5a56576c8b6a92d58f892ce98ac6fc9e478d9faefdb69439444
|
7
|
+
data.tar.gz: 9bfb2a47455b9d2e77741ffaa4d0288126b2bbde4521f5b1b86ef4cbbdbf215fde18c2ed036526f1b450e4c2ae2f5798907c90a21184ae750603f049fa617b00
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ And then execute:
|
|
14
14
|
|
15
15
|
$ bundle
|
16
16
|
|
17
|
-
Or install it yourself using:
|
17
|
+
Or install it yourself using:
|
18
18
|
|
19
19
|
$ gem install sr_fax
|
20
20
|
|
@@ -29,13 +29,13 @@ require 'srfax'
|
|
29
29
|
SrFax.setup do |config|
|
30
30
|
config.defaults[:access_id] = '1234'
|
31
31
|
config.defaults[:access_pwd] = 'password'
|
32
|
-
config.
|
32
|
+
config.logger = Rails.logger
|
33
33
|
end
|
34
34
|
|
35
35
|
SrFax.view_inbox
|
36
36
|
SrFax.view_outbox
|
37
|
-
SrFax.update_fax_status(descriptor, direction)
|
38
|
-
SrFax.get_fax(descriptor, direction, {:sMarkasViewed => 'Y'}
|
37
|
+
SrFax.update_fax_status(descriptor, direction)
|
38
|
+
SrFax.get_fax(descriptor, direction, {:sMarkasViewed => 'Y'}
|
39
39
|
```
|
40
40
|
|
41
41
|
As an example, here is a sample queue fax call to send a fax
|
@@ -65,5 +65,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
65
65
|
4. Push to the branch (`git push origin my-new-feature`)
|
66
66
|
5. Create a new Pull Request
|
67
67
|
|
68
|
-
Licensing: **MIT**
|
68
|
+
Licensing: **MIT**
|
69
69
|
Remember: **'Great opportunities to help others seldom come, but small ones surround us daily' -- Sally Koch**
|
data/Rakefile
CHANGED
@@ -1 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
4
|
+
require 'srfax/version'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
require 'rake/testtask'
|
16
|
+
Rake::TestTask.new(:test) do |test|
|
17
|
+
test.libs << 'lib' << 'test'
|
18
|
+
test.test_files = Dir.glob("test/**/*_test.rb")
|
19
|
+
test.verbose = true
|
20
|
+
end
|
21
|
+
|
22
|
+
task :build do
|
23
|
+
system "gem build srfax.gemspec"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :release => :build do
|
27
|
+
system "gem push srfax-#{SrFax::VERSION}.gem"
|
28
|
+
system "rm srfax-#{SrFax::VERSION}.gem"
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => :test
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'srfax'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "srfax"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/srfax.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
require 'restclient'
|
2
2
|
require 'active_support'
|
3
3
|
require 'active_support/core_ext/hash'
|
4
|
-
require '
|
4
|
+
require 'json'
|
5
|
+
require 'srfax/version'
|
5
6
|
|
6
7
|
# This class serves as the integration component between the application and the SRFax cloud service.
|
7
|
-
# API DOX available @ https://www.srfax.com/srf/media/SRFax-REST-API-Documentation.pdf.
|
8
|
+
# API DOX available @ https://www.srfax.com/srf/media/SRFax-REST-API-Documentation.pdf.
|
8
9
|
#
|
9
10
|
# This module currently Implements the following POST commands from the API:
|
10
|
-
# Get_Usage – Retrieves the account usage
|
11
|
+
# Get_Usage – Retrieves the account usage.
|
11
12
|
# Update_Viewed_Status – Mark a inbound or outbound fax as read or unread.
|
12
13
|
# Queue_Fax - Schedules a fax to be sent with or without cover page.
|
13
|
-
# Get_Fax_Inbox - Returns a list of faxes received for a specified period of time
|
14
|
-
# Get_Fax_Outbox - Returns a list of faxes sent for a specified period of time
|
15
|
-
# Retrieve_Fax – Returns a specified sent or received fax file in PDF or TIFF format
|
16
|
-
# Delete_Fax - Deletes specified received or sent faxes
|
14
|
+
# Get_Fax_Inbox - Returns a list of faxes received for a specified period of time.
|
15
|
+
# Get_Fax_Outbox - Returns a list of faxes sent for a specified period of time.
|
16
|
+
# Retrieve_Fax – Returns a specified sent or received fax file in PDF or TIFF format.
|
17
|
+
# Delete_Fax - Deletes specified received or sent faxes.
|
17
18
|
# Get_FaxStatus – Determines the status of a fax that has been scheduled for delivery.
|
18
|
-
# Get_MultiFaxStatus – Determines the status of a multiple faxes that
|
19
|
+
# Get_MultiFaxStatus – Determines the status of a multiple faxes that have been
|
19
20
|
# scheduled for delivery.
|
20
|
-
# Stop_Fax - Removes a scheduled fax from the queue
|
21
|
+
# Stop_Fax - Removes a scheduled fax from the queue.
|
21
22
|
# Unimplemented methods:
|
22
|
-
# Delete_Pending_Fax - THIS DOESN'T EXIST - but is documented to exist
|
23
|
+
# Delete_Pending_Fax - THIS DOESN'T EXIST - but is documented to exist.
|
23
24
|
module SrFax
|
24
25
|
# Base URL for accessing SRFax API
|
25
|
-
BASE_URL =
|
26
|
+
BASE_URL = 'https://www.srfax.com/SRF_SecWebSvc.php'.freeze
|
26
27
|
|
27
28
|
mattr_accessor :defaults
|
28
29
|
# Default values hash to use with all #execute commands
|
@@ -34,19 +35,17 @@ module SrFax
|
|
34
35
|
sResponseFormat: 'JSON' # XML or JSON
|
35
36
|
}
|
36
37
|
|
37
|
-
mattr_accessor :connection_defaults
|
38
|
-
# Default values to use with the RestClient connection
|
39
|
-
@@connection_defaults = {
|
40
|
-
timeout: 180
|
41
|
-
}
|
42
|
-
|
43
38
|
mattr_accessor :logger
|
44
|
-
# Logger object for use in standalone
|
45
|
-
|
46
|
-
|
39
|
+
# Logger object for use in standalone mode or with Rails.
|
40
|
+
if defined?(Rails)
|
41
|
+
@@logger = Rails.logger
|
42
|
+
else
|
43
|
+
@@logger = Logger.new(STDOUT)
|
44
|
+
@@logger.level = Logger::INFO
|
45
|
+
end
|
47
46
|
|
48
47
|
class << self
|
49
|
-
# Allow configuring Srfax with a block, these will be the methods default values for passing to
|
48
|
+
# Allow configuring Srfax with a block, these will be the methods default values for passing to
|
50
49
|
# each function and will be overridden by any methods locally posted variables (ex: :action)
|
51
50
|
#
|
52
51
|
# @yield Accepts a block of valid configuration options to set or override default values
|
@@ -57,174 +56,174 @@ module SrFax
|
|
57
56
|
# config.defaults[:access_pwd] = 'password'
|
58
57
|
# config.defaults[:sCallerID] = '5555555555'
|
59
58
|
# end
|
60
|
-
def setup
|
59
|
+
def setup
|
61
60
|
yield self
|
62
61
|
end
|
63
|
-
|
64
|
-
# Views the remote inbox.
|
62
|
+
|
63
|
+
# Views the remote inbox. By default this call does NOT update the viewed
|
65
64
|
# or read status of the fax unless specified in options.
|
66
65
|
#
|
67
66
|
# @param status [String] Specify the status of the message you are listing (UNREAD, ALL, READ)
|
68
67
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
69
|
-
# @option options [String] :sPeriod Specify the period to query.
|
70
|
-
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at.
|
71
|
-
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at.
|
68
|
+
# @option options [String] :sPeriod Specify the period to query. Accepts 'ALL' or 'RANGE'
|
69
|
+
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at. Format is 'YYYYMMDD'
|
70
|
+
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at. Format is 'YYYYMMDD'
|
72
71
|
# @option options [String] :sIncludeSubUsers Include subuser accounts ('Y' or 'N')
|
73
72
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
74
73
|
#
|
75
|
-
# Example Payload for Return:
|
76
|
-
# {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
|
77
|
-
# "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
|
74
|
+
# Example Payload for Return:
|
75
|
+
# {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
|
76
|
+
# "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
|
78
77
|
# "Size"=>"5000", "ViewedStatus"=>"N"} ]}
|
79
78
|
def view_inbox(status = 'UNREAD', options = {})
|
80
|
-
logger.debug
|
81
|
-
postVariables = {
|
82
|
-
:
|
83
|
-
:
|
79
|
+
logger.debug 'Checking fax inbox from cloud service'
|
80
|
+
postVariables = {
|
81
|
+
action: 'Get_Fax_Inbox',
|
82
|
+
sViewedStatus: status.upcase
|
84
83
|
}.merge!(options)
|
85
84
|
res = execute(postVariables)
|
86
|
-
|
87
|
-
if res[:Status] !=
|
88
|
-
faxcount = res[
|
89
|
-
faxcount > 0 ? logger.debug("Found #{faxcount} new fax(es)") : logger.debug(
|
85
|
+
|
86
|
+
if res[:Status] != 'Failure'
|
87
|
+
faxcount = res['Result'].length
|
88
|
+
faxcount > 0 ? logger.debug("Found #{faxcount} new fax(es)") : logger.debug('No faxes found matching that criteria')
|
90
89
|
end
|
91
|
-
|
92
|
-
|
90
|
+
|
91
|
+
res
|
93
92
|
end
|
94
|
-
|
93
|
+
|
95
94
|
# Uses post Get_Usage to fetch the current account usage statistics (for all associated accounts)
|
96
95
|
#
|
97
96
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
98
|
-
# @option options [String] :sPeriod Specify the period to query.
|
99
|
-
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at.
|
100
|
-
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at.
|
97
|
+
# @option options [String] :sPeriod Specify the period to query. Accepts 'ALL' or 'RANGE'
|
98
|
+
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at. Format is 'YYYYMMDD'
|
99
|
+
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at. Format is 'YYYYMMDD'
|
101
100
|
# @option options [String] :sIncludeSubUsers Include subuser accounts ('Y' or 'N')
|
102
101
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
103
102
|
#
|
104
|
-
# Example Payload for Return:
|
105
|
-
# {"Status"=>"Success", "Result"=>[{"UserID"=>1234, "Period"=>"ALL",
|
103
|
+
# Example Payload for Return:
|
104
|
+
# {"Status"=>"Success", "Result"=>[{"UserID"=>1234, "Period"=>"ALL",
|
106
105
|
# "ClientName"=>nil, "SubUserID"=>0, "BillingNumber"=>"8888888888", "NumberOfFaxes"=>5, "NumberOfPages"=>8}]}
|
107
106
|
def view_usage(options = {})
|
108
|
-
logger.debug
|
109
|
-
postVariables = { :
|
107
|
+
logger.debug 'Viewing fax usage from cloud service'
|
108
|
+
postVariables = { action: 'Get_Fax_Usage' }
|
110
109
|
res = execute(postVariables)
|
111
|
-
|
110
|
+
res
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
# Uses post Get_Fax_Outbox to retrieve the usage for the account (and all subaccounts)
|
115
114
|
#
|
116
115
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
117
|
-
# @option options [String] :sPeriod Specify the period to query.
|
118
|
-
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at.
|
119
|
-
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at.
|
116
|
+
# @option options [String] :sPeriod Specify the period to query. Accepts 'ALL' or 'RANGE'
|
117
|
+
# @option options [String] :sStatDate Used with :sPeriod and denotes the period to start at. Format is 'YYYYMMDD'
|
118
|
+
# @option options [String] :sEndDate Used with :sPeriod and denotes the period to endd at. Format is 'YYYYMMDD'
|
120
119
|
# @option options [String] :sIncludeSubUsers Include subuser accounts ('Y' or 'N')
|
121
120
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
122
121
|
def view_outbox(options = {})
|
123
|
-
logger.debug
|
124
|
-
postVariables = { :
|
122
|
+
logger.debug 'Viewing fax outbox from cloud service'
|
123
|
+
postVariables = { action: 'Get_Fax_Outbox' }
|
125
124
|
res = execute(postVariables)
|
126
|
-
|
127
|
-
if res[:Status] !=
|
128
|
-
faxcount = res[
|
129
|
-
faxcount > 0 ? logger.debug("Found #{faxcount} new fax(es)") : logger.debug(
|
125
|
+
|
126
|
+
if res[:Status] != 'Failure'
|
127
|
+
faxcount = res['Result'].length
|
128
|
+
faxcount > 0 ? logger.debug("Found #{faxcount} new fax(es)") : logger.debug('No faxes found matching that criteria')
|
130
129
|
end
|
131
|
-
|
132
|
-
|
130
|
+
|
131
|
+
res
|
133
132
|
end
|
134
|
-
|
135
|
-
# Uses POST Retrieve_Fax to retrieve a specified fax from the server.
|
133
|
+
|
134
|
+
# Uses POST Retrieve_Fax to retrieve a specified fax from the server. Returns it in the default
|
136
135
|
# specified format (PDF or TIFF)
|
137
|
-
#
|
136
|
+
#
|
138
137
|
# @param descriptor [String] Specify the status of the message you are listing (UNREAD, ALL, READ)
|
139
138
|
# @param direction [String] Either 'IN' or 'OUT' to specify the inbox or outbox
|
140
139
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
141
140
|
# @option options [String] :sMarkasViewed Update the fax status to viewed (or unviewed). Accepts 'Y' or 'N'
|
142
141
|
# @option options [String] :sFaxFormat Update the format to retrieve the file in ('PDF' or 'TIFF')
|
143
142
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
144
|
-
def get_fax(descriptor, direction, options = {})
|
145
|
-
logger.debug "Retrieving fax from cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
|
146
|
-
faxname,faxid = descriptor.split('|')
|
147
|
-
if
|
148
|
-
logger.debug "Valid descriptor not provided to get_fax function call.
|
143
|
+
def get_fax(descriptor, direction, options = {})
|
144
|
+
logger.debug "Retrieving fax from cloud service in the direction of '#{direction}', Descriptor: '#{descriptor}'"
|
145
|
+
faxname, faxid = descriptor.split('|')
|
146
|
+
if faxname.nil? || faxid.nil?
|
147
|
+
logger.debug "Valid descriptor not provided to get_fax function call. Descriptor: '#{descriptor}'"
|
149
148
|
return nil
|
150
149
|
end
|
151
|
-
|
152
|
-
logger.debug
|
153
|
-
postVariables = {
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
150
|
+
|
151
|
+
logger.debug 'Retrieving fax from cloud service'
|
152
|
+
postVariables = {
|
153
|
+
action: 'Retrieve_Fax',
|
154
|
+
sFaxFileName: descriptor,
|
155
|
+
sFaxDetailsID: faxid,
|
156
|
+
sDirection: direction.upcase,
|
157
|
+
sMarkasViewed: 'N'
|
159
158
|
}.merge!(options)
|
160
159
|
res = execute(postVariables)
|
161
|
-
|
160
|
+
res
|
162
161
|
end
|
163
|
-
|
162
|
+
|
164
163
|
# Update the status (read/unread) for a particular fax
|
165
164
|
#
|
166
165
|
# @param descriptor [String] Specify the status of the message you are listing (UNREAD, ALL, READ)
|
167
166
|
# @param direction [String] Either 'IN' or 'OUT' to specify the inbox or outbox
|
168
167
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
169
|
-
# @option options [String] :sMarkasViewed Update the fax status to viewed (or unviewed). Accepts 'Y' or 'N'.
|
168
|
+
# @option options [String] :sMarkasViewed Update the fax status to viewed (or unviewed). Accepts 'Y' or 'N'. Defaults to Y
|
170
169
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
171
170
|
def update_fax_status(descriptor, direction, options = {})
|
172
|
-
logger.debug "Updating a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
|
173
|
-
faxname,faxid = descriptor.split('|')
|
174
|
-
if
|
175
|
-
logger.debug "Valid descriptor not provided to get_fax function call.
|
171
|
+
logger.debug "Updating a fax in the cloud service in the direction of '#{direction}', Descriptor: '#{descriptor}'"
|
172
|
+
faxname, faxid = descriptor.split('|')
|
173
|
+
if faxname.nil? || faxid.nil?
|
174
|
+
logger.debug "Valid descriptor not provided to get_fax function call. Descriptor: '#{descriptor}'"
|
176
175
|
return nil
|
177
176
|
end
|
178
177
|
|
179
|
-
postVariables = {
|
180
|
-
:
|
181
|
-
:
|
182
|
-
:
|
183
|
-
:
|
184
|
-
:
|
178
|
+
postVariables = {
|
179
|
+
action: 'Update_Viewed_Status',
|
180
|
+
sFaxFileName: descriptor,
|
181
|
+
sFaxDetailsID: faxid,
|
182
|
+
sDirection: direction.upcase,
|
183
|
+
sMarkasViewed: 'Y'
|
185
184
|
}.merge!(options)
|
186
185
|
res = execute(postVariables)
|
187
|
-
|
186
|
+
res
|
188
187
|
end
|
189
188
|
|
190
189
|
# Schedules a fax to be sent with or without cover page
|
191
190
|
#
|
192
191
|
# @param faxids [String, Array] Get the state of 'id' as given by the #queue_fax call
|
193
192
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
194
|
-
# @option options [String] :sResponseFormat The output response format for
|
193
|
+
# @option options [String] :sResponseFormat The output response format for
|
195
194
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
196
195
|
def get_fax_status(faxids, options = {})
|
197
|
-
logger.debug "Gathering fax status information for id(s):'#{faxids}'"
|
196
|
+
logger.debug "Gathering fax status information for id(s): '#{faxids}'"
|
198
197
|
|
199
198
|
if faxids.is_a? String
|
200
|
-
action =
|
199
|
+
action = 'Get_FaxStatus'
|
201
200
|
elsif faxids.is_a? Array
|
202
|
-
action =
|
201
|
+
action = 'Get_MultiFaxStatus'
|
203
202
|
faxids = faxids.join('|')
|
204
203
|
else
|
205
|
-
logger.warn "Error wth fax ids parameter id(s):'#{faxid}'"
|
206
|
-
return { :
|
204
|
+
logger.warn "Error wth fax ids parameter id(s): '#{faxid}'"
|
205
|
+
return { Status: 'Failure' }
|
207
206
|
end
|
208
207
|
|
209
|
-
postVariables = {
|
210
|
-
:
|
211
|
-
:
|
208
|
+
postVariables = {
|
209
|
+
action: action,
|
210
|
+
sFaxDetailsID: faxids
|
212
211
|
}.merge!(options)
|
213
212
|
res = execute(postVariables)
|
214
|
-
|
213
|
+
res
|
215
214
|
end
|
216
215
|
|
217
|
-
# Determines the state of a fax that has been scheduled for delivery.
|
218
|
-
# for delivery.
|
216
|
+
# Determines the state of a fax that has been scheduled for delivery. Use queue fax to schedule a fax
|
217
|
+
# for delivery. Note: no validation is done on the fields prior to sending.
|
219
218
|
#
|
220
219
|
# @param senderEmail [String] Email address of the sender
|
221
220
|
# @param receiverNumber [String, Array] Single 11 digit fax number or up to 50 x 11 fax numbers
|
222
221
|
# @param faxType [String] 'SINGLE' or 'BROADCAST'
|
223
222
|
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
224
|
-
# @option options [String] :sResponseFormat The output response format for
|
223
|
+
# @option options [String] :sResponseFormat The output response format for
|
225
224
|
# @option options [String] :sAccountCode Internal reference number (Max of 20 Characters)
|
226
225
|
# @option options [String] :sRetries Number of times the system is to retry a number if busy or an error is encountered – number from 0 to 6.
|
227
|
-
# @option options [String] :sCoverPage If you want to use one of the cover pages on file, specify the cover page you wish to use “Basic”, “Standard” , “Company” or “Personal”. If a cover page is not provided then all cover page variable will be ignored.
|
226
|
+
# @option options [String] :sCoverPage If you want to use one of the cover pages on file, specify the cover page you wish to use “Basic”, “Standard” , “Company” or “Personal”. If a cover page is not provided then all cover page variable will be ignored. NOTE: If the default cover page on the account is set to “Attachments ONLY” the cover page will NOT be created irrespective of this variable.
|
228
227
|
# @option options [String] :sFaxFromHeader From: On the Fax Header Line (max 30 Char)
|
229
228
|
# @option options [String] :sCPFromName Sender’s name on the Cover Page
|
230
229
|
# @option options [String] :sCPToName Recipient’s name on the Cover Page
|
@@ -234,39 +233,38 @@ module SrFax
|
|
234
233
|
# @option options [String] :sFileName_x (See supported file types @ https://www.srfax.com/faqs)
|
235
234
|
# @option options [String] :sFileContent_x Base64 encoding of file contents.
|
236
235
|
# @option options [String] :sNotifyURL Provide an absolute URL (beginning with http:// or https://) and the SRFax system will POST back the fax status record when the fax completes. See the ‘NOTIFY URL POST’ section below for details of what is posted.
|
237
|
-
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
236
|
+
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
238
237
|
#
|
239
238
|
# Example code (this will send a fax with 'Sample Fax' as the fileContent field):
|
240
|
-
# SrFax.queue_fax "yourname@yourdomain.com", "
|
239
|
+
# SrFax.queue_fax "yourname@yourdomain.com", "18888888888", "SINGLE", {sFileName_1: "file1.txt", sFileContent_1: Base64.encode64("Sample Fax")}
|
241
240
|
def queue_fax(senderEmail, receiverNumber, faxType, options = {})
|
242
|
-
logger.debug
|
241
|
+
logger.debug 'Attempting to queue fax'
|
243
242
|
receiverNumber = receiverNumber.join('|') if receiverNumber.is_a? Array
|
244
243
|
|
245
|
-
postVariables = {
|
246
|
-
:
|
247
|
-
:
|
248
|
-
:
|
249
|
-
:
|
244
|
+
postVariables = {
|
245
|
+
action: 'Queue_Fax',
|
246
|
+
sSenderEmail: senderEmail,
|
247
|
+
sFaxType: faxType,
|
248
|
+
sToFaxNumber: receiverNumber
|
250
249
|
}.merge!(options)
|
251
250
|
res = execute(postVariables)
|
252
|
-
|
251
|
+
res
|
253
252
|
end
|
254
|
-
|
255
|
-
# Attempt to stop a fax from being delivered.
|
253
|
+
|
254
|
+
# Attempt to stop a fax from being delivered. See the result payload for possible conditions in fax status
|
256
255
|
#
|
257
|
-
# @param faxid [String] Stop fax with 'id' as given by the #queue_fax call
|
258
|
-
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
|
256
|
+
# @param faxid [String] Stop fax with 'id' as given by the #queue_fax call.
|
257
|
+
# @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID).
|
259
258
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
260
259
|
def stop_fax(faxid, options = {})
|
261
|
-
|
262
|
-
logger.debug "Sending stop fax command for id:'#{faxid}'"
|
260
|
+
logger.debug "Sending stop fax command for id: '#{faxid}'"
|
263
261
|
|
264
|
-
postVariables = {
|
265
|
-
:
|
266
|
-
:
|
262
|
+
postVariables = {
|
263
|
+
action: 'Stop_Fax',
|
264
|
+
sFaxDetailsID: faxid
|
267
265
|
}.merge!(options)
|
268
266
|
res = execute(postVariables)
|
269
|
-
|
267
|
+
res
|
270
268
|
end
|
271
269
|
|
272
270
|
# Delete a particular fax from the SRFax cloud service
|
@@ -275,75 +273,48 @@ module SrFax
|
|
275
273
|
# @param direction [String] Either 'IN' or 'OUT' to specify the inbox or outbox
|
276
274
|
# @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
|
277
275
|
#
|
278
|
-
# Example Payload for Return:
|
279
|
-
# {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
|
280
|
-
# "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
|
276
|
+
# Example Payload for Return:
|
277
|
+
# {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
|
278
|
+
# "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
|
281
279
|
# "Size"=>"5000", "ViewedStatus"=>"N"} ]}
|
282
280
|
def delete_fax(descriptor, direction)
|
283
|
-
logger.debug "Deleting a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
|
284
|
-
faxname,faxid = descriptor.split('|')
|
285
|
-
if
|
286
|
-
logger.debug "Valid descriptor not provided to get_fax function call.
|
281
|
+
logger.debug "Deleting a fax in the cloud service in the direction of '#{direction}', Descriptor: '#{descriptor}'"
|
282
|
+
faxname, faxid = descriptor.split('|')
|
283
|
+
if faxname.nil? || faxid.nil?
|
284
|
+
logger.debug "Valid descriptor not provided to get_fax function call. Descriptor: '#{descriptor}'"
|
287
285
|
return nil
|
288
286
|
end
|
289
|
-
|
290
|
-
postVariables = {
|
291
|
-
:
|
292
|
-
:
|
293
|
-
:
|
294
|
-
:
|
287
|
+
|
288
|
+
postVariables = {
|
289
|
+
action: 'Delete_Fax',
|
290
|
+
sFaxFileName_x: descriptor,
|
291
|
+
sFaxDetailsID_x: faxid,
|
292
|
+
sDirection: direction.upcase
|
295
293
|
}
|
296
294
|
res = execute(postVariables)
|
297
|
-
|
295
|
+
res
|
298
296
|
end
|
299
297
|
|
300
298
|
private
|
301
299
|
|
302
300
|
# Actually execute the RESTful post command to the #BASE_URL
|
303
301
|
#
|
304
|
-
# @param postVariables [String] The list of variables to apply in the POST body when executing the request
|
305
|
-
# @return [Hash] The hash payload value including a proper status.
|
302
|
+
# @param postVariables [String] The list of variables to apply in the POST body when executing the request.
|
303
|
+
# @return [Hash] The hash payload value including a proper status. Will never return nil.
|
306
304
|
def execute(postVariables)
|
307
305
|
logger.debug postVariables.merge(defaults)
|
308
|
-
#
|
309
|
-
res = RestClient
|
310
|
-
|
311
|
-
|
312
|
-
:headers => {:accept => :json}) { |response, request, result, &block|
|
313
|
-
if [301, 302, 307].include? response.code
|
314
|
-
response.follow_redirection(request, result, &block)
|
315
|
-
elsif [200].include? response.code
|
316
|
-
# default behaviour for OK requests
|
317
|
-
response.return!(request, result, &block)
|
318
|
-
else
|
319
|
-
# suppress the throw's by RestClient
|
320
|
-
response = Oj.dump({"Status"=>"Failure", "Result"=>"#{response}"}, mode: :compat)
|
321
|
-
end
|
322
|
-
}
|
323
|
-
|
324
|
-
# res = RestClient.post(BASE_URL, postVariables.merge(defaults).to_json,
|
325
|
-
# :content_type => :json, :accept => :json,
|
326
|
-
# :timeout => connection_defaults[:timeout], :open_timeout => connection_defaults[:timeout] ){ |response, request, result, &block|
|
327
|
-
# if [301, 302, 307].include? response.code
|
328
|
-
# response.follow_redirection(request, result, &block)
|
329
|
-
# elsif [200].include? response.code
|
330
|
-
# # default behaviour
|
331
|
-
# response.return!(request, result, &block)
|
332
|
-
# else
|
333
|
-
# # suppress the throw's by RestClient
|
334
|
-
# response = {"Status"=>"Failure", "Result"=>"#{response}"}.to_json
|
335
|
-
# end
|
336
|
-
# }
|
337
|
-
return_data = nil
|
338
|
-
return_data = !res.nil? ? JSON.parse(res) : nil
|
339
|
-
|
340
|
-
if return_data.nil? || return_data.fetch("Status", "Failure") != "Success"
|
341
|
-
logger.debug "Execution of SR Fax command not successful"
|
342
|
-
return_data = { :Status => "Failure", :Result => return_data.fetch("Result", "") }
|
306
|
+
# Redirect where necessary.
|
307
|
+
res = RestClient.post(BASE_URL, postVariables.merge(defaults), { accept: :json })
|
308
|
+
unless res.code == 200
|
309
|
+
return { 'Status' => 'Failed', 'Result' => res.body }.with_indifferent_access
|
343
310
|
end
|
344
311
|
|
345
|
-
|
312
|
+
return_data = JSON.parse(res.body).with_indifferent_access
|
313
|
+
|
314
|
+
if return_data['Status'] == 'Failed'
|
315
|
+
logger.debug 'Execution of SR Fax command not successful'
|
316
|
+
end
|
317
|
+
return_data
|
346
318
|
end
|
347
319
|
end
|
348
320
|
end
|
349
|
-
|
data/srfax.gemspec
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'version
|
4
|
+
require 'srfax/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'sr_fax'
|
8
8
|
spec.version = SrFax::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Jeff Klink', 'Sean Esson', 'Brady Bouchard']
|
10
|
+
spec.email = ['techcanuck@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'SR Fax Module provides and easy way to access SR fax online services to send, receive or query faxes'
|
13
|
+
spec.description = "This is the 'unofficial' SRFax (http://www.srfax.com) API wrapper for ruby. The API documentation for SRFax can be found at https://www.srfax.com/srf/media/SRFax-REST-API-Documentation.pdf"
|
14
|
+
spec.homepage = 'https://github.com/TechCanuck/srfax'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'minitest'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rake', '~> 11.0'
|
25
|
+
spec.add_development_dependency 'pry', '~> 0.8'
|
26
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
26
27
|
spec.add_dependency 'logger', '~> 1'
|
27
|
-
spec.add_dependency '
|
28
|
-
spec.add_dependency '
|
29
|
-
spec.add_dependency 'rest-client', '~> 1.7'
|
28
|
+
spec.add_dependency 'activesupport', ['>= 4.2', '< 6']
|
29
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
30
30
|
end
|
metadata
CHANGED
@@ -1,16 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sr_fax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Klink
|
8
8
|
- Sean Esson
|
9
|
+
- Brady Bouchard
|
9
10
|
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: minitest
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
14
29
|
- !ruby/object:Gem::Dependency
|
15
30
|
name: bundler
|
16
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,14 +46,14 @@ dependencies:
|
|
31
46
|
requirements:
|
32
47
|
- - "~>"
|
33
48
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
49
|
+
version: '11.0'
|
35
50
|
type: :development
|
36
51
|
prerelease: false
|
37
52
|
version_requirements: !ruby/object:Gem::Requirement
|
38
53
|
requirements:
|
39
54
|
- - "~>"
|
40
55
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
56
|
+
version: '11.0'
|
42
57
|
- !ruby/object:Gem::Dependency
|
43
58
|
name: pry
|
44
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,48 +96,40 @@ dependencies:
|
|
81
96
|
- - "~>"
|
82
97
|
- !ruby/object:Gem::Version
|
83
98
|
version: '1'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: oj
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '2.11'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '2.11'
|
98
99
|
- !ruby/object:Gem::Dependency
|
99
100
|
name: activesupport
|
100
101
|
requirement: !ruby/object:Gem::Requirement
|
101
102
|
requirements:
|
102
|
-
- - "
|
103
|
+
- - ">="
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '4.2'
|
106
|
+
- - "<"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '6'
|
105
109
|
type: :runtime
|
106
110
|
prerelease: false
|
107
111
|
version_requirements: !ruby/object:Gem::Requirement
|
108
112
|
requirements:
|
109
|
-
- - "
|
113
|
+
- - ">="
|
110
114
|
- !ruby/object:Gem::Version
|
111
115
|
version: '4.2'
|
116
|
+
- - "<"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '6'
|
112
119
|
- !ruby/object:Gem::Dependency
|
113
120
|
name: rest-client
|
114
121
|
requirement: !ruby/object:Gem::Requirement
|
115
122
|
requirements:
|
116
123
|
- - "~>"
|
117
124
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
125
|
+
version: '2.0'
|
119
126
|
type: :runtime
|
120
127
|
prerelease: false
|
121
128
|
version_requirements: !ruby/object:Gem::Requirement
|
122
129
|
requirements:
|
123
130
|
- - "~>"
|
124
131
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
132
|
+
version: '2.0'
|
126
133
|
description: This is the 'unofficial' SRFax (http://www.srfax.com) API wrapper for
|
127
134
|
ruby. The API documentation for SRFax can be found at https://www.srfax.com/srf/media/SRFax-REST-API-Documentation.pdf
|
128
135
|
email:
|
@@ -139,7 +146,7 @@ files:
|
|
139
146
|
- bin/console
|
140
147
|
- bin/setup
|
141
148
|
- lib/srfax.rb
|
142
|
-
- lib/version.rb
|
149
|
+
- lib/srfax/version.rb
|
143
150
|
- srfax.gemspec
|
144
151
|
homepage: https://github.com/TechCanuck/srfax
|
145
152
|
licenses:
|
data/lib/version.rb
DELETED