Class: VoiceML::QueuesResource

Inherits:
BaseResource show all
Defined in:
lib/voiceml/resources/queues.rb

Overview

Operations on ‘/Queues` and their members.

Constant Summary collapse

QUEUE_FIELDS =
{
  'FriendlyName' => :friendly_name,
  'MaxSize'      => :max_size
}.freeze
DEQUEUE_FIELDS =
{
  'Url'    => :url,
  'Method' => :method
}.freeze
LIST_PAGE_FIELDS =
{
  'Page'      => :page,
  'PageSize'  => :page_size,
  'PageToken' => :page_token
}.freeze
LIST_MEMBERS_FIELDS =
{
  'Page'      => :page,
  'PageSize'  => :page_size,
  'PageToken' => :page_token
}.freeze

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from VoiceML::BaseResource

Instance Method Details

#create(**kwargs) ⇒ VoiceML::Queue

Returns:



32
33
34
35
36
# File 'lib/voiceml/resources/queues.rb', line 32

def create(**kwargs)
  Queue.from_hash(
    @transport.request(:post, path('Queues'), form: form_params(QUEUE_FIELDS, kwargs))
  )
end

#delete(queue_sid) ⇒ nil

Returns:

  • (nil)


73
74
75
76
# File 'lib/voiceml/resources/queues.rb', line 73

def delete(queue_sid)
  @transport.request(:delete, path('Queues', queue_sid))
  nil
end

#dequeue_front(queue_sid, **kwargs) ⇒ VoiceML::QueueMember

Dequeue the front-of-queue member to a TwiML URL.



97
98
99
100
101
102
# File 'lib/voiceml/resources/queues.rb', line 97

def dequeue_front(queue_sid, **kwargs)
  QueueMember.from_hash(
    @transport.request(:post, path('Queues', queue_sid, 'Members', 'Front'),
                       form: form_params(DEQUEUE_FIELDS, kwargs))
  )
end

#dequeue_member(queue_sid, call_sid, **kwargs) ⇒ VoiceML::QueueMember

Dequeue a specific member by CallSid.



113
114
115
116
117
118
# File 'lib/voiceml/resources/queues.rb', line 113

def dequeue_member(queue_sid, call_sid, **kwargs)
  QueueMember.from_hash(
    @transport.request(:post, path('Queues', queue_sid, 'Members', call_sid),
                       form: form_params(DEQUEUE_FIELDS, kwargs))
  )
end

#each(**kwargs) {|VoiceML::Queue| ... } ⇒ Enumerator<VoiceML::Queue>

Returns when no block given.

Yields:

Returns:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/voiceml/resources/queues.rb', line 47

def each(**kwargs, &block)
  return enum_for(:each, **kwargs) unless block

  page_num = kwargs.delete(:page) || 0
  loop do
    chunk = list(**kwargs, page: page_num)
    chunk.queues.each(&block)
    break if chunk.next_page_uri.nil? || chunk.next_page_uri.empty? || chunk.queues.empty?
    page_num += 1
  end
end

#get(queue_sid) ⇒ VoiceML::Queue

Returns:



60
61
62
# File 'lib/voiceml/resources/queues.rb', line 60

def get(queue_sid)
  Queue.from_hash(@transport.request(:get, path('Queues', queue_sid)))
end

#get_member(queue_sid, call_sid) ⇒ VoiceML::QueueMember



105
106
107
108
109
# File 'lib/voiceml/resources/queues.rb', line 105

def get_member(queue_sid, call_sid)
  QueueMember.from_hash(
    @transport.request(:get, path('Queues', queue_sid, 'Members', call_sid))
  )
end

#list(**kwargs) ⇒ VoiceML::QueueList

Returns:



39
40
41
42
43
# File 'lib/voiceml/resources/queues.rb', line 39

def list(**kwargs)
  QueueList.from_hash(
    @transport.request(:get, path('Queues'), params: form_params(LIST_PAGE_FIELDS, kwargs))
  )
end

#list_members(queue_sid, **kwargs) ⇒ VoiceML::QueueMemberList



81
82
83
84
85
86
# File 'lib/voiceml/resources/queues.rb', line 81

def list_members(queue_sid, **kwargs)
  QueueMemberList.from_hash(
    @transport.request(:get, path('Queues', queue_sid, 'Members'),
                       params: form_params(LIST_MEMBERS_FIELDS, kwargs))
  )
end

#peek_front(queue_sid) ⇒ VoiceML::QueueMember



89
90
91
92
93
# File 'lib/voiceml/resources/queues.rb', line 89

def peek_front(queue_sid)
  QueueMember.from_hash(
    @transport.request(:get, path('Queues', queue_sid, 'Members', 'Front'))
  )
end

#update(queue_sid, **kwargs) ⇒ VoiceML::Queue

Returns:



65
66
67
68
69
70
# File 'lib/voiceml/resources/queues.rb', line 65

def update(queue_sid, **kwargs)
  Queue.from_hash(
    @transport.request(:post, path('Queues', queue_sid),
                       form: form_params(QUEUE_FIELDS, kwargs))
  )
end