Class: Interfax
- Inherits:
-
Object
- Object
- Interfax
- Defined in:
- lib/interfax.rb
Constant Summary collapse
- WSDL_URL =
"https://ws.interfax.net/dfs.asmx?WSDL"
Instance Method Summary collapse
- #cancel_file_upload(options = {}) ⇒ Object
- #client ⇒ Object
-
#initialize(options = {}) ⇒ Interfax
constructor
A new instance of Interfax.
- #sendfax_ex_2(options = {}) ⇒ Object
- #start_file_upload ⇒ Object
- #upload_file_chunk(file_path, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Interfax
Returns a new instance of Interfax.
6 7 8 9 10 11 12 |
# File 'lib/interfax.rb', line 6 def initialize( = {}) @username = [:username] || ENV['INTERFAX_USERNAME'] @password = [:password] || ENV['INTERFAX_PASSWORD'] @raw_response = {} @bytes_uploaded = 0 Gyoku.convert_symbols_to(:camelcase) end |
Instance Method Details
#cancel_file_upload(options = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/interfax.rb', line 41 def cancel_file_upload( = {}) session_id = .delete(:session_id) || @last_session_id return if session_id.nil? request :cancel_file_upload, :session_id => session_id end |
#client ⇒ Object
14 15 16 |
# File 'lib/interfax.rb', line 14 def client @client ||= ::Savon::Client.new(WSDL_URL) end |
#sendfax_ex_2(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/interfax.rb', line 47 def sendfax_ex_2( = {}) = { :retries_to_perform => 1, :page_size => 'A4', :page_orientation => 'Portrait', :is_high_resolution => false, :is_fine_rendering => true, } .merge!( :file_types => File.extname(@file_path)[1..4].upcase, :file_sizes => "#{@bytes_uploaded}/sessionID=#{@last_session_id}" ) unless @bytes_uploaded.zero? = .merge() [:is_high_resolution] = [:is_high_resolution] ? 1 : 0 unless [:is_high_resolution].is_a? Integer [:is_fine_rendering] = [:is_fine_rendering] ? 1 : 0 unless [:is_fine_rendering].is_a? Integer request :sendfax_ex_2, end |
#start_file_upload ⇒ Object
18 19 20 21 22 |
# File 'lib/interfax.rb', line 18 def start_file_upload @last_session_id = request :start_file_upload do |response| response[:session_id] end end |
#upload_file_chunk(file_path, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/interfax.rb', line 24 def upload_file_chunk(file_path, = {}) chunk_size = .delete(:chunk_size) || 200000 session_id = .delete(:session_id) || @last_session_id || start_file_upload @file_path = file_path each_chunk(chunk_size) do |chunk, is_last| request :upload_file_chunk, { :chunk => Base64.encode64(chunk), :SessionID => session_id, :IsLast => is_last ? 1 : 0 } do |response, result| @bytes_uploaded = result end end return @bytes_uploaded == File.size(@file_path) end |