Class: Twilio::REST::Conversations::V2::ConversationList

Inherits:
ListResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v2/conversation.rb

Defined Under Namespace

Classes: ConversationsV2Address, ConversationsV2CaptureRule, ConversationsV2StatusTimeouts, CreateConversationWithConfigRequest, CreateConversationWithConfigRequestConfiguration, CreateConversationWithConfigRequestParticipants, CreateConversationWithConfigRequestParticipantsAddresses, PatchConversationByIdRequest, PatchConversationByIdRequestConfiguration, UpdateConversationByIdRequest

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ ConversationList

Initialize the ConversationList

Parameters:

  • version (Version)

    Version that contains the resource



563
564
565
566
567
568
569
570
571
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 563

def initialize(version)
    
    apiV1Version = ApiV1Version.new version.domain, version
    super(apiV1Version)
    # Path Solution
    @solution = {  }
    @uri = "/Conversations"
    
end

Instance Method Details

#create(create_conversation_with_config_request: :unset) ⇒ ConversationInstance

Create the ConversationInstance

Parameters:

Returns:



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 576

def create(create_conversation_with_config_request: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    headers['Content-Type'] = 'application/json'
    
    
    
    
    payload = @version.create('POST', @uri, headers: headers, data: create_conversation_with_config_request.to_json)
    ConversationInstance.new(
        @version,
        payload,
    )
end

#create_with_metadata(create_conversation_with_config_request: :unset) ⇒ ConversationInstance

Create the ConversationInstanceMetadata

Parameters:

Returns:



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 596

def (create_conversation_with_config_request: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    headers['Content-Type'] = 'application/json'
    
    
    
    
    response = @version.('POST', @uri, headers: headers, data: create_conversation_with_config_request.to_json)
    conversation_instance = ConversationInstance.new(
        @version,
        response.body,
    )
    ConversationInstanceMetadata.new(
        @version,
        conversation_instance,
        response.headers,
        response.status_code
    )
end

#eachObject

When passed a block, yields ConversationInstance records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.



706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 706

def each
    limits = @version.read_limits

    page = self.page(page_size: limits[:page_size], )

    return [].each if page.nil?

    result = @version.stream(page,
        limit: limits[:limit],
        page_limit: limits[:page_limit])
    return [].each if result.nil?
    result.each {|x| yield x}
end

#get_page(target_url) ⇒ Page

Retrieve a single page of ConversationInstance records from the API. Request is executed immediately.

Parameters:

  • target_url (String)

    API-generated URL for the requested results page

Returns:

  • (Page)

    Page of ConversationInstance



750
751
752
753
754
755
756
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 750

def get_page(target_url)
    response = @version.domain.request(
        'GET',
        target_url
    )
ConversationPage.new(@version, response, @solution)
end

#list(status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil) ⇒ Array

Lists ConversationInstance records from the API as a list. Unlike stream(), this operation is eager and will load ‘limit` records into memory before returning.

Parameters:

  • status (Array[String]) (defaults to: :unset)

    Filters for specific statuses

  • channel_id (String) (defaults to: :unset)

    The resource identifier (such as callSid or messageSid) to filter conversations.

  • page_token (String) (defaults to: :unset)

    A URL-safe, base64-encoded token representing the page of results to return

  • limit (Integer) (defaults to: nil)

    Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit

  • page_size (Integer) (defaults to: nil)

    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)

Returns:

  • (Array)

    Array of up to limit results



633
634
635
636
637
638
639
640
641
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 633

def list(status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil)
    self.stream(
        status: status,
        channel_id: channel_id,
        page_token: page_token,
        limit: limit,
        page_size: page_size
    ).entries
end

#list_with_metadata(status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil) ⇒ Array

Returns Array of up to limit results.

Parameters:

  • limit (Integer) (defaults to: nil)

    Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit

  • page_size (Integer) (defaults to: nil)

    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)

Returns:

  • (Array)

    Array of up to limit results



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 685

def (status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil)
    limits = @version.read_limits(limit, page_size)
    params = Twilio::Values.of({
        
        'status' =>  Twilio.serialize_list(status) { |e| e },
        'channelId' => channel_id,
        'pageToken' => page_token,
        
        'PageSize' => limits[:page_size],
    });
    headers = Twilio::Values.of({})

    response = @version.page('GET', @uri, params: params, headers: headers)

    ConversationPageMetadata.new(@version, response, @solution, limits[:limit])
end

#page(status: :unset, channel_id: :unset, page_token: :unset, page_size: :unset) ⇒ Page

Returns Page of ConversationInstance.

Returns:

  • (Page)

    Page of ConversationInstance



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 728

def page(status: :unset, channel_id: :unset, page_token: :unset, page_size: :unset)
    params = Twilio::Values.of({
        
        'status' =>  Twilio.serialize_list(status) { |e| e },
        'channelId' => channel_id,
        'pageToken' => page_token,
                                    'PageSize' => page_size,
    })
    headers = Twilio::Values.of({})
    
    

    response = @version.page('GET', @uri, params: params, headers: headers)

    ConversationPage.new(@version, response, @solution)
end

#stream(status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil) ⇒ Enumerable

Streams Instance records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached.

Parameters:

  • status (Array[String]) (defaults to: :unset)

    Filters for specific statuses

  • channel_id (String) (defaults to: :unset)

    The resource identifier (such as callSid or messageSid) to filter conversations.

  • page_token (String) (defaults to: :unset)

    A URL-safe, base64-encoded token representing the page of results to return

  • limit (Integer) (defaults to: nil)

    Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit

  • page_size (Integer) (defaults to: nil)

    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)

Returns:

  • (Enumerable)

    Enumerable that will yield up to limit results



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 657

def stream(status: :unset, channel_id: :unset, page_token: :unset, limit: nil, page_size: nil)
    limits = @version.read_limits(limit, page_size)

    page = self.page(
        status: status,
        channel_id: channel_id,
        page_token: page_token,
        page_size: limits[:page_size], )

    return [].each if page.nil?

    result = @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
    return [].each if result.nil?
    result
end

#to_sObject

Provide a user friendly representation



761
762
763
# File 'lib/twilio-ruby/rest/conversations/v2/conversation.rb', line 761

def to_s
    '#<Twilio.Conversations.V2.ConversationList>'
end