Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created April 6, 2011 10:49
Show Gist options
  • Save rubiii/905461 to your computer and use it in GitHub Desktop.
Save rubiii/905461 to your computer and use it in GitHub Desktop.
Savon InterFAX example: Send a fax to multiple recipients
# more examples at:
# https://gist.github.com/903337
require "rubygems"
require "base64"
require "date"
# $ gem install savon (works with v0.9.1 and higher)
require "savon"
# convert hash key symbols to camelcase
Gyoku.convert_symbols_to(:camelcase)
# create a client using the InterFAX WSDL
client = Savon::Client.new("http://ws.interfax.net/dfs.asmx?wsdl")
# read a file from disk
image = File.read("/Users/rubiii/Desktop/important.png")
# execute a request to the :sendfax_ex_2 action
response = client.request(:int, :sendfax_ex_2) do
soap.body = {
:username => "your username",
:password => "your password",
:fax_numbers => "+18667700000;+18667700001",
:contacts => "Mac;Mary",
:files_data => Base64.encode64(image),
:file_types => "PNG",
:file_sizes => image.size,
:postpone => DateTime.parse("2011-05-26 01:00:00")
}
end
# translate the response to a Hash and get the result
result = response[:sendfax_ex_2_response][:sendfax_ex_2_result]
# print the result. returns for example: "56778" (the Transaction ID)
p result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment