Class: Twilio::REST::Notify::V1::ServiceList

Inherits:
ListResource show all
Defined in:
lib/twilio-ruby/rest/notify/v1/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ ServiceList

Initialize the ServiceList

Parameters:

  • Version that contains the resource



26
27
28
29
30
31
32
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 26

def initialize(version)
    super(version)
    # Path Solution
    @solution = {  }
    @uri = "/Services"
    
end

Instance Method Details

#create(friendly_name: :unset, apn_credential_sid: :unset, gcm_credential_sid: :unset, messaging_service_sid: :unset, facebook_messenger_page_id: :unset, default_apn_notification_protocol_version: :unset, default_gcm_notification_protocol_version: :unset, fcm_credential_sid: :unset, default_fcm_notification_protocol_version: :unset, log_enabled: :unset, alexa_skill_id: :unset, default_alexa_notification_protocol_version: :unset, delivery_callback_url: :unset, delivery_callback_enabled: :unset) ⇒ ServiceInstance

Create the ServiceInstance

Parameters:

Returns:

  • Created ServiceInstance



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 50

def create(
    friendly_name: :unset, 
    apn_credential_sid: :unset, 
    gcm_credential_sid: :unset, 
    messaging_service_sid: :unset, 
    facebook_messenger_page_id: :unset, 
    default_apn_notification_protocol_version: :unset, 
    default_gcm_notification_protocol_version: :unset, 
    fcm_credential_sid: :unset, 
    default_fcm_notification_protocol_version: :unset, 
    log_enabled: :unset, 
    alexa_skill_id: :unset, 
    default_alexa_notification_protocol_version: :unset, 
    delivery_callback_url: :unset, 
    delivery_callback_enabled: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'ApnCredentialSid' => apn_credential_sid,
        'GcmCredentialSid' => gcm_credential_sid,
        'MessagingServiceSid' => messaging_service_sid,
        'FacebookMessengerPageId' => facebook_messenger_page_id,
        'DefaultApnNotificationProtocolVersion' => default_apn_notification_protocol_version,
        'DefaultGcmNotificationProtocolVersion' => default_gcm_notification_protocol_version,
        'FcmCredentialSid' => fcm_credential_sid,
        'DefaultFcmNotificationProtocolVersion' => default_fcm_notification_protocol_version,
        'LogEnabled' => log_enabled,
        'AlexaSkillId' => alexa_skill_id,
        'DefaultAlexaNotificationProtocolVersion' => default_alexa_notification_protocol_version,
        'DeliveryCallbackUrl' => delivery_callback_url,
        'DeliveryCallbackEnabled' => delivery_callback_enabled,
    })

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

#eachObject

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



144
145
146
147
148
149
150
151
152
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 144

def each
    limits = @version.read_limits

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

    @version.stream(page,
        limit: limits[:limit],
        page_limit: limits[:page_limit]).each {|x| yield x}
end

#get_page(target_url) ⇒ Page

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

Parameters:

  • API-generated URL for the requested results page

Returns:

  • Page of ServiceInstance



183
184
185
186
187
188
189
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 183

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

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

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

Parameters:

  • (defaults to: :unset)

    The string that identifies the Service resources to read.

  • (defaults to: nil)

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

  • (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 of up to limit results



110
111
112
113
114
115
116
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 110

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

#page(friendly_name: :unset, page_token: :unset, page_number: :unset, page_size: :unset) ⇒ Page

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

Parameters:

  • (defaults to: :unset)

    The string that identifies the Service resources to read.

  • (defaults to: :unset)

    PageToken provided by the API

  • (defaults to: :unset)

    Page Number, this value is simply for client state

  • (defaults to: :unset)

    Number of records to return, defaults to 50

Returns:

  • Page of ServiceInstance



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 162

def page(friendly_name: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
    params = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'PageToken' => page_token,
        'Page' => page_number,
        'PageSize' => page_size,
    })
    headers = Twilio::Values.of({})
    
    

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

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

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

  • (defaults to: :unset)

    The string that identifies the Service resources to read.

  • (defaults to: nil)

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

  • (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 that will yield up to limit results



130
131
132
133
134
135
136
137
138
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 130

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

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

    @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
end

#to_sObject

Provide a user friendly representation



194
195
196
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 194

def to_s
    '#<Twilio.Notify.V1.ServiceList>'
end