diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 425d0417..cfa2e14e 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -388,8 +388,13 @@ lib/bandwidth-sdk/models/recording_transcription_metadata.rb lib/bandwidth-sdk/models/recording_transcriptions.rb lib/bandwidth-sdk/models/redirect_callback.rb lib/bandwidth-sdk/models/redirect_method_enum.rb +lib/bandwidth-sdk/models/refer.rb +lib/bandwidth-sdk/models/refer_call_status_enum.rb +lib/bandwidth-sdk/models/refer_complete_callback.rb +lib/bandwidth-sdk/models/refer_complete_method_enum.rb lib/bandwidth-sdk/models/sip_connection_metadata.rb lib/bandwidth-sdk/models/sip_credentials.rb +lib/bandwidth-sdk/models/sip_uri.rb lib/bandwidth-sdk/models/sms_message_content.rb lib/bandwidth-sdk/models/standalone_card_orientation_enum.rb lib/bandwidth-sdk/models/status_callback.rb @@ -431,3 +436,8 @@ lib/bandwidth-sdk/models/webhook_subscription_request_schema.rb lib/bandwidth-sdk/models/webhook_subscription_type_enum.rb lib/bandwidth-sdk/models/webhook_subscriptions_list_body.rb lib/bandwidth-sdk/version.rb +spec/unit/models/refer_call_status_enum_spec.rb +spec/unit/models/refer_complete_callback_spec.rb +spec/unit/models/refer_complete_method_enum_spec.rb +spec/unit/models/refer_spec.rb +spec/unit/models/sip_uri_spec.rb \ No newline at end of file diff --git a/bandwidth.yml b/bandwidth.yml index a380e26d..f86cb450 100644 --- a/bandwidth.yml +++ b/bandwidth.yml @@ -3215,6 +3215,21 @@ components: Setting the conference state to `completed` ends the conference and ejects all members. example: completed + referCallStatusEnum: + type: string + enum: + - success + - failure + description: The status of the SIP REFER request. + example: success + referCompleteMethodEnum: + type: string + description: HTTP method used for referCompleteUrl callback. + default: POST + enum: + - GET + - POST + example: POST machineDetectionModeEnum: type: string default: async @@ -5053,6 +5068,83 @@ components: $ref: '#/components/schemas/transferCallerId' transferTo: $ref: '#/components/schemas/transferTo' + sipUri: + type: object + description: SIP URI destination for Refer-To header. + properties: + sipUri: + type: string + description: SIP URI destination (e.g. sip:alice@atlanta.example.com). + example: sip:alice@atlanta.example.com + required: + - sipUri + refer: + type: object + description: Send a SIP REFER for an inbound SIP URI call. + properties: + referCompleteUrl: + type: string + description: Optional callback URL for referComplete event. Relative URL allowed. + referCompleteMethod: + $ref: '#/components/schemas/referCompleteMethodEnum' + tag: + type: string + description: Optional tag echoed in future callbacks. Max length 256. + maxLength: 256 + sipUri: + $ref: '#/components/schemas/sipUri' + required: + - sipUri + referCompleteCallback: + type: object + description: >- + This event is sent to the referCompleteUrl of the verb when the + SIP REFER request has been resolved — either the remote endpoint has + accepted and redirected the call (success) or the REFER was rejected or + timed out (failure). On success the original call is terminated. + properties: + eventType: + $ref: '#/components/schemas/eventType' + eventTime: + $ref: '#/components/schemas/eventTime' + accountId: + $ref: '#/components/schemas/accountId' + applicationId: + $ref: '#/components/schemas/applicationId1' + from: + $ref: '#/components/schemas/from' + to: + $ref: '#/components/schemas/to' + direction: + $ref: '#/components/schemas/callDirectionEnum' + callId: + $ref: '#/components/schemas/callId' + callUrl: + $ref: '#/components/schemas/callUrl' + startTime: + $ref: '#/components/schemas/startTime' + answerTime: + $ref: '#/components/schemas/answerTime' + tag: + $ref: '#/components/schemas/tag1' + referCallStatus: + $ref: '#/components/schemas/referCallStatusEnum' + referSipResponseCode: + type: integer + description: >- + The SIP response code received in response to the REFER request. + Present when the status of the REFER is known (e.g. 202 Accepted or + 405 Method Not Allowed). Absent when the REFER was not attempted. + example: 202 + nullable: true + notifySipResponseCode: + type: integer + description: >- + The SIP response code received in a NOTIFY from the remote endpoint + after it attempted to reach the transfer target. Present only if a + NOTIFY was received before the 30-second timeout. + example: 200 + nullable: true transcriptionAvailableCallback: type: object description: >- diff --git a/lib/bandwidth-sdk.rb b/lib/bandwidth-sdk.rb index a15c309c..6380a047 100644 --- a/lib/bandwidth-sdk.rb +++ b/lib/bandwidth-sdk.rb @@ -174,8 +174,13 @@ require 'bandwidth-sdk/models/recording_transcriptions' require 'bandwidth-sdk/models/redirect_callback' require 'bandwidth-sdk/models/redirect_method_enum' +require 'bandwidth-sdk/models/refer' +require 'bandwidth-sdk/models/refer_call_status_enum' +require 'bandwidth-sdk/models/refer_complete_callback' +require 'bandwidth-sdk/models/refer_complete_method_enum' require 'bandwidth-sdk/models/sip_connection_metadata' require 'bandwidth-sdk/models/sip_credentials' +require 'bandwidth-sdk/models/sip_uri' require 'bandwidth-sdk/models/sms_message_content' require 'bandwidth-sdk/models/standalone_card_orientation_enum' require 'bandwidth-sdk/models/status_callback' @@ -235,6 +240,7 @@ require 'bandwidth-sdk/models/bxml/verbs/play_audio' require 'bandwidth-sdk/models/bxml/verbs/record' require 'bandwidth-sdk/models/bxml/verbs/redirect' +require 'bandwidth-sdk/models/bxml/verbs/refer' require 'bandwidth-sdk/models/bxml/verbs/resume_recording' require 'bandwidth-sdk/models/bxml/verbs/ring' require 'bandwidth-sdk/models/bxml/verbs/send_dtmf' diff --git a/lib/bandwidth-sdk/models/bxml/verbs/refer.rb b/lib/bandwidth-sdk/models/bxml/verbs/refer.rb new file mode 100644 index 00000000..776b0652 --- /dev/null +++ b/lib/bandwidth-sdk/models/bxml/verbs/refer.rb @@ -0,0 +1,14 @@ +module Bandwidth + module Bxml + class Refer < Bandwidth::Bxml::NestableVerb + def initialize(sip_uri, attributes = {}) + super('Refer', nil, [sip_uri], attributes) + @attribute_map = { + refer_complete_url: 'referCompleteUrl', + refer_complete_method: 'referCompleteMethod', + tag: 'tag' + } + end + end + end +end \ No newline at end of file diff --git a/lib/bandwidth-sdk/models/refer.rb b/lib/bandwidth-sdk/models/refer.rb new file mode 100644 index 00000000..9fd16710 --- /dev/null +++ b/lib/bandwidth-sdk/models/refer.rb @@ -0,0 +1,101 @@ +=begin +#Bandwidth +#Bandwidth's Communication APIs +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 +=end + +require 'date' +require 'time' + +module Bandwidth + #BXML verb model. Sends a SIP REFER for an inbound SIP URI call + class Refer < ApiModelBase + attr_accessor :refer_complete_url + attr_accessor :refer_complete_method + attr_accessor :tag + attr_accessor :sip_uri + + def self.attribute_map + { + :'refer_complete_url' => :'referCompleteUrl', + :'refer_complete_method' => :'referCompleteMethod', + :'tag' => :'tag', + :'sip_uri' => :'sipUri' + } + end + + def self.acceptable_attribute_map + attribute_map + end + + def self.acceptable_attributes + acceptable_attribute_map.values + end + + def self.openapi_types + { + :'refer_complete_url' => :'String', + :'refer_complete_method' => :'ReferCompleteMethodEnum', + :'tag' => :'String', + :'sip_uri' => :'SipUri' + } + end + + def self.openapi_nullable + Set.new([:'refer_complete_url', :'refer_complete_method', :'tag']) + end + + def initialize(attributes = {}) + raise ArgumentError, "attributes must be a Hash" unless attributes.is_a?(Hash) + + acceptable_attribute_map = self.class.acceptable_attribute_map + attributes = attributes.each_with_object({}) do |(k, v), h| + raise ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::Refer`." unless acceptable_attribute_map.key?(k.to_sym) + h[k.to_sym] = v + end + + self.refer_complete_url = attributes[:'refer_complete_url'] if attributes.key?(:'refer_complete_url') + self.refer_complete_method = attributes[:'refer_complete_method'] if attributes.key?(:'refer_complete_method') + self.tag = attributes[:'tag'] if attributes.key?(:'tag') + self.sip_uri = attributes[:'sip_uri'] if attributes.key?(:'sip_uri') + + # required nested destination + raise ArgumentError, "`sip_uri` is required for Bandwidth::Refer" if self.sip_uri.nil? + # optional validation + if !self.refer_complete_method.nil? + ReferCompleteMethodEnum.build_from_hash(self.refer_complete_method) + end + if !self.tag.nil? && self.tag.length > 256 + raise ArgumentError, "`tag` max length is 256" + end + end + + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && !attributes[attribute_map[key]].nil? + transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next unless is_nullable && instance_variable_defined?(:"@#{attr}") + end + hash[param] = _to_hash(value) + end + hash + end + end +end \ No newline at end of file diff --git a/lib/bandwidth-sdk/models/refer_call_status_enum.rb b/lib/bandwidth-sdk/models/refer_call_status_enum.rb new file mode 100644 index 00000000..3eea58b4 --- /dev/null +++ b/lib/bandwidth-sdk/models/refer_call_status_enum.rb @@ -0,0 +1,37 @@ +=begin +#Bandwidth +#Bandwidth's Communication APIs +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 +=end + +require 'date' +require 'time' + +module Bandwidth + class ReferCallStatusEnum + SUCCESS = "success".freeze + FAILURE = "failure".freeze + + def self.all_vars + @all_vars ||= [SUCCESS, FAILURE].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if ReferCallStatusEnum.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #ReferCallStatusEnum" + end + end +end \ No newline at end of file diff --git a/lib/bandwidth-sdk/models/refer_complete_callback.rb b/lib/bandwidth-sdk/models/refer_complete_callback.rb new file mode 100644 index 00000000..fda3658a --- /dev/null +++ b/lib/bandwidth-sdk/models/refer_complete_callback.rb @@ -0,0 +1,310 @@ +=begin +#Bandwidth +#Bandwidth's Communication APIs +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 +=end + +require 'date' +require 'time' + +module Bandwidth + # This event is sent to the referCompleteUrl of the verb when the SIP REFER request has been resolved — either the remote endpoint has accepted and redirected the call (success) or the REFER was rejected or timed out (failure). On success the original call is terminated. + class ReferCompleteCallback < ApiModelBase + # The event type for this webhook. For this callback, the value is `referComplete`. + attr_accessor :event_type + + # The approximate UTC date and time when the event was generated by the Bandwidth server, in ISO 8601 format. This may not be exactly the time of event execution. + attr_accessor :event_time + + # The user account associated with the call. + attr_accessor :account_id + + # The id of the application associated with the call. + attr_accessor :application_id + + # The provided identifier of the caller. Must be a phone number in E.164 format (e.g. +15555555555). + attr_accessor :from + + # The phone number that received the call, in E.164 format (e.g. +15555555555). + attr_accessor :to + + attr_accessor :direction + + # The call id associated with the event. + attr_accessor :call_id + + # The URL of the call associated with the event. + attr_accessor :call_url + + # Time the call was started, in ISO 8601 format. + attr_accessor :start_time + + # Time the call was answered, in ISO 8601 format. + attr_accessor :answer_time + + # (optional) The tag specified on call creation. If no tag was specified or it was previously cleared, this field will not be present. + attr_accessor :tag + + attr_accessor :refer_call_status + + # The SIP response code received in response to the REFER request. Present when the status of the REFER is known (e.g. 202 Accepted or 405 Method Not Allowed). Absent when the REFER was not attempted. + attr_accessor :refer_sip_response_code + + # The SIP response code received in a NOTIFY from the remote endpoint after it attempted to reach the transfer target. Present only if a NOTIFY was received before the 30-second timeout. + attr_accessor :notify_sip_response_code + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'event_type' => :'eventType', + :'event_time' => :'eventTime', + :'account_id' => :'accountId', + :'application_id' => :'applicationId', + :'from' => :'from', + :'to' => :'to', + :'direction' => :'direction', + :'call_id' => :'callId', + :'call_url' => :'callUrl', + :'start_time' => :'startTime', + :'answer_time' => :'answerTime', + :'tag' => :'tag', + :'refer_call_status' => :'referCallStatus', + :'refer_sip_response_code' => :'referSipResponseCode', + :'notify_sip_response_code' => :'notifySipResponseCode' + } + end + + # Returns attribute mapping this model knows about + def self.acceptable_attribute_map + attribute_map + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + acceptable_attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'event_type' => :'String', + :'event_time' => :'Time', + :'account_id' => :'String', + :'application_id' => :'String', + :'from' => :'String', + :'to' => :'String', + :'direction' => :'CallDirectionEnum', + :'call_id' => :'String', + :'call_url' => :'String', + :'start_time' => :'Time', + :'answer_time' => :'Time', + :'tag' => :'String', + :'refer_call_status' => :'ReferCallStatusEnum', + :'refer_sip_response_code' => :'Integer', + :'notify_sip_response_code' => :'Integer' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'answer_time', + :'tag', + :'refer_sip_response_code', + :'notify_sip_response_code' + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Bandwidth::ReferCompleteCallback` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + acceptable_attribute_map = self.class.acceptable_attribute_map + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!acceptable_attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::ReferCompleteCallback`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'event_type') + self.event_type = attributes[:'event_type'] + end + + if attributes.key?(:'event_time') + self.event_time = attributes[:'event_time'] + end + + if attributes.key?(:'account_id') + self.account_id = attributes[:'account_id'] + end + + if attributes.key?(:'application_id') + self.application_id = attributes[:'application_id'] + end + + if attributes.key?(:'from') + self.from = attributes[:'from'] + end + + if attributes.key?(:'to') + self.to = attributes[:'to'] + end + + if attributes.key?(:'direction') + self.direction = attributes[:'direction'] + end + + if attributes.key?(:'call_id') + self.call_id = attributes[:'call_id'] + end + + if attributes.key?(:'call_url') + self.call_url = attributes[:'call_url'] + end + + if attributes.key?(:'start_time') + self.start_time = attributes[:'start_time'] + end + + if attributes.key?(:'answer_time') + self.answer_time = attributes[:'answer_time'] + end + + if attributes.key?(:'tag') + self.tag = attributes[:'tag'] + end + + if attributes.key?(:'refer_call_status') + self.refer_call_status = attributes[:'refer_call_status'] + end + + if attributes.key?(:'refer_sip_response_code') + self.refer_sip_response_code = attributes[:'refer_sip_response_code'] + end + + if attributes.key?(:'notify_sip_response_code') + self.notify_sip_response_code = attributes[:'notify_sip_response_code'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + event_type == o.event_type && + event_time == o.event_time && + account_id == o.account_id && + application_id == o.application_id && + from == o.from && + to == o.to && + direction == o.direction && + call_id == o.call_id && + call_url == o.call_url && + start_time == o.start_time && + answer_time == o.answer_time && + tag == o.tag && + refer_call_status == o.refer_call_status && + refer_sip_response_code == o.refer_sip_response_code && + notify_sip_response_code == o.notify_sip_response_code + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [event_type, event_time, account_id, application_id, from, to, direction, call_id, call_url, start_time, answer_time, tag, refer_call_status, refer_sip_response_code, notify_sip_response_code].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + end + +end \ No newline at end of file diff --git a/lib/bandwidth-sdk/models/refer_complete_method_enum.rb b/lib/bandwidth-sdk/models/refer_complete_method_enum.rb new file mode 100644 index 00000000..77ee209f --- /dev/null +++ b/lib/bandwidth-sdk/models/refer_complete_method_enum.rb @@ -0,0 +1,32 @@ +=begin +#Bandwidth +#Bandwidth's Communication APIs +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 +=end + +require 'date' +require 'time' + +module Bandwidth + # HTTP method enum for referCompleteUrl callback requests. + class ReferCompleteMethodEnum + GET = "GET".freeze + POST = "POST".freeze + + def self.all_vars + @all_vars ||= [GET, POST].freeze + end + + def self.build_from_hash(value) + new.build_from_hash(value) + end + + def build_from_hash(value) + return value if ReferCompleteMethodEnum.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #ReferCompleteMethodEnum" + end + end +end \ No newline at end of file diff --git a/lib/bandwidth-sdk/models/sip_uri.rb b/lib/bandwidth-sdk/models/sip_uri.rb new file mode 100644 index 00000000..8a8bd392 --- /dev/null +++ b/lib/bandwidth-sdk/models/sip_uri.rb @@ -0,0 +1,72 @@ +=begin +#Bandwidth +#Bandwidth's Communication APIs +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 +=end + +require 'date' +require 'time' + +module Bandwidth + # Nested SIP URI destination model used by . + class SipUri < ApiModelBase + # SIP URI destination (e.g. sip:alice@atlanta.example.com) + attr_accessor :uri + + def self.attribute_map + { :'uri' => :'uri' } + end + + def self.acceptable_attribute_map + attribute_map + end + + def self.acceptable_attributes + acceptable_attribute_map.values + end + + def self.openapi_types + { :'uri' => :'String' } + end + + def self.openapi_nullable + Set.new([]) + end + + def initialize(attributes = {}) + raise ArgumentError, "attributes must be a Hash" unless attributes.is_a?(Hash) + + acceptable_attribute_map = self.class.acceptable_attribute_map + attributes = attributes.each_with_object({}) do |(k, v), h| + raise ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::SipUri`." unless acceptable_attribute_map.key?(k.to_sym) + h[k.to_sym] = v + end + + self.uri = attributes[:'uri'] if attributes.key?(:'uri') + end + + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + next if attributes[attribute_map[key]].nil? + transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]]) + end + new(transformed_hash) + end + + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + next if value.nil? + hash[param] = _to_hash(value) + end + hash + end + end +end \ No newline at end of file diff --git a/spec/unit/models/refer_call_status_enum_spec.rb b/spec/unit/models/refer_call_status_enum_spec.rb new file mode 100644 index 00000000..5e032de0 --- /dev/null +++ b/spec/unit/models/refer_call_status_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::ReferCallStatusEnum +describe Bandwidth::ReferCallStatusEnum do + describe 'constants' do + it 'defines SUCCESS' do + expect(Bandwidth::ReferCallStatusEnum::SUCCESS).to eq('success') + end + + it 'defines FAILURE' do + expect(Bandwidth::ReferCallStatusEnum::FAILURE).to eq('failure') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ReferCallStatusEnum.all_vars).to eq([ + 'success', + 'failure' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ReferCallStatusEnum.build_from_hash('success')).to eq('success') + expect(Bandwidth::ReferCallStatusEnum.build_from_hash('failure')).to eq('failure') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ReferCallStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end \ No newline at end of file diff --git a/spec/unit/models/refer_complete_callback_spec.rb b/spec/unit/models/refer_complete_callback_spec.rb new file mode 100644 index 00000000..a6e2fb93 --- /dev/null +++ b/spec/unit/models/refer_complete_callback_spec.rb @@ -0,0 +1,213 @@ +# Unit tests for Bandwidth::ReferCompleteCallback +describe Bandwidth::ReferCompleteCallback do + let(:refer_complete_callback_default) { Bandwidth::ReferCompleteCallback.new } + let(:refer_complete_callback_success) { Bandwidth::ReferCompleteCallback.new({ + event_type: 'referComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + refer_call_status: Bandwidth::ReferCallStatusEnum::SUCCESS + }) } + let(:refer_complete_callback_failure) { Bandwidth::ReferCompleteCallback.new({ + event_type: 'referComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + refer_call_status: Bandwidth::ReferCallStatusEnum::FAILURE, + refer_sip_response_code: 405 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ReferCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ReferCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ReferCompleteCallback.acceptable_attributes).to eq(Bandwidth::ReferCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ReferCompleteCallback.openapi_nullable).to eq(Set.new([ + :'answer_time', + :'tag', + :'refer_sip_response_code', + :'notify_sip_response_code' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ReferCompleteCallback created by the build_from_hash method (success)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referCallStatus: 'success', + referSipResponseCode: nil, + notifySipResponseCode: nil + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.event_type).to eq('referComplete') + expect(callback.account_id).to eq('9900000') + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::SUCCESS) + expect(callback.refer_sip_response_code).to be_nil + expect(callback.notify_sip_response_code).to be_nil + end + + it 'validates instance of ReferCompleteCallback for a rejected REFER (referSipResponseCode=405)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: 'inbound', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + referCallStatus: 'failure', + referSipResponseCode: 405 + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::FAILURE) + expect(callback.refer_sip_response_code).to eq(405) + expect(callback.notify_sip_response_code).to be_nil + end + + it 'validates instance of ReferCompleteCallback for an unreachable destination (notifySipResponseCode present)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: 'inbound', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + referCallStatus: 'failure', + referSipResponseCode: 202, + notifySipResponseCode: 503 + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::FAILURE) + expect(callback.refer_sip_response_code).to eq(202) + expect(callback.notify_sip_response_code).to eq(503) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(refer_complete_callback_success.to_s).to eq('{:eventType=>"referComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :referCallStatus=>"success"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(refer_complete_callback_default.eql?(Bandwidth::ReferCompleteCallback.new)).to be true + expect(refer_complete_callback_default.eql?(refer_complete_callback_success)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the success callback' do + expect(refer_complete_callback_success.to_body).to eq({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referCallStatus: Bandwidth::ReferCallStatusEnum::SUCCESS + }) + end + + it 'returns a hash representation of the failure callback with referSipResponseCode' do + expect(refer_complete_callback_failure.to_body).to eq({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referCallStatus: Bandwidth::ReferCallStatusEnum::FAILURE, + referSipResponseCode: 405 + }) + end + + it 'handles NOTIFY timeout (202 accepted, no NOTIFY received)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: 'inbound', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + referCallStatus: 'failure', + referSipResponseCode: 202 + }) + + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::FAILURE) + expect(callback.refer_sip_response_code).to eq(202) + expect(callback.notify_sip_response_code).to be_nil + end + end +end \ No newline at end of file diff --git a/spec/unit/models/refer_complete_method_enum_spec.rb b/spec/unit/models/refer_complete_method_enum_spec.rb new file mode 100644 index 00000000..de14efeb --- /dev/null +++ b/spec/unit/models/refer_complete_method_enum_spec.rb @@ -0,0 +1,19 @@ +describe Bandwidth::ReferCompleteMethodEnum do + it 'defines GET and POST' do + expect(Bandwidth::ReferCompleteMethodEnum::GET).to eq('GET') + expect(Bandwidth::ReferCompleteMethodEnum::POST).to eq('POST') + end + + it 'returns all vars' do + expect(Bandwidth::ReferCompleteMethodEnum.all_vars).to eq(['GET', 'POST']) + end + + it 'builds from valid hash values' do + expect(Bandwidth::ReferCompleteMethodEnum.build_from_hash('GET')).to eq('GET') + expect(Bandwidth::ReferCompleteMethodEnum.build_from_hash('POST')).to eq('POST') + end + + it 'raises for invalid values' do + expect { Bandwidth::ReferCompleteMethodEnum.build_from_hash('PUT') }.to raise_error(RuntimeError) + end +end \ No newline at end of file diff --git a/spec/unit/models/refer_spec.rb b/spec/unit/models/refer_spec.rb new file mode 100644 index 00000000..ccd0015d --- /dev/null +++ b/spec/unit/models/refer_spec.rb @@ -0,0 +1,55 @@ +describe Bandwidth::Refer do + let(:sip_uri) { Bandwidth::SipUri.new(uri: 'sip:alice@atlanta.example.com') } + + it 'initializes and serializes with valid attributes' do + model = Bandwidth::Refer.new( + refer_complete_url: 'https://example.com/referComplete', + refer_complete_method: Bandwidth::ReferCompleteMethodEnum::POST, + tag: 'custom-tag', + sip_uri: sip_uri + ) + + expect(model.to_hash).to eq({ + referCompleteUrl: 'https://example.com/referComplete', + referCompleteMethod: 'POST', + tag: 'custom-tag', + sipUri: { uri: 'sip:alice@atlanta.example.com' } + }) + end + + it 'requires sip_uri' do + expect { + Bandwidth::Refer.new(refer_complete_method: 'POST') + }.to raise_error(ArgumentError) + end + + it 'rejects invalid method enum' do + expect { + Bandwidth::Refer.new(sip_uri: sip_uri, refer_complete_method: 'PUT') + }.to raise_error(RuntimeError) + end + + it 'rejects invalid attributes' do + expect { + Bandwidth::Refer.new(sip_uri: sip_uri, invalid: true) + }.to raise_error(ArgumentError) + end + + it 'rejects a tag exceeding 256 characters' do + expect { + Bandwidth::Refer.new(sip_uri: sip_uri, tag: 'x' * 257) + }.to raise_error(ArgumentError) + end + + it 'builds from hash' do + model = Bandwidth::Refer.build_from_hash({ + referCompleteUrl: 'https://example.com/referComplete', + referCompleteMethod: 'GET', + tag: 'x', + sipUri: { uri: 'sip:alice@atlanta.example.com' } + }) + + expect(model.refer_complete_method).to eq('GET') + expect(model.sip_uri.uri).to eq('sip:alice@atlanta.example.com') + end +end \ No newline at end of file diff --git a/spec/unit/models/sip_uri_spec.rb b/spec/unit/models/sip_uri_spec.rb new file mode 100644 index 00000000..c29d6453 --- /dev/null +++ b/spec/unit/models/sip_uri_spec.rb @@ -0,0 +1,15 @@ +describe Bandwidth::SipUri do + it 'initializes with valid value' do + model = Bandwidth::SipUri.new(uri: 'sip:alice@atlanta.example.com') + expect(model.uri).to eq('sip:alice@atlanta.example.com') + end + + it 'raises on invalid attribute' do + expect { Bandwidth::SipUri.new(invalid: true) }.to raise_error(ArgumentError) + end + + it 'builds from hash and serializes' do + model = Bandwidth::SipUri.build_from_hash({ uri: 'sip:alice@atlanta.example.com' }) + expect(model.to_hash).to eq({ uri: 'sip:alice@atlanta.example.com' }) + end +end \ No newline at end of file