Class: VoiceML::Client

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

Overview

Synchronous client for the VoiceML REST API.

VoiceML uses HTTP Basic auth: the account_sid (Twilio-format AC + 32 hex) is the username and api_key is the password. Drop-in compatible with the Twilio Ruby SDK constructor signature.

Examples:

client = VoiceML::Client.new(account_sid: 'AC...', api_key: '...')
call = client.calls.create(
  to: '+18005551234',
  from: '+18005550000',
  url: 'https://example.com/twiml'
)
puts call.sid, call.status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_sid:, api_key: nil, auth_token: nil, base_url: Transport::DEFAULT_BASE_URL, timeout: Transport::DEFAULT_TIMEOUT, max_retries: Transport::DEFAULT_MAX_RETRIES, user_agent: nil, http_client: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • account_sid (String)

    Twilio-format AccountSid (AC + 32 hex).

  • api_key (String, nil) (defaults to: nil)

    per-tenant API key. Pass either api_key: or the Twilio-compatible alias auth_token: (not both — ArgumentError if you do).

  • auth_token (String, nil) (defaults to: nil)

    Twilio-compatible alias for api_key. Lets twilio-ruby code (VoiceML::Client.new(account_sid: sid, auth_token: token)) work unchanged.

  • base_url (String) (defaults to: Transport::DEFAULT_BASE_URL)

    server base URL. Defaults to https://voiceml.voicetel.com.

  • timeout (Numeric) (defaults to: Transport::DEFAULT_TIMEOUT)

    per-request timeout in seconds. Defaults to 30.

  • max_retries (Integer) (defaults to: Transport::DEFAULT_MAX_RETRIES)

    retry attempts for 429/5xx and transport errors. Defaults to 2.

  • user_agent (String, nil) (defaults to: nil)

    override the User-Agent header. Defaults to "voiceml-ruby/#{VERSION}".



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/voiceml/client.rb', line 49

def initialize(account_sid:, api_key: nil, auth_token: nil,
               base_url: Transport::DEFAULT_BASE_URL,
               timeout: Transport::DEFAULT_TIMEOUT,
               max_retries: Transport::DEFAULT_MAX_RETRIES,
               user_agent: nil, http_client: nil)
  if !api_key.nil? && !auth_token.nil?
    raise ArgumentError, 'pass either api_key: or auth_token:, not both'
  end

  resolved_key = api_key || auth_token

  @transport = Transport.new(
    account_sid: ,
    api_key:     resolved_key,
    base_url:    base_url,
    timeout:     timeout,
    max_retries: max_retries,
    user_agent:  user_agent,
    http_client: http_client
  )

  @calls                  = CallsResource.new(@transport)
  @conferences            = ConferencesResource.new(@transport)
  @queues                 = QueuesResource.new(@transport)
  @applications           = ApplicationsResource.new(@transport)
  @recordings             = RecordingsResource.new(@transport)
  @incoming_phone_numbers = IncomingPhoneNumbersResource.new(@transport)
  @notifications          = NotificationsResource.new(@transport)
  @diagnostics            = DiagnosticsResource.new(@transport)
  @messages               = MessagesResource.new(@transport)
  @sip                    = SipResource.new(@transport)
  @routes_v2              = RoutesV2Resource.new(@transport)
  @voice_v1               = VoiceV1Resource.new(@transport)
  @conversations_v1       = ConversationsV1Resource.new(@transport)
  @assistants_v1          = AssistantsV1Resource.new(@transport)
end

Instance Attribute Details

#applicationsObject (readonly)

Returns the value of attribute applications.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def applications
  @applications
end

#assistants_v1Object (readonly)

Returns the value of attribute assistants_v1.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def assistants_v1
  @assistants_v1
end

#callsObject (readonly)

Returns the value of attribute calls.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def calls
  @calls
end

#conferencesObject (readonly)

Returns the value of attribute conferences.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def conferences
  @conferences
end

#conversations_v1Object (readonly)

Returns the value of attribute conversations_v1.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def conversations_v1
  @conversations_v1
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def diagnostics
  @diagnostics
end

#incoming_phone_numbersObject (readonly)

Returns the value of attribute incoming_phone_numbers.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def incoming_phone_numbers
  @incoming_phone_numbers
end

#messagesObject (readonly)

Returns the value of attribute messages.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def messages
  @messages
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def notifications
  @notifications
end

#queuesObject (readonly)

Returns the value of attribute queues.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def queues
  @queues
end

#recordingsObject (readonly)

Returns the value of attribute recordings.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def recordings
  @recordings
end

#routes_v2Object (readonly)

Returns the value of attribute routes_v2.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def routes_v2
  @routes_v2
end

#sipObject (readonly)

Returns the value of attribute sip.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def sip
  @sip
end

#voice_v1Object (readonly)

Returns the value of attribute voice_v1.



35
36
37
# File 'lib/voiceml/client.rb', line 35

def voice_v1
  @voice_v1
end

Instance Method Details

#account_sidObject



86
87
88
# File 'lib/voiceml/client.rb', line 86

def 
  @transport.
end

#base_urlObject



90
91
92
# File 'lib/voiceml/client.rb', line 90

def base_url
  @transport.base_url
end