class Restcomm::REST::Client

The Restcomm::REST::Client class caches authentication parameters and exposes methods to make HTTP requests to Restcomm’s REST API. However, you should never really need to call these methods yourself since you can work with the more pleasant wrapper objects like Restcomm::REST::Call.

Instantiate a client like so:

@client = Restcomm::REST::Client.new account_sid, auth_token

There are a few options you can use to configure the way your client will communicate with Restcomm. See new for a list and descriptions.

Once you have a client object you can use it to do fun things. Every client object exposes two wrapper objects which you can use as entry points into Restcomm: account and accounts.

@client.account

Most of the time you’ll want to start with the account attribute. This object is an instance of Restcomm::REST::Account that wraps the account referenced by the account_sid you used when instantiating the client.

An instance of Restcomm::REST::Account exposes objects wrapping all of the account-level Restcomm resources as properties. So

@client.account.calls

For convenience, the resources of the default account are also available on the client object. So the following call is equivalent to the example above

@client.calls

represents an account’s call list.

@client.accounts

If you are doing anything related to subaccounts you’ll want to start here. This object is an instance of Restcomm::REST::Accounts that wraps the list of accounts belonging to the master account referenced by the account_sid used to instantiate the client.

This class inherits from Restcomm::REST::ListResource, so you can use methods like ListResource#list to return a (possibly filtered) list of accounts and ListResource#create to create a new account. Use ListResource#get to grab a particular account once you know its sid.

Constants

API_VERSION

Attributes

account[R]
accounts[R]

Public Class Methods

new(*args) click to toggle source

Instantiate a new HTTP client to talk to Restcomm. The parameters account_sid and auth_token are required, unless you have configured them already using the block configure syntax, and used to generate the HTTP basic auth header in each request. The options parameter is a hash of connection configuration options. the following keys are supported:

host: 'api.restcomm.com'

The domain to which you’d like the client to make HTTP requests. Useful for testing. Defaults to ‘api.restcomm.com’.

port: 443

The port on which to connect to the above domain. Defaults to 443 and should be left that way except in testing environments.

use_ssl: true

Declare whether ssl should be used for connections to the above domain. Defaults to true and should be left alone except when testing.

ssl_verify_peer: true

Declare whether to verify the host’s ssl cert when setting up the connection to the above domain. Defaults to true, but can be turned off to avoid ssl certificate verification failures in environments without the necessary ca certificates.

ssl_ca_file: '/path/to/ca/file'

Specify the path to the certificate authority bundle you’d like to use to verify Restcomm’s SSL certificate on each request. If not specified, a certificate bundle extraced from Firefox is packaged with the gem and used by default.

timeout: 30

Set the time in seconds to wait before timing out the HTTP request. Defaults to 30 seconds. If you aren’t fetching giant pages of call or SMS logs you can safely decrease this to something like 3 seconds or lower. In paricular if you are sending SMS you can set this to 1 second or less and swallow the exception if you don’t care about the response.

proxy_addr: 'proxy.host.domain'

The domain of a proxy through which you’d like the client to make HTTP requests. Defaults to nil.

proxy_port: 3128

The port on which to connect to the above proxy. Defaults to nil.

proxy_user: 'username'

The user name to use for authentication with the proxy. Defaults to nil.

proxy_pass: 'password'

The password to use for authentication with the proxy. Defaults to nil.

retry_limit: 1

The number of times to retry a request that has failed before throwing an exception. Defaults to one.

Calls superclass method Restcomm::REST::BaseClient::new
    # File lib/restcomm-ruby/rest/client.rb
261 def initialize(*args)
262   super(*args)
263 end

Public Instance Methods

method_missing(method_name, *args, &block) click to toggle source

Delegate account methods from the client. This saves having to call client.account every time for resources on the default account.

Calls superclass method
    # File lib/restcomm-ruby/rest/client.rb
328 def method_missing(method_name, *args, &block)
329   if account.respond_to?(method_name)
330     account.send(method_name, *args, &block)
331   else
332     super
333   end
334 end
respond_to?(method_name, include_private=false) click to toggle source
Calls superclass method
    # File lib/restcomm-ruby/rest/client.rb
336 def respond_to?(method_name, include_private=false)
337   if account.respond_to?(method_name, include_private)
338     true
339   else
340     super
341   end
342 end

Protected Instance Methods

set_up_subresources() click to toggle source

Set up account and accounts attributes.

    # File lib/restcomm-ruby/rest/client.rb
348 def set_up_subresources # :doc:
349   @accounts = Restcomm::REST::Accounts.new "/#{API_VERSION}/Accounts", self
350   @account = @accounts.get @account_sid
351 end