Class: Voxbone

Inherits:
Object
  • Object
show all
Defined in:
lib/voxbone/voxbone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Object

Instantiate a Voxbone object

Examples:

Instantiate a Voxbone object

require 'rubygems'
require 'voxbone'
voxbone = Voxbone.new(:username   => 'test', 
                      :password   => 'test')

Parameters:

  • params (required, Hash)

Options Hash (params):

  • :username (required, String)

    for your Voxbone account

  • :password (required, String)

    for your Voxbone password

  • :base_uri (optional, String)

    for using an alternative URI, such as the Voxbone sandbox

  • :log_level (optional, String)

    for changing the Savon log levels

Raises:

  • ArgumentError when the :username or :password is not present



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/voxbone/voxbone.rb', line 19

def initialize(params)
  raise ArgumentError, ":username required" if params[:username].nil?
  raise ArgumentError, ":password required" if params[:password].nil?
  
  config_savon(params)
  @user_token = create_user_token(params)
  
  @client = Savon::Client.new do
    wsdl.document  = params[:base_uri] || 'http://www.voxbone.com/VoxAPI/services/VoxAPI?WSDL'
    wsdl.namespace = 'http://www.voxbone.com/VoxAPI'
  end
  
  @methods = @client.wsdl.soap_actions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, params = {}) ⇒ Hash

Provides the dispatcher to the available SOAP methods defined in the WSDL

Examples:

Retrieve a country list

voxbone.get_countries_list(:type => 'GEOGRAPHIC')

Parameters:

  • the (required, Symbol)

    method name to invoke on the SOAP API

  • the (optional, Hash)

    parameters to pass to the method, should be symbols and may be all lowercase with underscores

Returns:

  • (Hash)

    containing the results of the SOAP call

Raises:

  • NoMethodError if the method requested is not defined in the WSDL



43
44
45
46
47
48
49
50
51
52
# File 'lib/voxbone/voxbone.rb', line 43

def method_missing(method_name, params={})
  if @methods.include? method_name
    response = @client.request :vox, method_name do
      prepare_soap(soap, capitalize_params(params))
    end
    response.to_hash
  else
    raise NoMethodError, "The method #{method_name.to_s} does not exist."
  end
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



2
3
4
# File 'lib/voxbone/voxbone.rb', line 2

def methods
  @methods
end