Class: Twilio::REST::Messaging::V1::ServiceList

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

Overview

PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ ServiceList

Initialize the ServiceList

Parameters:

  • version (Version)

    Version that contains the resource



20
21
22
23
24
25
26
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 20

def initialize(version)
  super(version)

  # Path Solution
  @solution = {}
  @uri = "/Services"
end

Instance Method Details

#create(friendly_name: nil, inbound_request_url: :unset, inbound_method: :unset, fallback_url: :unset, fallback_method: :unset, status_callback: :unset, sticky_sender: :unset, mms_converter: :unset, smart_encoding: :unset, scan_message_content: :unset, fallback_to_long_code: :unset, area_code_geomatch: :unset, validity_period: :unset, synchronous_validation: :unset) ⇒ ServiceInstance

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

Parameters:

  • friendly_name (String) (defaults to: nil)

    A human readable descriptive text for this resource, up to 64 characters.

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

    A [webhook request](www.twilio.com/docs/api/twiml/sms/twilio_request) is made to the Inbound Request URL when a message is received by any phone number or shortcode associated to your Messaging Service. Set to ‘null` to disable inbound messaging.

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

    The HTTP method used when making requests to the Inbound Request URL. Either ‘GET` or `POST`. Default value is `POST`.

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

    A request is made to the Fallback URL if an error occurs with retrieving or executing the TwiML from you Inbound Request URL.

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

    The HTTP method used when requesting the Fallback URL. Either ‘GET` or `POST`. Default value is `POST`.

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

    A webhook request is made to the Status Callback to pass [status updates](www.twilio.com/docs/api/rest/message#sms-status-values) about your messages. These status updates let you know if your accepted message were successfully sent and delivered or if a [delivery related error](www.twilio.com/docs/api/rest/message#error-values) may have occurred.

  • sticky_sender (Boolean) (defaults to: :unset)

    Configuration to enable or disable Sticky Sender on your Service Instance. Possible values are ‘true` and `false`. Default value is `true`.

  • mms_converter (Boolean) (defaults to: :unset)

    Configuration to enable or disable MMS Converter on your Service Instance. Possible values are ‘true` and `false`. Default value is `true`.

  • smart_encoding (Boolean) (defaults to: :unset)

    Configuration to enable or disable [Smart Encoding](www.twilio.com/docs/api/messaging/services-and-copilot#smart-encoding). Possible values are ‘true` and `false`. Default value is `true`.

  • scan_message_content (service.ScanMessageContent) (defaults to: :unset)

    The scan_message_content

  • fallback_to_long_code (Boolean) (defaults to: :unset)

    Configuration to enable or disable [Fallback to Long Code](www.twilio.com/docs/api/messaging/services-and-copilot#fallback-to-long-code). Possible values are ‘true` and `false`. Default value is `false`.

  • area_code_geomatch (Boolean) (defaults to: :unset)

    Configuration to enable or disable [Area Code Geomatch](www.twilio.com/docs/api/messaging/services-and-copilot#area-code-geomatch). Possible values are ‘true` and `false`. Default value is `false`.

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

    Configuration to set the [validity period](www.twilio.com/docs/api/messaging/services-and-copilot#validity-period) of all messages sent from your Service, in seconds. Acceptable integers range from ‘1` to `14,400`. Default value is `14,400`.

  • synchronous_validation (Boolean) (defaults to: :unset)

    The synchronous_validation

Returns:



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
96
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 71

def create(friendly_name: nil, inbound_request_url: :unset, inbound_method: :unset, fallback_url: :unset, fallback_method: :unset, status_callback: :unset, sticky_sender: :unset, mms_converter: :unset, smart_encoding: :unset, scan_message_content: :unset, fallback_to_long_code: :unset, area_code_geomatch: :unset, validity_period: :unset, synchronous_validation: :unset)
  data = Twilio::Values.of({
      'FriendlyName' => friendly_name,
      'InboundRequestUrl' => inbound_request_url,
      'InboundMethod' => inbound_method,
      'FallbackUrl' => fallback_url,
      'FallbackMethod' => fallback_method,
      'StatusCallback' => status_callback,
      'StickySender' => sticky_sender,
      'MmsConverter' => mms_converter,
      'SmartEncoding' => smart_encoding,
      'ScanMessageContent' => scan_message_content,
      'FallbackToLongCode' => fallback_to_long_code,
      'AreaCodeGeomatch' => area_code_geomatch,
      'ValidityPeriod' => validity_period,
      'SynchronousValidation' => synchronous_validation,
  })

  payload = @version.create(
      'POST',
      @uri,
      data: data
  )

  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.



136
137
138
139
140
141
142
143
144
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 136

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:

  • target_url (String)

    API-generated URL for the requested results page

Returns:

  • (Page)

    Page of ServiceInstance



172
173
174
175
176
177
178
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 172

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

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

  • 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



109
110
111
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 109

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

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

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

    PageToken provided by the API

  • page_number (Integer) (defaults to: :unset)

    Page Number, this value is simply for client state

  • page_size (Integer) (defaults to: :unset)

    Number of records to return, defaults to 50

Returns:

  • (Page)

    Page of ServiceInstance



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 153

def page(page_token: :unset, page_number: :unset, page_size: :unset)
  params = Twilio::Values.of({
      'PageToken' => page_token,
      'Page' => page_number,
      'PageSize' => page_size,
  })
  response = @version.page(
      'GET',
      @uri,
      params
  )
  ServicePage.new(@version, response, @solution)
end

#stream(limit: nil, page_size: nil) ⇒ Enumerable

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



124
125
126
127
128
129
130
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 124

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

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

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

#to_sObject

Provide a user friendly representation



182
183
184
# File 'lib/twilio-ruby/rest/messaging/v1/service.rb', line 182

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