class Twilio::REST::Sync::V1::ServiceContext::DocumentList

Public Class Methods

new(version, service_sid: nil) click to toggle source

Initialize the DocumentList @param [Version] version Version that contains the resource @param [String] service_sid The SID of the {Sync

Service}[https://www.twilio.com/docs/sync/api/service] the resource is
associated with.

@return [DocumentList] DocumentList

Calls superclass method Twilio::REST::ListResource::new
   # File lib/twilio-ruby/rest/sync/v1/service/document.rb
22 def initialize(version, service_sid: nil)
23   super(version)
24 
25   # Path Solution
26   @solution = {service_sid: service_sid}
27   @uri = "/Services/#{@solution[:service_sid]}/Documents"
28 end

Public Instance Methods

create(unique_name: :unset, data: :unset, ttl: :unset) click to toggle source

Create the DocumentInstance @param [String] unique_name An application-defined string that uniquely

identifies the Sync Document

@param [Hash] data A JSON string that represents an arbitrary, schema-less

object that the Sync Document stores. Can be up to 16 KiB in length.

@param [String] ttl How long, {in

seconds}[https://www.twilio.com/docs/sync/limits#sync-payload-limits], before
the Sync Document expires and is deleted (the Sync Document's time-to-live).

@return [DocumentInstance] Created DocumentInstance

   # File lib/twilio-ruby/rest/sync/v1/service/document.rb
40 def create(unique_name: :unset, data: :unset, ttl: :unset)
41   data = Twilio::Values.of({
42       'UniqueName' => unique_name,
43       'Data' => Twilio.serialize_object(data),
44       'Ttl' => ttl,
45   })
46 
47   payload = @version.create('POST', @uri, data: data)
48 
49   DocumentInstance.new(@version, payload, service_sid: @solution[:service_sid], )
50 end
each() { |x| ... } click to toggle source

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

   # File lib/twilio-ruby/rest/sync/v1/service/document.rb
90 def each
91   limits = @version.read_limits
92 
93   page = self.page(page_size: limits[:page_size], )
94 
95   @version.stream(page,
96                   limit: limits[:limit],
97                   page_limit: limits[:page_limit]).each {|x| yield x}
98 end
get_page(target_url) click to toggle source

Retrieve a single page of DocumentInstance records from the API. Request is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page of DocumentInstance

    # File lib/twilio-ruby/rest/sync/v1/service/document.rb
124 def get_page(target_url)
125   response = @version.domain.request(
126       'GET',
127       target_url
128   )
129   DocumentPage.new(@version, response, @solution)
130 end
list(limit: nil, page_size: nil) click to toggle source

Lists DocumentInstance 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

   # File lib/twilio-ruby/rest/sync/v1/service/document.rb
63 def list(limit: nil, page_size: nil)
64   self.stream(limit: limit, page_size: page_size).entries
65 end
page(page_token: :unset, page_number: :unset, page_size: :unset) click to toggle source

Retrieve a single page of DocumentInstance 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 DocumentInstance

    # File lib/twilio-ruby/rest/sync/v1/service/document.rb
107 def page(page_token: :unset, page_number: :unset, page_size: :unset)
108   params = Twilio::Values.of({
109       'PageToken' => page_token,
110       'Page' => page_number,
111       'PageSize' => page_size,
112   })
113 
114   response = @version.page('GET', @uri, params: params)
115 
116   DocumentPage.new(@version, response, @solution)
117 end
stream(limit: nil, page_size: nil) click to toggle source

Streams DocumentInstance 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

   # File lib/twilio-ruby/rest/sync/v1/service/document.rb
78 def stream(limit: nil, page_size: nil)
79   limits = @version.read_limits(limit, page_size)
80 
81   page = self.page(page_size: limits[:page_size], )
82 
83   @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
84 end
to_s() click to toggle source

Provide a user friendly representation

    # File lib/twilio-ruby/rest/sync/v1/service/document.rb
134 def to_s
135   '#<Twilio.Sync.V1.DocumentList>'
136 end