Class: Twilio::REST::Memory::V1::IdentifierList

Inherits:
ListResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/memory/v1/identifier.rb

Defined Under Namespace

Classes: Identifier, IdentifierUpdate

Instance Method Summary collapse

Constructor Details

#initialize(version, store_id: nil, profile_id: nil) ⇒ IdentifierList

Initialize the IdentifierList

Parameters:

  • version (Version) —

    Version that contains the resource



98
99
100
101
102
103
104
105
106
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 98

def initialize(version, store_id: nil, profile_id: nil)
    
    apiV1Version = ApiV1Version.new version.domain, version
    super(apiV1Version)
    # Path Solution
    @solution = { store_id: store_id, profile_id: profile_id }
    @uri = "/Stores/#{@solution[:store_id]}/Profiles/#{@solution[:profile_id]}/Identifiers"
    
end

Instance Method Details

#create(identifier: nil) ⇒ IdentifierInstance

Create the IdentifierInstance

Parameters:

Returns:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 111

def create(identifier: nil
)

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

#create_with_metadata(identifier: nil) ⇒ IdentifierInstance

Create the IdentifierInstanceMetadata

Parameters:

Returns:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 133

def (identifier: nil
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    headers['Content-Type'] = 'application/json'
    
    
    
    
    response = @version.('POST', @uri, headers: headers, data: identifier.to_json)
    identifier_instance = IdentifierInstance.new(
        @version,
        response.body,
        store_id: @solution[:store_id],
        profile_id: @solution[:profile_id],
    )
    IdentifierInstanceMetadata.new(
        @version,
        identifier_instance,
        response.headers,
        response.status_code
    )
end

#each ⇒ Object

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



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 205

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 IdentifierInstance records from the API. Request is executed immediately.

Parameters:

  • target_url (String) —

    API-generated URL for the requested results page

Returns:

  • (Page) —

    Page of IdentifierInstance



242
243
244
245
246
247
248
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 242

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

#list(limit: nil, page_size: nil) ⇒ Array

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

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



169
170
171
172
173
174
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 169

def list(limit: nil, page_size: nil)
    self.stream(
        limit: limit,
        page_size: page_size
    ).entries
end

#page(page_size: :unset) ⇒ Page

Returns Page of IdentifierInstance.

Returns:

  • (Page) —

    Page of IdentifierInstance



224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 224

def page(page_size: :unset)
    params = Twilio::Values.of({
                                    'PageSize' => page_size,
    })
    headers = Twilio::Values.of({})
    
    

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

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

#stream(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:

  • 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



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 187

def stream(limit: nil, page_size: nil)
    limits = @version.read_limits(limit, page_size)

    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
end

#to_s ⇒ Object

Provide a user friendly representation



253
254
255
# File 'lib/twilio-ruby/rest/memory/v1/identifier.rb', line 253

def to_s
    '#<Twilio.Memory.V1.IdentifierList>'
end