sr_fax 0.2.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56a3f8e6fc0de9b9777780d6a53e07b0321d8dcc
4
- data.tar.gz: a0a385e62d210e72b916e66bc2607855074333d1
3
+ metadata.gz: b08b8fbb2726537e1c481371db271bd81a630689
4
+ data.tar.gz: 12939f123b696d6bc753e275cd18cf7821184f78
5
5
  SHA512:
6
- metadata.gz: 255ad2006904e751d180537d21de052a0038ee23d47405bd446f7e8d9eac9e83e395f3dc20b464972c2a2f6a290eb5ce1815c377861594b9b2a52dd020e8a0ce
7
- data.tar.gz: 6baffe09500daa159d920a1c6bcd088faf3c3c08310441b0c9f089aa2687379777c45629a9316119b1e45c21004caa751d0589f77f2d9397749eed1fc6b403f7
6
+ metadata.gz: b3ba7b257586a528df2983a692ba24fc77cbc115125882fa478c55917ac979674a25c3a220426dceccdabbb638d06f78a9debda3b4fab077d76274f6be5197ec
7
+ data.tar.gz: 03a576e0bc5b91855ff6737ae4dc1ac547673863d167d79e29f564a2f15639d4c5fc7cddbd17c7f08301cd8e53ae932a0bf0150d6f1be71d5e75e3b80bfb2f2f
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- group :development do
4
- gem "yard", "~> 0.8"
5
- end
6
-
7
3
  # Specify your gem's dependencies in srfax.gemspec
8
4
  gemspec
data/README.md CHANGED
@@ -22,9 +22,9 @@ Or install it yourself using:
22
22
 
23
23
  To get started, simply open the console view and require the SrFax module. Once you have completed that, enter your account credentials using the SrFax setup block, and then begin to execute calls. All status' returned are simply formatted hashes from the SrFax service.
24
24
 
25
- ```sh
25
+ ```ruby
26
26
 
27
- require 'SrFax'
27
+ require 'srfax'
28
28
 
29
29
  SrFax.setup do |config|
30
30
  config.defaults[:access_id] = '1234'
@@ -37,6 +37,12 @@ SrFax.update_fax_status(descriptor, direction)
37
37
  SrFax.get_fax(descriptor, direction, {:sMarkasViewed => 'Y'}
38
38
  ```
39
39
 
40
+ As an example, here is a sample queue fax call to send a fax
41
+
42
+ ```ruby
43
+ SrFax.queue_fax "yourname@yourdomain.com", "SINGLE", "18888888888", {sFileName_1: "file1.txt", sFileContent_1: Base64.encode64("Sample Fax")}
44
+ ```
45
+
40
46
  The SrFax module currently supports the following functions
41
47
  - Sending and receiving faxes
42
48
  - Updating flags on the inbox or outbox faxes
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "SrFax"
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.
data/lib/srfax.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'RestClient'
1
+ require 'restclient'
2
2
  require 'active_support'
3
+ require 'active_support/core_ext/hash'
4
+ require 'version'
3
5
 
4
6
  # This class serves as the integration component between the application and the SRFax cloud service.
5
7
  # API DOX available @ https://www.srfax.com/srf/media/SRFax-REST-API-Documentation.pdf.
@@ -12,18 +14,15 @@ require 'active_support'
12
14
  # Get_Fax_Outbox - Returns a list of faxes sent for a specified period of time
13
15
  # Retrieve_Fax – Returns a specified sent or received fax file in PDF or TIFF format
14
16
  # Delete_Fax - Deletes specified received or sent faxes
15
- #
16
- # Unimplemented:
17
17
  # Get_FaxStatus – Determines the status of a fax that has been scheduled for delivery.
18
18
  # Get_MultiFaxStatus – Determines the status of a multiple faxes that hav been
19
19
  # scheduled for delivery.
20
- # Delete_Pending_Fax - Deletes a specified queued fax which has not been processed
21
20
  # Stop_Fax - Removes a scheduled fax from the queue
21
+ # Unimplemented methods:
22
+ # Delete_Pending_Fax - THIS DOESN'T EXIST - but is documented to exist
22
23
  module SrFax
23
- VERSION = '0.3.0pre'
24
-
25
24
  # Base URL for accessing SRFax API
26
- BASE_URI = "https://www.srfax.com/SRF_SecWebSvc.php"
25
+ BASE_URL = "https://www.srfax.com/SRF_SecWebSvc.php"
27
26
 
28
27
  mattr_accessor :defaults
29
28
  # Default values hash to use with all #execute commands
@@ -31,12 +30,14 @@ module SrFax
31
30
  access_id: '1234',
32
31
  access_pwd: 'password',
33
32
  sFaxFormat: 'PDF', # Default format, PDF or TIF
33
+ sCallerID: '5555555555', # MUST be 10 digits
34
34
  sResponseFormat: 'JSON' # XML or JSON
35
35
  }
36
36
 
37
37
  mattr_accessor :logger
38
38
  # Logger object for use in standalone modeo or with Rails
39
39
  @@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
40
+ @@logger.level = Logger::INFO
40
41
 
41
42
  class << self
42
43
  # Allow configuring Srfax with a block, these will be the methods default values for passing to
@@ -48,6 +49,7 @@ module SrFax
48
49
  # Srfax.setup do |config|
49
50
  # config.defaults[:access_id] = '1234'
50
51
  # config.defaults[:access_pwd] = 'password'
52
+ # config.defaults[:sCallerID] = '5555555555'
51
53
  # end
52
54
  def setup(&block)
53
55
  yield self
@@ -66,10 +68,10 @@ module SrFax
66
68
  #
67
69
  # Example Payload for Return:
68
70
  # {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
69
- # "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"9056193547", "RemoteID"=>"", "Pages"=>"1",
71
+ # "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
70
72
  # "Size"=>"5000", "ViewedStatus"=>"N"} ]}
71
73
  def view_inbox(status = 'UNREAD', options = {})
72
- logger.info("Checking fax inbox from cloud service")
74
+ logger.debug "Checking fax inbox from cloud service"
73
75
  postVariables = {
74
76
  :action => "Get_Fax_Inbox",
75
77
  :sViewedStatus => status.upcase
@@ -95,13 +97,9 @@ module SrFax
95
97
  #
96
98
  # Example Payload for Return:
97
99
  # {"Status"=>"Success", "Result"=>[{"UserID"=>1234, "Period"=>"ALL",
98
- # "ClientName"=>nil, "SubUserID"=>0, "BillingNumber"=>"8669906402", "NumberOfFaxes"=>5, "NumberOfPages"=>8}]}
99
- #
100
- # optional variables
101
- # sPeriod: (ALL or RANGE), sStartDate: YYYYMMDD, sEndDate: YYYYMMDD
102
- # sIncludeSubUsers: Y or N (if you want to see all faxes on subaccounts as well)
100
+ # "ClientName"=>nil, "SubUserID"=>0, "BillingNumber"=>"8888888888", "NumberOfFaxes"=>5, "NumberOfPages"=>8}]}
103
101
  def view_usage(options = {})
104
- logger.info "Viewing fax usage from cloud service"
102
+ logger.debug "Viewing fax usage from cloud service"
105
103
  postVariables = { :action => "Get_Fax_Usage" }
106
104
  res = execute(postVariables)
107
105
  return res
@@ -116,7 +114,7 @@ module SrFax
116
114
  # @option options [String] :sIncludeSubUsers Include subuser accounts ('Y' or 'N')
117
115
  # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
118
116
  def view_outbox(options = {})
119
- logger.info "Viewing fax outbox from cloud service"
117
+ logger.debug "Viewing fax outbox from cloud service"
120
118
  postVariables = { :action => "Get_Fax_Outbox" }
121
119
  res = execute(postVariables)
122
120
 
@@ -138,14 +136,14 @@ module SrFax
138
136
  # @option options [String] :sFaxFormat Update the format to retrieve the file in ('PDF' or 'TIFF')
139
137
  # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
140
138
  def get_fax(descriptor, direction, options = {})
141
- logger.info "Retrieving fax from cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
139
+ logger.debug "Retrieving fax from cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
142
140
  faxname,faxid = descriptor.split('|')
143
141
  if (faxname.nil? or faxid.nil?)
144
- logger.info "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
142
+ logger.debug "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
145
143
  return nil
146
144
  end
147
145
 
148
- logger.info "Retrieving fax from cloud service"
146
+ logger.debug "Retrieving fax from cloud service"
149
147
  postVariables = {
150
148
  :action => "Retrieve_Fax",
151
149
  :sFaxFileName => descriptor,
@@ -165,10 +163,10 @@ module SrFax
165
163
  # @option options [String] :sMarkasViewed Update the fax status to viewed (or unviewed). Accepts 'Y' or 'N'. Defaults to Y
166
164
  # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
167
165
  def update_fax_status(descriptor, direction, options = {})
168
- logger.info "Updating a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
166
+ logger.debug "Updating a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
169
167
  faxname,faxid = descriptor.split('|')
170
168
  if (faxname.nil? or faxid.nil?)
171
- logger.info "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
169
+ logger.debug "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
172
170
  return nil
173
171
  end
174
172
 
@@ -182,7 +180,89 @@ module SrFax
182
180
  res = execute(postVariables)
183
181
  return res
184
182
  end
183
+
184
+ # Schedules a fax to be sent with or without cover page
185
+ #
186
+ # @param faxids [String, Array] Get the state of 'id' as given by the #queue_fax call
187
+ # @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
188
+ # @option options [String] :sResponseFormat The output response format for
189
+ # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
190
+ def get_fax_status(faxids, options = {})
191
+ logger.debug "Gathering fax status information for id(s):'#{faxids}'"
192
+
193
+ if faxids.is_a? String
194
+ action = "Get_FaxStatus"
195
+ elsif faxids.is_a? Array
196
+ action = "Get_MultiFaxStatus"
197
+ faxids = faxids.join('|')
198
+ else
199
+ logger.warn "Error wth fax ids parameter id(s):'#{faxid}'"
200
+ return { :Status => "Failure" }
201
+ end
202
+
203
+ postVariables = {
204
+ :action => action,
205
+ :sFaxDetailsID => faxids
206
+ }.merge!(options)
207
+ res = execute(postVariables)
208
+ return res
209
+ end
210
+
211
+ # Determines the state of a fax that has been scheduled for delivery. Use queue fax to schedule a fax
212
+ # for delivery. Note: no validation is done on the fields prior to sending.
213
+ #
214
+ # @param senderEmail [String] Email address of the sender
215
+ # @param receiverNumber [String, Array] Single 11 digit fax number or up to 50 x 11 fax numbers
216
+ # @param faxType [String] 'SINGLE' or 'BROADCAST'
217
+ # @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
218
+ # @option options [String] :sResponseFormat The output response format for
219
+ # @option options [String] :sAccountCode Internal reference number (Max of 20 Characters)
220
+ # @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.
221
+ # @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.
222
+ # @option options [String] :sFaxFromHeader From: On the Fax Header Line (max 30 Char)
223
+ # @option options [String] :sCPFromName Sender’s name on the Cover Page
224
+ # @option options [String] :sCPToName Recipient’s name on the Cover Page
225
+ # @option options [String] :sCPOrganization Organization on the Cover Page
226
+ # @option options [String] :sCPSubject Subject line on the Cover Page**
227
+ # @option options [String] :sCPComments Comments placed in the body of the Cover Page
228
+ # @option options [String] :sFileName_x (See supported file types @ https://www.srfax.com/faqs)
229
+ # @option options [String] :sFileContent_x Base64 encoding of file contents.
230
+ # @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.
231
+ # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
232
+ #
233
+ # Example code (this will send a fax with 'Sample Fax' as the fileContent field):
234
+ # SrFax.queue_fax "yourname@yourdomain.com", "SINGLE", "18888888888", {sFileName_1: "file1.txt", sFileContent_1: Base64.encode64("Sample Fax")}
235
+ def queue_fax(senderEmail, receiverNumber, faxType, options = {})
236
+ logger.debug "Attempting to queue fax"
237
+ receiverNumber = receiverNumber.join('|') if receiverNumber.is_a? Array
238
+
239
+ postVariables = {
240
+ :action => "Queue_Fax",
241
+ :sSenderEmail => senderEmail,
242
+ :sFaxType => faxType,
243
+ :sToFaxNumber => receiverNumber
244
+ }.merge!(options)
245
+ res = execute(postVariables)
246
+ return res
247
+ end
185
248
 
249
+ # Attempt to stop a fax from being delivered. See the result payload for possible condiitions in fax status
250
+ #
251
+ # @param faxid [String] Stop fax with 'id' as given by the #queue_fax call
252
+ # @param options [Hash] An optional hash paramter to ovveride any default values (ie., Account ID)
253
+ # @return [Hash] A hash containing the return value (Success/Failure) and the payload where applicable
254
+ def stop_fax(faxid, options = {})
255
+ action = nil
256
+ logger.debug "Sending stop fax command for id:'#{faxid}'"
257
+
258
+ postVariables = {
259
+ :action => 'Stop_Fax',
260
+ :sFaxDetailsID => faxid
261
+ }.merge!(options)
262
+ res = execute(postVariables)
263
+ return res
264
+ end
265
+
186
266
  # Delete a particular fax from the SRFax cloud service
187
267
  #
188
268
  # @param descriptor [String] THe descriptor provided by SRFax which identifies a unique fax
@@ -191,15 +271,13 @@ module SrFax
191
271
  #
192
272
  # Example Payload for Return:
193
273
  # {"Status"=>"Success", "Result"=>[{"FileName"=>"20150430124505-6104-19_1|20360095", "ReceiveStatus"=>"Ok",
194
- # "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"9056193547", "RemoteID"=>"", "Pages"=>"1",
274
+ # "Date"=>"Apr 30/15 02:45 PM", "EpochTime"=>1430423105, "CallerID"=>"5555555555", "RemoteID"=>"", "Pages"=>"1",
195
275
  # "Size"=>"5000", "ViewedStatus"=>"N"} ]}
196
- # :direction is either 'IN' or 'OUT' for inbox or outbox
197
- # :descriptor is what is returns from the POST Filename field from the view_inbox result
198
276
  def delete_fax(descriptor, direction)
199
- logger.info "Deleting a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
277
+ logger.debug "Deleting a fax in the cloud service in the direction of '#{direction}', Descriptor:'#{descriptor}'"
200
278
  faxname,faxid = descriptor.split('|')
201
279
  if (faxname.nil? or faxid.nil?)
202
- logger.info "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
280
+ logger.debug "Valid descriptor not provided to get_fax function call. Descriptor:'#{descriptor}'"
203
281
  return nil
204
282
  end
205
283
 
@@ -215,21 +293,22 @@ module SrFax
215
293
 
216
294
  private
217
295
 
218
- # Actually execute the RESTful post command to the #BASE_URI
296
+ # Actually execute the RESTful post command to the #BASE_URL
219
297
  #
220
298
  # @param postVariables [String] The list of variables to apply in the POST body when executing the request
221
299
  # @return [Hash] The hash payload value including a proper status. Will never return nil.
222
300
  def execute(postVariables)
223
- res = RestClient::Request.execute :url => BASE_URI, :method => :post, :payload => postVariables.merge(defaults).to_json, :content_type => :json, :accept => :json
301
+ logger.debug postVariables.merge(defaults)
302
+ res = RestClient.post BASE_URL, postVariables.merge(defaults).to_json, :content_type => :json, :accept => :json
224
303
  return_data = nil
225
304
  return_data = JSON.parse(res) if res
226
305
 
227
306
  if return_data.nil? || return_data.fetch("Status", "Failure") != "Success"
228
- logger.info "Execution of SR Fax command not successful"
229
- return_data = { :Status => "Failure" }
307
+ logger.debug "Execution of SR Fax command not successful"
308
+ return_data = { :Status => "Failure", :Result => return_data.fetch("Result", "") }
230
309
  end
231
310
 
232
- return return_data
311
+ return return_data.with_indifferent_access
233
312
  end
234
313
  end
235
314
  end
data/lib/version.rb ADDED
@@ -0,0 +1,4 @@
1
+ module SrFax
2
+ # Version # for SrFax
3
+ VERSION = '0.4.0'
4
+ end
data/srfax.gemspec CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_runtime_dependency 'logger', '~> 1'
25
- spec.add_runtime_dependency 'activesupport', '~> 4.2'
26
- spec.add_runtime_dependency 'rest-client', '~> 1.7'
24
+ spec.add_development_dependency "pry", "~> 0.8"
25
+ spec.add_development_dependency "yard", "~> 0.8"
26
+ spec.add_dependency 'logger', '~> 1'
27
+ spec.add_dependency 'activesupport', '~> 4.2'
28
+ spec.add_dependency 'rest-client', '~> 1.7'
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sr_fax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Klink
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-05-12 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.7'
20
+ version: '1.6'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.7'
27
+ version: '1.6'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -39,6 +39,34 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.8'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.8'
56
+ - !ruby/object:Gem::Dependency
57
+ name: yard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.8'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.8'
42
70
  - !ruby/object:Gem::Dependency
43
71
  name: logger
44
72
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +125,7 @@ files:
97
125
  - bin/console
98
126
  - bin/setup
99
127
  - lib/srfax.rb
128
+ - lib/version.rb
100
129
  - srfax.gemspec
101
130
  homepage: https://github.com/TechCanuck/srfax
102
131
  licenses: