## # This code was generated by # \ / _ _ _| _ _ # | (_)\/(_)(_|\/| |(/_ v1.0.0 # / / # # frozen_string_literal: true module Twilio module REST class Voice < Domain class V1 < Version class ByocTrunkList < ListResource ## # Initialize the ByocTrunkList # @param [Version] version Version that contains the resource # @return [ByocTrunkList] ByocTrunkList def initialize(version) super(version) # Path Solution @solution = {} @uri = "/ByocTrunks" end ## # Retrieve a single page of ByocTrunkInstance records from the API. # Request is executed immediately. # @param [String] friendly_name A descriptive string that you create to describe # the resource. It is not unique and can be up to 255 characters long. # @param [String] voice_url The URL we should call when the BYOC Trunk receives a # call. # @param [String] voice_method The HTTP method we should use to call `voice_url`. # Can be: `GET` or `POST`. # @param [String] voice_fallback_url The URL that we should call when an error # occurs while retrieving or executing the TwiML from `voice_url`. # @param [String] voice_fallback_method The HTTP method we should use to call # `voice_fallback_url`. Can be: `GET` or `POST`. # @param [String] status_callback_url The URL that we should call to pass status # parameters (such as call ended) to your application. # @param [String] status_callback_method The HTTP method we should use to call # `status_callback_url`. Can be: `GET` or `POST`. # @param [Boolean] cnam_lookup_enabled Whether Caller ID Name (CNAM) lookup is # enabled for the trunk. If enabled, all inbound calls to the BYOC Trunk from the # United States and Canada automatically perform a CNAM Lookup and display Caller # ID data on your phone. See [CNAM # Lookups](https://www.twilio.com/docs/sip-trunking#CNAM) for more information. # @param [String] connection_policy_sid The SID of the Connection Policy that # Twilio will use when routing traffic to your communications infrastructure. # @param [String] from_domain_sid The SID of the SIP Domain that should be used in # the `From` header of originating calls sent to your SIP infrastructure. If your # SIP infrastructure allows users to "call back" an incoming call, configure this # with a [SIP Domain](https://www.twilio.com/docs/voice/api/sending-sip) to ensure # proper routing. If not configured, the from domain will default to # "sip.twilio.com". # @return [ByocTrunkInstance] Newly created ByocTrunkInstance def create(friendly_name: :unset, voice_url: :unset, voice_method: :unset, voice_fallback_url: :unset, voice_fallback_method: :unset, status_callback_url: :unset, status_callback_method: :unset, cnam_lookup_enabled: :unset, connection_policy_sid: :unset, from_domain_sid: :unset) data = Twilio::Values.of({ 'FriendlyName' => friendly_name, 'VoiceUrl' => voice_url, 'VoiceMethod' => voice_method, 'VoiceFallbackUrl' => voice_fallback_url, 'VoiceFallbackMethod' => voice_fallback_method, 'StatusCallbackUrl' => status_callback_url, 'StatusCallbackMethod' => status_callback_method, 'CnamLookupEnabled' => cnam_lookup_enabled, 'ConnectionPolicySid' => connection_policy_sid, 'FromDomainSid' => from_domain_sid, }) payload = @version.create( 'POST', @uri, data: data ) ByocTrunkInstance.new(@version, payload, ) end ## # Lists ByocTrunkInstance records from the API as a list. # Unlike stream(), this operation is eager and will load `limit` records into # memory before returning. # @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(limit: nil, page_size: nil) self.stream(limit: limit, page_size: page_size).entries end ## # Streams ByocTrunkInstance records from the API as an Enumerable. # This operation lazily loads records as efficiently as possible until the limit # is reached. # @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(limit: nil, page_size: nil) limits = @version.read_limits(limit, page_size) page = self.page(page_size: limits[:page_size], ) @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) end ## # When passed a block, yields ByocTrunkInstance 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 ByocTrunkInstance records from the API. # Request is executed immediately. # @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 ByocTrunkInstance def page(page_token: :unset, page_number: :unset, page_size: :unset) params = Twilio::Values.of({ 'PageToken' => page_token, 'Page' => page_number, 'PageSize' => page_size, }) response = @version.page( 'GET', @uri, params ) ByocTrunkPage.new(@version, response, @solution) end ## # Retrieve a single page of ByocTrunkInstance records from the API. # Request is executed immediately. # @param [String] target_url API-generated URL for the requested results page # @return [Page] Page of ByocTrunkInstance def get_page(target_url) response = @version.domain.request( 'GET', target_url ) ByocTrunkPage.new(@version, response, @solution) end ## # Provide a user friendly representation def to_s '#' end end class ByocTrunkPage < Page ## # Initialize the ByocTrunkPage # @param [Version] version Version that contains the resource # @param [Response] response Response from the API # @param [Hash] solution Path solution for the resource # @return [ByocTrunkPage] ByocTrunkPage def initialize(version, response, solution) super(version, response) # Path Solution @solution = solution end ## # Build an instance of ByocTrunkInstance # @param [Hash] payload Payload response from the API # @return [ByocTrunkInstance] ByocTrunkInstance def get_instance(payload) ByocTrunkInstance.new(@version, payload, ) end ## # Provide a user friendly representation def to_s '' end end class ByocTrunkContext < InstanceContext ## # Initialize the ByocTrunkContext # @param [Version] version Version that contains the resource # @param [String] sid The Twilio-provided string that uniquely identifies the BYOC # Trunk resource to fetch. # @return [ByocTrunkContext] ByocTrunkContext def initialize(version, sid) super(version) # Path Solution @solution = {sid: sid, } @uri = "/ByocTrunks/#{@solution[:sid]}" end ## # Fetch a ByocTrunkInstance # @return [ByocTrunkInstance] Fetched ByocTrunkInstance def fetch params = Twilio::Values.of({}) payload = @version.fetch( 'GET', @uri, params, ) ByocTrunkInstance.new(@version, payload, sid: @solution[:sid], ) end ## # Update the ByocTrunkInstance # @param [String] friendly_name A descriptive string that you create to describe # the resource. It is not unique and can be up to 255 characters long. # @param [String] voice_url The URL we should call when the BYOC Trunk receives a # call. # @param [String] voice_method The HTTP method we should use to call `voice_url` # @param [String] voice_fallback_url The URL that we should call when an error # occurs while retrieving or executing the TwiML requested by `voice_url`. # @param [String] voice_fallback_method The HTTP method we should use to call # `voice_fallback_url`. Can be: `GET` or `POST`. # @param [String] status_callback_url The URL that we should call to pass status # parameters (such as call ended) to your application. # @param [String] status_callback_method The HTTP method we should use to call # `status_callback_url`. Can be: `GET` or `POST`. # @param [Boolean] cnam_lookup_enabled Whether Caller ID Name (CNAM) lookup is # enabled for the trunk. If enabled, all inbound calls to the BYOC Trunk from the # United States and Canada automatically perform a CNAM Lookup and display Caller # ID data on your phone. See [CNAM # Lookups](https://www.twilio.com/docs/sip-trunking#CNAM) for more information. # @param [String] connection_policy_sid The SID of the Connection Policy that # Twilio will use when routing traffic to your communications infrastructure. # @param [String] from_domain_sid The SID of the SIP Domain that should be used in # the `From` header of originating calls sent to your SIP infrastructure. If your # SIP infrastructure allows users to "call back" an incoming call, configure this # with a [SIP Domain](https://www.twilio.com/docs/voice/api/sending-sip) to ensure # proper routing. If not configured, the from domain will default to # "sip.twilio.com". # @return [ByocTrunkInstance] Updated ByocTrunkInstance def update(friendly_name: :unset, voice_url: :unset, voice_method: :unset, voice_fallback_url: :unset, voice_fallback_method: :unset, status_callback_url: :unset, status_callback_method: :unset, cnam_lookup_enabled: :unset, connection_policy_sid: :unset, from_domain_sid: :unset) data = Twilio::Values.of({ 'FriendlyName' => friendly_name, 'VoiceUrl' => voice_url, 'VoiceMethod' => voice_method, 'VoiceFallbackUrl' => voice_fallback_url, 'VoiceFallbackMethod' => voice_fallback_method, 'StatusCallbackUrl' => status_callback_url, 'StatusCallbackMethod' => status_callback_method, 'CnamLookupEnabled' => cnam_lookup_enabled, 'ConnectionPolicySid' => connection_policy_sid, 'FromDomainSid' => from_domain_sid, }) payload = @version.update( 'POST', @uri, data: data, ) ByocTrunkInstance.new(@version, payload, sid: @solution[:sid], ) end ## # Deletes the ByocTrunkInstance # @return [Boolean] true if delete succeeds, false otherwise def delete @version.delete('delete', @uri) 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 ByocTrunkInstance < InstanceResource ## # Initialize the ByocTrunkInstance # @param [Version] version Version that contains the resource # @param [Hash] payload payload that contains response from Twilio # @param [String] sid The Twilio-provided string that uniquely identifies the BYOC # Trunk resource to fetch. # @return [ByocTrunkInstance] ByocTrunkInstance def initialize(version, payload, sid: nil) super(version) # Marshaled Properties @properties = { 'account_sid' => payload['account_sid'], 'sid' => payload['sid'], 'friendly_name' => payload['friendly_name'], 'voice_url' => payload['voice_url'], 'voice_method' => payload['voice_method'], 'voice_fallback_url' => payload['voice_fallback_url'], 'voice_fallback_method' => payload['voice_fallback_method'], 'status_callback_url' => payload['status_callback_url'], 'status_callback_method' => payload['status_callback_method'], 'cnam_lookup_enabled' => payload['cnam_lookup_enabled'], 'connection_policy_sid' => payload['connection_policy_sid'], 'from_domain_sid' => payload['from_domain_sid'], 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']), 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']), 'url' => payload['url'], } # Context @instance_context = nil @params = {'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 [ByocTrunkContext] ByocTrunkContext for this ByocTrunkInstance def context unless @instance_context @instance_context = ByocTrunkContext.new(@version, @params['sid'], ) end @instance_context end ## # @return [String] The SID of the Account that created the resource def account_sid @properties['account_sid'] end ## # @return [String] The unique string that identifies the resource def sid @properties['sid'] end ## # @return [String] The string that you assigned to describe the resource def friendly_name @properties['friendly_name'] end ## # @return [String] The URL we call when receiving a call def voice_url @properties['voice_url'] end ## # @return [String] The HTTP method to use with voice_url def voice_method @properties['voice_method'] end ## # @return [String] The URL we call when an error occurs while executing TwiML def voice_fallback_url @properties['voice_fallback_url'] end ## # @return [String] The HTTP method used with voice_fallback_url def voice_fallback_method @properties['voice_fallback_method'] end ## # @return [String] The URL that we call with status updates def status_callback_url @properties['status_callback_url'] end ## # @return [String] The HTTP method we use to call status_callback_url def status_callback_method @properties['status_callback_method'] end ## # @return [Boolean] Whether Caller ID Name (CNAM) lookup is enabled for the trunk def cnam_lookup_enabled @properties['cnam_lookup_enabled'] end ## # @return [String] Origination Connection Policy (to your Carrier) def connection_policy_sid @properties['connection_policy_sid'] end ## # @return [String] The SID of the SIP Domain that should be used in the `From` header of originating calls def from_domain_sid @properties['from_domain_sid'] end ## # @return [Time] The RFC 2822 date and time in GMT that the resource was created def date_created @properties['date_created'] end ## # @return [Time] The RFC 2822 date and time in GMT that the resource was last updated def date_updated @properties['date_updated'] end ## # @return [String] The absolute URL of the resource def url @properties['url'] end ## # Fetch a ByocTrunkInstance # @return [ByocTrunkInstance] Fetched ByocTrunkInstance def fetch context.fetch end ## # Update the ByocTrunkInstance # @param [String] friendly_name A descriptive string that you create to describe # the resource. It is not unique and can be up to 255 characters long. # @param [String] voice_url The URL we should call when the BYOC Trunk receives a # call. # @param [String] voice_method The HTTP method we should use to call `voice_url` # @param [String] voice_fallback_url The URL that we should call when an error # occurs while retrieving or executing the TwiML requested by `voice_url`. # @param [String] voice_fallback_method The HTTP method we should use to call # `voice_fallback_url`. Can be: `GET` or `POST`. # @param [String] status_callback_url The URL that we should call to pass status # parameters (such as call ended) to your application. # @param [String] status_callback_method The HTTP method we should use to call # `status_callback_url`. Can be: `GET` or `POST`. # @param [Boolean] cnam_lookup_enabled Whether Caller ID Name (CNAM) lookup is # enabled for the trunk. If enabled, all inbound calls to the BYOC Trunk from the # United States and Canada automatically perform a CNAM Lookup and display Caller # ID data on your phone. See [CNAM # Lookups](https://www.twilio.com/docs/sip-trunking#CNAM) for more information. # @param [String] connection_policy_sid The SID of the Connection Policy that # Twilio will use when routing traffic to your communications infrastructure. # @param [String] from_domain_sid The SID of the SIP Domain that should be used in # the `From` header of originating calls sent to your SIP infrastructure. If your # SIP infrastructure allows users to "call back" an incoming call, configure this # with a [SIP Domain](https://www.twilio.com/docs/voice/api/sending-sip) to ensure # proper routing. If not configured, the from domain will default to # "sip.twilio.com". # @return [ByocTrunkInstance] Updated ByocTrunkInstance def update(friendly_name: :unset, voice_url: :unset, voice_method: :unset, voice_fallback_url: :unset, voice_fallback_method: :unset, status_callback_url: :unset, status_callback_method: :unset, cnam_lookup_enabled: :unset, connection_policy_sid: :unset, from_domain_sid: :unset) context.update( friendly_name: friendly_name, voice_url: voice_url, voice_method: voice_method, voice_fallback_url: voice_fallback_url, voice_fallback_method: voice_fallback_method, status_callback_url: status_callback_url, status_callback_method: status_callback_method, cnam_lookup_enabled: cnam_lookup_enabled, connection_policy_sid: connection_policy_sid, from_domain_sid: from_domain_sid, ) end ## # Deletes the ByocTrunkInstance # @return [Boolean] true if delete succeeds, false otherwise def delete context.delete 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