A Ruby gem for interacting with the Phaxio API.
NOTE: Versions of this gem before 2.1.0.0 are considered "beta". Breaking changes may be more common in this period.
Add to your application's Gemfile:
gem 'phaxio', '2.1.0.0'And then execute:
$ bundle installOr install it yourself as:
$ gem install phaxioSet up your API Key, API Secret, and, optionally, Callback Token.
Phaxio.api_key = '11111'
Phaxio.api_secret = '22222'
Phaxio.callback_token = '33333'Try sending a fax:
fax_file = File.open 'test.pdf', 'rb'
Phaxio::Fax.create to: '+15558675309', file: fax_fileYou can include Phaxio::Resources to pull in the resource classes for convenience:
include Phaxio::Resources
fax_file = File.open 'test.pdf', 'rb'
Fax.create to: '+15558675309', file: fax_fileCreate and send a fax.
fax_file = File.open 'test.pdf', 'rb'
ref = Fax.create to: '+15558675309', file: fax_file
# => Fax::Reference(id: 1234)
fax = ref.get
# => Fax(id: 1234, num_pages: 1, ...)List faxes in date range.
start = 2.weeks.ago
stop = 1.week.ago
faxes = Fax.list created_after: start, created_before: stop
# => Phaxio::Resource::Collection([Fax(id: 1234, ...), ...])
faxes.length
# => 5
faxes.map(&:cost).inject(&:+)
# => 35Get information about a specific fax.
fax = Fax.get 1234
# => Fax(id: 1234, ...)Cancel a fax.
Fax.cancel 1234
# => Fax::Reference(id: 1234)Resend a fax.
Fax.resend 1234
# => Fax::Reference(id: 5678)Delete a fax. Only test faxes are allowed to be deleted.
Fax.delete 1234
# => trueDelete fax file.
Fax.delete_file 1234
# => trueFax.file 1234
# => FileTest receiving a fax.
fax_file = File.open 'test.pdf', 'rb'
Fax.test_receive file: fax_file
# => trueGet a list of supported countries.
Fax.supported_countries
# => Phaxio::Resource::Collection([Country(alpha2: 'US', ...), ...])Provision a new phone number.
PhoneNumber.create country_code: 1, area_code: 555
# => PhoneNumber(phone_number: '+15558675309', ...)List phone numbers that you own on Phaxio.
PhoneNumber.list
# => Phaxio::Resource::Collection([PhoneNumber(phone_number: '+15558675309', ...), ...])Get information about a specific phone number.
PhoneNumber.get '+15558675309'
# => PhoneNumber(phone_number: '+15558675309', ...)Release a phone number.
PhoneNumber.delete '+15558675309'
# => trueLists available area codes for purchasing Phaxio numbers.
phone_numbers = PhoneNumber.list_available_area_codes toll_free: true
# => Phaxio::Resource::Collection([AreaCode(city: 'Chicago', ...), ...], page: 1)Creates a PhaxCode. Returns data about the PhaxCode by default, or a .png file if type: 'png' is
passed.
PhaxCode.create metadata: 'test_phax_code'
# => PhaxCode(identifier: 'phax-code-identifier')
PhaxCode.create type: 'png'
# => FileGets a PhaxCode. Returns data about the PhaxCode by default, or a .png file if type: 'png' is
passed.
PhaxCode.get 'phax-code-identifier'
# => PhaxCode(identifier: 'phax-code-identifier', metadata: 'phax-code-metadata')
PhaxCode.get 'phax-code-identifier', type: 'png'
# => FileGet information about your Phaxio account.
Account.get
# => Account(balance: 1000, faxes_today: 0, faxes_this_month: 100)Validate the callback signature sent with a Phaxio callback. Requires that Phaxio.callback_token be set.
Callback.valid_signature? received_signature, callback_url, received_params, received_files
# => truerequire 'sinatra/base'
require 'phaxio'
class PhaxioCallbackExample < Sinatra::Base
Phaxio.config do |config|
config.api_key = '0123456789'
config.api_secret = '0123456789'
config.callback_token = '0123456789'
end
post '/phaxio_callback' do
signature = request.env['HTTP_X_PHAXIO_SIGNATURE']
url = request.url
file_params = params[:filename]
if Phaxio::Callback.valid_signature? signature, url, callback_params, file_params
'Success'
else
'Invalid callback signature'
end
end
def callback_params
params.select do |key, _value|
%w(success is_test direction fax metadata message).include?(key)
end
end
end- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Versions consist of four parts. The first corresponds to the supported Phaxio API version, the second to the major version of the gem itself, the third to the minor version of the gem, and the fourth to the patch level of the gem.