Skip to content

Commit

Permalink
DX-2648 Add enqueuedTime to SDK (#56)
Browse files Browse the repository at this point in the history
* DX-2648 Add enqueuedTime to SDK

* add test for `enqueued_time`

* add test for create call response and add accessor
  • Loading branch information
ckoegel authored Jun 24, 2022
1 parent af13607 commit 1e6ff4b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
21 changes: 19 additions & 2 deletions lib/bandwidth/voice_lib/voice/models/call_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class CallState < BaseModel
# @return [DateTime]
attr_accessor :start_time

# @return [DateTime]
attr_accessor :enqueued_time

# The current state of the call. Current possible values are 'initiated',
# 'answered' and 'disconnected'. Additional states may be added in the
# future, so your application must be tolerant of unknown values.
Expand Down Expand Up @@ -124,6 +127,7 @@ def self.names
@_hash['identity'] = 'identity'
@_hash['stir_shaken'] = 'stirShaken'
@_hash['start_time'] = 'startTime'
@_hash['enqueued_time'] = 'enqueuedTime'
@_hash['answer_time'] = 'answerTime'
@_hash['end_time'] = 'endTime'
@_hash['disconnect_cause'] = 'disconnectCause'
Expand All @@ -147,6 +151,7 @@ def optionals
identity
stir_shaken
start_time
enqueued_time
answer_time
end_time
disconnect_cause
Expand Down Expand Up @@ -180,6 +185,7 @@ def initialize(call_id = nil,
identity = nil,
stir_shaken = nil,
start_time = nil,
enqueued_time = nil,
answer_time = nil,
end_time = nil,
disconnect_cause = nil,
Expand All @@ -197,6 +203,7 @@ def initialize(call_id = nil,
@identity = identity unless identity == SKIP
@stir_shaken = stir_shaken unless stir_shaken == SKIP
@start_time = start_time unless start_time == SKIP
@enqueued_time = enqueued_time unless enqueued_time == SKIP
@answer_time = answer_time unless answer_time == SKIP
@end_time = end_time unless end_time == SKIP
@disconnect_cause = disconnect_cause unless disconnect_cause == SKIP
Expand All @@ -221,17 +228,22 @@ def self.from_hash(hash)
identity = hash.key?('identity') ? hash['identity'] : SKIP
stir_shaken = hash.key?('stirShaken') ? hash['stirShaken'] : SKIP
start_time = if hash.key?('startTime')
(DateTimeHelper.from_rfc3339(hash['startTime']) if hash['startTime'])
(DateTimeHelper.from_rfc3339(hash['startTime']) if hash['startTime'])
else
SKIP
end
enqueued_time = if hash.key?('enqueuedTime')
(DateTimeHelper.from_rfc3339(hash['enqueuedTime']) if hash['enqueuedTime'])
else
SKIP
end
answer_time = if hash.key?('answerTime')
(DateTimeHelper.from_rfc3339(hash['answerTime']) if hash['answerTime'])
else
SKIP
end
end_time = if hash.key?('endTime')
(DateTimeHelper.from_rfc3339(hash['endTime']) if hash['endTime'])
(DateTimeHelper.from_rfc3339(hash['endTime']) if hash['endTime'])
else
SKIP
end
Expand All @@ -257,6 +269,7 @@ def self.from_hash(hash)
identity,
stir_shaken,
start_time,
enqueued_time,
answer_time,
end_time,
disconnect_cause,
Expand All @@ -269,6 +282,10 @@ def to_start_time
DateTimeHelper.to_rfc3339(start_time)
end

def to_enqueued_time
DateTimeHelper.to_rfc3339(enqueued_time)
end

def to_answer_time
DateTimeHelper.to_rfc3339(answer_time)
end
Expand Down
20 changes: 10 additions & 10 deletions lib/bandwidth/voice_lib/voice/models/create_call_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CreateCallResponse < BaseModel

# TODO: Write general description for this method
# @return [DateTime]
attr_accessor :start_time
attr_accessor :enqueued_time

# TODO: Write general description for this method
# @return [String]
Expand Down Expand Up @@ -101,7 +101,7 @@ def self.names
@_hash['application_id'] = 'applicationId'
@_hash['to'] = 'to'
@_hash['from'] = 'from'
@_hash['start_time'] = 'startTime'
@_hash['enqueued_time'] = 'enqueuedTime '
@_hash['call_url'] = 'callUrl'
@_hash['call_timeout'] = 'callTimeout'
@_hash['callback_timeout'] = 'callbackTimeout'
Expand All @@ -123,7 +123,7 @@ def self.names
# An array for optional fields
def optionals
%w[
start_time
enqueued_time
call_timeout
callback_timeout
answer_fallback_url
Expand Down Expand Up @@ -163,7 +163,7 @@ def initialize(account_id = nil,
answer_url = nil,
answer_method = nil,
disconnect_method = nil,
start_time = nil,
enqueued_time = nil,
call_timeout = nil,
callback_timeout = nil,
answer_fallback_url = nil,
Expand All @@ -180,7 +180,7 @@ def initialize(account_id = nil,
@application_id = application_id unless application_id == SKIP
@to = to unless to == SKIP
@from = from unless from == SKIP
@start_time = start_time unless start_time == SKIP
@enqueued_time = enqueued_time unless enqueued_time == SKIP
@call_url = call_url unless call_url == SKIP
@call_timeout = call_timeout unless call_timeout == SKIP
@callback_timeout = callback_timeout unless callback_timeout == SKIP
Expand Down Expand Up @@ -213,8 +213,8 @@ def self.from_hash(hash)
answer_method = hash.key?('answerMethod') ? hash['answerMethod'] : SKIP
disconnect_method =
hash.key?('disconnectMethod') ? hash['disconnectMethod'] : SKIP
start_time = if hash.key?('startTime')
(DateTimeHelper.from_rfc3339(hash['startTime']) if hash['startTime'])
enqueued_time = if hash.key?('enqueuedTime')
(DateTimeHelper.from_rfc3339(hash['enqueuedTime']) if hash['enqueuedTime'])
else
SKIP
end
Expand Down Expand Up @@ -245,7 +245,7 @@ def self.from_hash(hash)
answer_url,
answer_method,
disconnect_method,
start_time,
enqueued_time,
call_timeout,
callback_timeout,
answer_fallback_url,
Expand All @@ -259,8 +259,8 @@ def self.from_hash(hash)
priority)
end

def to_start_time
DateTimeHelper.to_rfc3339(start_time)
def to_enqueued_time
DateTimeHelper.to_rfc3339(enqueued_time)
end
end
end
4 changes: 4 additions & 0 deletions test/integration/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ def test_create_call_and_get_call_state
body.answer_url = BASE_CALLBACK_URL
response = @bandwidth_client.voice_client.client.create_call(BW_ACCOUNT_ID, body)
assert(response.data.call_id.length > 0, "call_id value not set")
assert_not_nil(response.data.enqueued_time, "enqueued time is nil")
assert(response.data.enqueued_time.is_a?(DateTime), "enqueued time is not a DateTime object")

#Get phone call information
sleep 1
response = @bandwidth_client.voice_client.client.get_call(BW_ACCOUNT_ID, response.data.call_id)
assert(response.data.state.length > 0, "state value not set")
assert_not_nil(response.data.enqueued_time, "enqueued time is nil")
assert(response.data.enqueued_time.is_a?(DateTime), "enqueued time is not a DateTime object")
end

def test_create_call_with_amd_and_get_call_state
Expand Down

0 comments on commit 1e6ff4b

Please sign in to comment.