## # This code was generated by # ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ # | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ # | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ # # Twilio - Api # This is the public Twilio REST API. # # NOTE: This class is auto generated by OpenAPI Generator. # https://openapi-generator.tech # Do not edit the class manually. # module Twilio module REST class Api < ApiBase class V2010 < Version class AccountContext < InstanceContext class CallList < ListResource ## # Initialize the CallList # @param [Version] version Version that contains the resource # @return [CallList] CallList def initialize(version, account_sid: nil) super(version) # Path Solution @solution = { account_sid: account_sid } @uri = "/Accounts/#{@solution[:account_sid]}/Calls.json" end ## # Create the CallInstance # @param [String] to The phone number, SIP address, or client identifier to call. # @param [String] from The phone number or client identifier to use as the caller id. If using a phone number, it must be a Twilio number or a Verified [outgoing caller id](https://www.twilio.com/docs/voice/api/outgoing-caller-ids) for your account. If the `to` parameter is a phone number, `From` must also be a phone number. # @param [String] method The HTTP method we should use when calling the `url` parameter's value. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] fallback_url The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] fallback_method The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] status_callback The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted). # @param [Array[String]] status_callback_event The call progress events that we will send to the `status_callback` URL. Can be: `initiated`, `ringing`, `answered`, and `completed`. If no event is specified, we send the `completed` status. If you want to receive multiple events, specify each one in a separate `status_callback_event` parameter. See the code sample for [monitoring call progress](https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-create-a-call-resource-and-specify-a-statuscallbackevent&code-sdk-version=json). If an `application_sid` is present, this parameter is ignored. # @param [String] status_callback_method The HTTP method we should use when calling the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] send_digits A string of keys to dial after connecting to the number, maximum of 32 digits. Valid digits in the string include: any digit (`0`-`9`), '`#`', '`*`' and '`w`', to insert a half second pause. For example, if you connected to a company phone number and wanted to pause for one second, and then dial extension 1234 followed by the pound key, the value of this parameter would be `ww1234#`. Remember to URL-encode this string, since the '`#`' character has special meaning in a URL. If both `SendDigits` and `MachineDetection` parameters are provided, then `MachineDetection` will be ignored. # @param [String] timeout The integer number of seconds that we should allow the phone to ring before assuming there is no answer. The default is `60` seconds and the maximum is `600` seconds. For some call flows, we will add a 5-second buffer to the timeout value you provide. For this reason, a timeout value of 10 seconds could result in an actual timeout closer to 15 seconds. You can set this to a short time, such as `15` seconds, to hang up before reaching an answering machine or voicemail. # @param [Boolean] record Whether to record the call. Can be `true` to record the phone call, or `false` to not. The default is `false`. The `recording_url` is sent to the `status_callback` URL. # @param [String] recording_channels The number of channels in the final recording. Can be: `mono` or `dual`. The default is `mono`. `mono` records both legs of the call in a single channel of the recording file. `dual` records each leg to a separate channel of the recording file. The first channel of a dual-channel recording contains the parent call and the second channel contains the child call. # @param [String] recording_status_callback The URL that we call when the recording is available to be accessed. # @param [String] recording_status_callback_method The HTTP method we should use when calling the `recording_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. # @param [String] sip_auth_username The username used to authenticate the caller making a SIP call. # @param [String] sip_auth_password The password required to authenticate the user account specified in `sip_auth_username`. # @param [String] machine_detection Whether to detect if a human, answering machine, or fax has picked up the call. Can be: `Enable` or `DetectMessageEnd`. Use `Enable` if you would like us to return `AnsweredBy` as soon as the called party is identified. Use `DetectMessageEnd`, if you would like to leave a message on an answering machine. If `send_digits` is provided, this parameter is ignored. For more information, see [Answering Machine Detection](https://www.twilio.com/docs/voice/answering-machine-detection). # @param [String] machine_detection_timeout The number of seconds that we should attempt to detect an answering machine before timing out and sending a voice request with `AnsweredBy` of `unknown`. The default timeout is 30 seconds. # @param [Array[String]] recording_status_callback_event The recording status events that will trigger calls to the URL specified in `recording_status_callback`. Can be: `in-progress`, `completed` and `absent`. Defaults to `completed`. Separate multiple values with a space. # @param [String] trim Whether to trim any leading and trailing silence from the recording. Can be: `trim-silence` or `do-not-trim` and the default is `trim-silence`. # @param [String] caller_id The phone number, SIP address, or Client identifier that made this call. Phone numbers are in [E.164 format](https://wwnw.twilio.com/docs/glossary/what-e164) (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. # @param [String] machine_detection_speech_threshold The number of milliseconds that is used as the measuring stick for the length of the speech activity, where durations lower than this value will be interpreted as a human and longer than this value as a machine. Possible Values: 1000-6000. Default: 2400. # @param [String] machine_detection_speech_end_threshold The number of milliseconds of silence after speech activity at which point the speech activity is considered complete. Possible Values: 500-5000. Default: 1200. # @param [String] machine_detection_silence_timeout The number of milliseconds of initial silence after which an `unknown` AnsweredBy result will be returned. Possible Values: 2000-10000. Default: 5000. # @param [String] async_amd Select whether to perform answering machine detection in the background. Default, blocks the execution of the call until Answering Machine Detection is completed. Can be: `true` or `false`. # @param [String] async_amd_status_callback The URL that we should call using the `async_amd_status_callback_method` to notify customer application whether the call was answered by human, machine or fax. # @param [String] async_amd_status_callback_method The HTTP method we should use when calling the `async_amd_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. # @param [String] byoc The SID of a BYOC (Bring Your Own Carrier) trunk to route this call with. Note that `byoc` is only meaningful when `to` is a phone number; it will otherwise be ignored. (Beta) # @param [String] call_reason The Reason for the outgoing call. Use it to specify the purpose of the call that is presented on the called party's phone. (Branded Calls Beta) # @param [String] call_token A token string needed to invoke a forwarded call. A call_token is generated when an incoming call is received on a Twilio number. Pass an incoming call's call_token value to a forwarded call via the call_token parameter when creating a new call. A forwarded call should bear the same CallerID of the original incoming call. # @param [String] recording_track The audio track to record for the call. Can be: `inbound`, `outbound` or `both`. The default is `both`. `inbound` records the audio that is received by Twilio. `outbound` records the audio that is generated from Twilio. `both` records the audio that is received and generated by Twilio. # @param [String] time_limit The maximum duration of the call in seconds. Constraints depend on account and configuration. # @param [String] url The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls). # @param [String] twiml TwiML instructions for the call Twilio will use without fetching Twiml from url parameter. If both `twiml` and `url` are provided then `twiml` parameter will be ignored. Max 4000 characters. # @param [String] application_sid The SID of the Application resource that will handle the call, if the call will be handled by an application. # @return [CallInstance] Created CallInstance def create( to: nil, from: nil, method: :unset, fallback_url: :unset, fallback_method: :unset, status_callback: :unset, status_callback_event: :unset, status_callback_method: :unset, send_digits: :unset, timeout: :unset, record: :unset, recording_channels: :unset, recording_status_callback: :unset, recording_status_callback_method: :unset, sip_auth_username: :unset, sip_auth_password: :unset, machine_detection: :unset, machine_detection_timeout: :unset, recording_status_callback_event: :unset, trim: :unset, caller_id: :unset, machine_detection_speech_threshold: :unset, machine_detection_speech_end_threshold: :unset, machine_detection_silence_timeout: :unset, async_amd: :unset, async_amd_status_callback: :unset, async_amd_status_callback_method: :unset, byoc: :unset, call_reason: :unset, call_token: :unset, recording_track: :unset, time_limit: :unset, url: :unset, twiml: :unset, application_sid: :unset ) data = Twilio::Values.of({ 'To' => to, 'From' => from, 'Method' => method, 'FallbackUrl' => fallback_url, 'FallbackMethod' => fallback_method, 'StatusCallback' => status_callback, 'StatusCallbackEvent' => Twilio.serialize_list(status_callback_event) { |e| e }, 'StatusCallbackMethod' => status_callback_method, 'SendDigits' => send_digits, 'Timeout' => timeout, 'Record' => record, 'RecordingChannels' => recording_channels, 'RecordingStatusCallback' => recording_status_callback, 'RecordingStatusCallbackMethod' => recording_status_callback_method, 'SipAuthUsername' => sip_auth_username, 'SipAuthPassword' => sip_auth_password, 'MachineDetection' => machine_detection, 'MachineDetectionTimeout' => machine_detection_timeout, 'RecordingStatusCallbackEvent' => Twilio.serialize_list(recording_status_callback_event) { |e| e }, 'Trim' => trim, 'CallerId' => caller_id, 'MachineDetectionSpeechThreshold' => machine_detection_speech_threshold, 'MachineDetectionSpeechEndThreshold' => machine_detection_speech_end_threshold, 'MachineDetectionSilenceTimeout' => machine_detection_silence_timeout, 'AsyncAmd' => async_amd, 'AsyncAmdStatusCallback' => async_amd_status_callback, 'AsyncAmdStatusCallbackMethod' => async_amd_status_callback_method, 'Byoc' => byoc, 'CallReason' => call_reason, 'CallToken' => call_token, 'RecordingTrack' => recording_track, 'TimeLimit' => time_limit, 'Url' => url, 'Twiml' => twiml, 'ApplicationSid' => application_sid, }) headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) payload = @version.create('POST', @uri, data: data, headers: headers) CallInstance.new( @version, payload, account_sid: @solution[:account_sid], ) end ## # Lists CallInstance records from the API as a list. # Unlike stream(), this operation is eager and will load `limit` records into # memory before returning. # @param [String] to Only show calls made to this phone number, SIP address, Client identifier or SIM SID. # @param [String] from Only include calls from this phone number, SIP address, Client identifier or SIM SID. # @param [String] parent_call_sid Only include calls spawned by calls with this SID. # @param [Status] status The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`. # @param [Time] start_time Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_before Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_after Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] end_time Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_before Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_after Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Integer] limit Upper limit for the number of records to return. stream() # guarantees to never return more than limit. Default is no limit # @param [Integer] page_size Number of records to fetch per request, when # not set will use the default value of 50 records. If no page_size is defined # but a limit is defined, stream() will attempt to read the limit with the most # efficient page size, i.e. min(limit, 1000) # @return [Array] Array of up to limit results def list(to: :unset, from: :unset, parent_call_sid: :unset, status: :unset, start_time: :unset, start_time_before: :unset, start_time_after: :unset, end_time: :unset, end_time_before: :unset, end_time_after: :unset, limit: nil, page_size: nil) self.stream( to: to, from: from, parent_call_sid: parent_call_sid, status: status, start_time: start_time, start_time_before: start_time_before, start_time_after: start_time_after, end_time: end_time, end_time_before: end_time_before, end_time_after: end_time_after, limit: limit, page_size: page_size ).entries end ## # Streams Instance records from the API as an Enumerable. # This operation lazily loads records as efficiently as possible until the limit # is reached. # @param [String] to Only show calls made to this phone number, SIP address, Client identifier or SIM SID. # @param [String] from Only include calls from this phone number, SIP address, Client identifier or SIM SID. # @param [String] parent_call_sid Only include calls spawned by calls with this SID. # @param [Status] status The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`. # @param [Time] start_time Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_before Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_after Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] end_time Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_before Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_after Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Integer] limit Upper limit for the number of records to return. stream() # guarantees to never return more than limit. Default is no limit # @param [Integer] page_size Number of records to fetch per request, when # not set will use the default value of 50 records. If no page_size is defined # but a limit is defined, stream() will attempt to read the limit with the most # efficient page size, i.e. min(limit, 1000) # @return [Enumerable] Enumerable that will yield up to limit results def stream(to: :unset, from: :unset, parent_call_sid: :unset, status: :unset, start_time: :unset, start_time_before: :unset, start_time_after: :unset, end_time: :unset, end_time_before: :unset, end_time_after: :unset, limit: nil, page_size: nil) limits = @version.read_limits(limit, page_size) page = self.page( to: to, from: from, parent_call_sid: parent_call_sid, status: status, start_time: start_time, start_time_before: start_time_before, start_time_after: start_time_after, end_time: end_time, end_time_before: end_time_before, end_time_after: end_time_after, page_size: limits[:page_size], ) @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) end ## # When passed a block, yields CallInstance records from the API. # This operation lazily loads records as efficiently as possible until the limit # is reached. def each limits = @version.read_limits page = self.page(page_size: limits[:page_size], ) @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]).each {|x| yield x} end ## # Retrieve a single page of CallInstance records from the API. # Request is executed immediately. # @param [String] to Only show calls made to this phone number, SIP address, Client identifier or SIM SID. # @param [String] from Only include calls from this phone number, SIP address, Client identifier or SIM SID. # @param [String] parent_call_sid Only include calls spawned by calls with this SID. # @param [Status] status The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`. # @param [Time] start_time Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_before Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] start_time_after Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. # @param [Time] end_time Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_before Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [Time] end_time_after Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. # @param [String] page_token PageToken provided by the API # @param [Integer] page_number Page Number, this value is simply for client state # @param [Integer] page_size Number of records to return, defaults to 50 # @return [Page] Page of CallInstance def page(to: :unset, from: :unset, parent_call_sid: :unset, status: :unset, start_time: :unset, start_time_before: :unset, start_time_after: :unset, end_time: :unset, end_time_before: :unset, end_time_after: :unset, page_token: :unset, page_number: :unset, page_size: :unset) params = Twilio::Values.of({ 'To' => to, 'From' => from, 'ParentCallSid' => parent_call_sid, 'Status' => status, 'StartTime' => Twilio.serialize_iso8601_datetime(start_time), 'StartTime<' => Twilio.serialize_iso8601_datetime(start_time_before), 'StartTime>' => Twilio.serialize_iso8601_datetime(start_time_after), 'EndTime' => Twilio.serialize_iso8601_datetime(end_time), 'EndTime<' => Twilio.serialize_iso8601_datetime(end_time_before), 'EndTime>' => Twilio.serialize_iso8601_datetime(end_time_after), 'PageToken' => page_token, 'Page' => page_number, 'PageSize' => page_size, }) response = @version.page('GET', @uri, params: params) CallPage.new(@version, response, @solution) end ## # Retrieve a single page of CallInstance records from the API. # Request is executed immediately. # @param [String] target_url API-generated URL for the requested results page # @return [Page] Page of CallInstance def get_page(target_url) response = @version.domain.request( 'GET', target_url ) CallPage.new(@version, response, @solution) end # Provide a user friendly representation def to_s '#' end end class CallContext < InstanceContext ## # Initialize the CallContext # @param [Version] version Version that contains the resource # @param [String] account_sid The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to update. # @param [String] sid The Twilio-provided string that uniquely identifies the Call resource to update # @return [CallContext] CallContext def initialize(version, account_sid, sid) super(version) # Path Solution @solution = { account_sid: account_sid, sid: sid, } @uri = "/Accounts/#{@solution[:account_sid]}/Calls/#{@solution[:sid]}.json" # Dependents @events = nil @user_defined_messages = nil @siprec = nil @user_defined_message_subscriptions = nil @payments = nil @recordings = nil @notifications = nil @streams = nil end ## # Delete the CallInstance # @return [Boolean] True if delete succeeds, false otherwise def delete headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) @version.delete('DELETE', @uri, headers: headers) end ## # Fetch the CallInstance # @return [CallInstance] Fetched CallInstance def fetch headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) payload = @version.fetch('GET', @uri, headers: headers) CallInstance.new( @version, payload, account_sid: @solution[:account_sid], sid: @solution[:sid], ) end ## # Update the CallInstance # @param [String] url The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls). # @param [String] method The HTTP method we should use when calling the `url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [UpdateStatus] status # @param [String] fallback_url The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] fallback_method The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] status_callback The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted). # @param [String] status_callback_method The HTTP method we should use when requesting the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] twiml TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive # @param [String] time_limit The maximum duration of the call in seconds. Constraints depend on account and configuration. # @return [CallInstance] Updated CallInstance def update( url: :unset, method: :unset, status: :unset, fallback_url: :unset, fallback_method: :unset, status_callback: :unset, status_callback_method: :unset, twiml: :unset, time_limit: :unset ) data = Twilio::Values.of({ 'Url' => url, 'Method' => method, 'Status' => status, 'FallbackUrl' => fallback_url, 'FallbackMethod' => fallback_method, 'StatusCallback' => status_callback, 'StatusCallbackMethod' => status_callback_method, 'Twiml' => twiml, 'TimeLimit' => time_limit, }) headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) payload = @version.update('POST', @uri, data: data, headers: headers) CallInstance.new( @version, payload, account_sid: @solution[:account_sid], sid: @solution[:sid], ) end ## # Access the events # @return [EventList] # @return [EventContext] def events unless @events @events = EventList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @events end ## # Access the user_defined_messages # @return [UserDefinedMessageList] # @return [UserDefinedMessageContext] def user_defined_messages unless @user_defined_messages @user_defined_messages = UserDefinedMessageList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @user_defined_messages end ## # Access the siprec # @return [SiprecList] # @return [SiprecContext] if sid was passed. def siprec(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return SiprecContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @siprec @siprec = SiprecList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @siprec end ## # Access the user_defined_message_subscriptions # @return [UserDefinedMessageSubscriptionList] # @return [UserDefinedMessageSubscriptionContext] if sid was passed. def user_defined_message_subscriptions(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return UserDefinedMessageSubscriptionContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @user_defined_message_subscriptions @user_defined_message_subscriptions = UserDefinedMessageSubscriptionList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @user_defined_message_subscriptions end ## # Access the payments # @return [PaymentList] # @return [PaymentContext] if sid was passed. def payments(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return PaymentContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @payments @payments = PaymentList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @payments end ## # Access the recordings # @return [RecordingList] # @return [RecordingContext] if sid was passed. def recordings(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return RecordingContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @recordings @recordings = RecordingList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @recordings end ## # Access the notifications # @return [NotificationList] # @return [NotificationContext] if sid was passed. def notifications(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return NotificationContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @notifications @notifications = NotificationList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @notifications end ## # Access the streams # @return [StreamList] # @return [StreamContext] if sid was passed. def streams(sid=:unset) raise ArgumentError, 'sid cannot be nil' if sid.nil? if sid != :unset return StreamContext.new(@version, @solution[:account_sid], @solution[:sid],sid ) end unless @streams @streams = StreamList.new( @version, account_sid: @solution[:account_sid], call_sid: @solution[:sid], ) end @streams end ## # Provide a user friendly representation def to_s context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') "#" end ## # Provide a detailed, user friendly representation def inspect context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') "#" end end class CallPage < Page ## # Initialize the CallPage # @param [Version] version Version that contains the resource # @param [Response] response Response from the API # @param [Hash] solution Path solution for the resource # @return [CallPage] CallPage def initialize(version, response, solution) super(version, response) # Path Solution @solution = solution end ## # Build an instance of CallInstance # @param [Hash] payload Payload response from the API # @return [CallInstance] CallInstance def get_instance(payload) CallInstance.new(@version, payload, account_sid: @solution[:account_sid]) end ## # Provide a user friendly representation def to_s '' end end class CallInstance < InstanceResource ## # Initialize the CallInstance # @param [Version] version Version that contains the resource # @param [Hash] payload payload that contains response from Twilio # @param [String] account_sid The SID of the # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Call # resource. # @param [String] sid The SID of the Call resource to fetch. # @return [CallInstance] CallInstance def initialize(version, payload , account_sid: nil, sid: nil) super(version) # Marshaled Properties @properties = { 'sid' => payload['sid'], 'date_created' => Twilio.deserialize_rfc2822(payload['date_created']), 'date_updated' => Twilio.deserialize_rfc2822(payload['date_updated']), 'parent_call_sid' => payload['parent_call_sid'], 'account_sid' => payload['account_sid'], 'to' => payload['to'], 'to_formatted' => payload['to_formatted'], 'from' => payload['from'], 'from_formatted' => payload['from_formatted'], 'phone_number_sid' => payload['phone_number_sid'], 'status' => payload['status'], 'start_time' => Twilio.deserialize_rfc2822(payload['start_time']), 'end_time' => Twilio.deserialize_rfc2822(payload['end_time']), 'duration' => payload['duration'], 'price' => payload['price'], 'price_unit' => payload['price_unit'], 'direction' => payload['direction'], 'answered_by' => payload['answered_by'], 'api_version' => payload['api_version'], 'forwarded_from' => payload['forwarded_from'], 'group_sid' => payload['group_sid'], 'caller_name' => payload['caller_name'], 'queue_time' => payload['queue_time'], 'trunk_sid' => payload['trunk_sid'], 'uri' => payload['uri'], 'subresource_uris' => payload['subresource_uris'], } # Context @instance_context = nil @params = { 'account_sid' => account_sid ,'sid' => sid || @properties['sid'] , } end ## # Generate an instance context for the instance, the context is capable of # performing various actions. All instance actions are proxied to the context # @return [CallContext] CallContext for this CallInstance def context unless @instance_context @instance_context = CallContext.new(@version , @params['account_sid'], @params['sid']) end @instance_context end ## # @return [String] The unique string that we created to identify this Call resource. def sid @properties['sid'] end ## # @return [Time] The date and time in UTC that this resource was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. def date_created @properties['date_created'] end ## # @return [Time] The date and time in UTC that this resource was last updated, specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. def date_updated @properties['date_updated'] end ## # @return [String] The SID that identifies the call that created this leg. def parent_call_sid @properties['parent_call_sid'] end ## # @return [String] The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created this Call resource. def account_sid @properties['account_sid'] end ## # @return [String] The phone number, SIP address, Client identifier or SIM SID that received this call. Phone numbers are in [E.164](https://www.twilio.com/docs/glossary/what-e164) format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. Client identifiers are formatted `client:name`. SIM SIDs are formatted as `sim:sid`. def to @properties['to'] end ## # @return [String] The phone number, SIP address or Client identifier that received this call. Formatted for display. Non-North American phone numbers are in [E.164](https://www.twilio.com/docs/glossary/what-e164) format (e.g., +442071838750). def to_formatted @properties['to_formatted'] end ## # @return [String] The phone number, SIP address, Client identifier or SIM SID that made this call. Phone numbers are in [E.164](https://www.twilio.com/docs/glossary/what-e164) format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. Client identifiers are formatted `client:name`. SIM SIDs are formatted as `sim:sid`. def from @properties['from'] end ## # @return [String] The calling phone number, SIP address, or Client identifier formatted for display. Non-North American phone numbers are in [E.164](https://www.twilio.com/docs/glossary/what-e164) format (e.g., +442071838750). def from_formatted @properties['from_formatted'] end ## # @return [String] If the call was inbound, this is the SID of the IncomingPhoneNumber resource that received the call. If the call was outbound, it is the SID of the OutgoingCallerId resource from which the call was placed. def phone_number_sid @properties['phone_number_sid'] end ## # @return [Status] def status @properties['status'] end ## # @return [Time] The start time of the call, given as UTC in [RFC 2822](https://www.php.net/manual/en/class.datetime.php#datetime.constants.rfc2822) format. Empty if the call has not yet been dialed. def start_time @properties['start_time'] end ## # @return [Time] The time the call ended, given as UTC in [RFC 2822](https://www.php.net/manual/en/class.datetime.php#datetime.constants.rfc2822) format. Empty if the call did not complete successfully. def end_time @properties['end_time'] end ## # @return [String] The length of the call in seconds. This value is empty for busy, failed, unanswered, or ongoing calls. def duration @properties['duration'] end ## # @return [String] The charge for this call, in the currency associated with the account. Populated after the call is completed. May not be immediately available. The price associated with a call only reflects the charge for connectivity. Charges for other call-related features such as Answering Machine Detection, Text-To-Speech, and SIP REFER are not included in this value. def price @properties['price'] end ## # @return [String] The currency in which `Price` is measured, in [ISO 4127](https://www.iso.org/iso/home/standards/currency_codes.htm) format (e.g., `USD`, `EUR`, `JPY`). Always capitalized for calls. def price_unit @properties['price_unit'] end ## # @return [String] A string describing the direction of the call. Can be: `inbound` for inbound calls, `outbound-api` for calls initiated via the REST API or `outbound-dial` for calls initiated by a `` verb. Using [Elastic SIP Trunking](https://www.twilio.com/docs/sip-trunking), the values can be [`trunking-terminating`](https://www.twilio.com/docs/sip-trunking#termination) for outgoing calls from your communications infrastructure to the PSTN or [`trunking-originating`](https://www.twilio.com/docs/sip-trunking#origination) for incoming calls to your communications infrastructure from the PSTN. def direction @properties['direction'] end ## # @return [String] Either `human` or `machine` if this call was initiated with answering machine detection. Empty otherwise. def answered_by @properties['answered_by'] end ## # @return [String] The API version used to create the call. def api_version @properties['api_version'] end ## # @return [String] The forwarding phone number if this call was an incoming call forwarded from another number (depends on carrier supporting forwarding). Otherwise, empty. def forwarded_from @properties['forwarded_from'] end ## # @return [String] The Group SID associated with this call. If no Group is associated with the call, the field is empty. def group_sid @properties['group_sid'] end ## # @return [String] The caller's name if this call was an incoming call to a phone number with caller ID Lookup enabled. Otherwise, empty. def caller_name @properties['caller_name'] end ## # @return [String] The wait time in milliseconds before the call is placed. def queue_time @properties['queue_time'] end ## # @return [String] The unique identifier of the trunk resource that was used for this call. The field is empty if the call was not made using a SIP trunk or if the call is not terminated. def trunk_sid @properties['trunk_sid'] end ## # @return [String] The URI of this resource, relative to `https://api.twilio.com`. def uri @properties['uri'] end ## # @return [Hash] A list of subresources available to this call, identified by their URIs relative to `https://api.twilio.com`. def subresource_uris @properties['subresource_uris'] end ## # Delete the CallInstance # @return [Boolean] True if delete succeeds, false otherwise def delete context.delete end ## # Fetch the CallInstance # @return [CallInstance] Fetched CallInstance def fetch context.fetch end ## # Update the CallInstance # @param [String] url The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls). # @param [String] method The HTTP method we should use when calling the `url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [UpdateStatus] status # @param [String] fallback_url The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] fallback_method The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] status_callback The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted). # @param [String] status_callback_method The HTTP method we should use when requesting the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. # @param [String] twiml TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive # @param [String] time_limit The maximum duration of the call in seconds. Constraints depend on account and configuration. # @return [CallInstance] Updated CallInstance def update( url: :unset, method: :unset, status: :unset, fallback_url: :unset, fallback_method: :unset, status_callback: :unset, status_callback_method: :unset, twiml: :unset, time_limit: :unset ) context.update( url: url, method: method, status: status, fallback_url: fallback_url, fallback_method: fallback_method, status_callback: status_callback, status_callback_method: status_callback_method, twiml: twiml, time_limit: time_limit, ) end ## # Access the events # @return [events] events def events context.events end ## # Access the user_defined_messages # @return [user_defined_messages] user_defined_messages def user_defined_messages context.user_defined_messages end ## # Access the siprec # @return [siprec] siprec def siprec context.siprec end ## # Access the user_defined_message_subscriptions # @return [user_defined_message_subscriptions] user_defined_message_subscriptions def user_defined_message_subscriptions context.user_defined_message_subscriptions end ## # Access the payments # @return [payments] payments def payments context.payments end ## # Access the recordings # @return [recordings] recordings def recordings context.recordings end ## # Access the notifications # @return [notifications] notifications def notifications context.notifications end ## # Access the streams # @return [streams] streams def streams context.streams end ## # Provide a user friendly representation def to_s values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") "" end ## # Provide a detailed, user friendly representation def inspect values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") "" end end end end end end end