class Twilio::REST::Api::V2010::AccountContext::UsageList::TriggerList

Public Class Methods

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

Initialize the TriggerList @param [Version] version Version that contains the resource @param [String] account_sid A 34 character string that uniquely identifies this

resource.

@return [TriggerList] TriggerList

Calls superclass method Twilio::REST::ListResource::new
   # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
22 def initialize(version, account_sid: nil)
23   super(version)
24 
25   # Path Solution
26   @solution = {account_sid: account_sid}
27   @uri = "/Accounts/#{@solution[:account_sid]}/Usage/Triggers.json"
28 end

Public Instance Methods

create(callback_url: nil, trigger_value: nil, usage_category: nil, callback_method: :unset, friendly_name: :unset, recurring: :unset, trigger_by: :unset) click to toggle source

Create the TriggerInstance @param [String] callback_url The URL we should call using `callback_method` when

the trigger fires.

@param [String] trigger_value The usage value at which the trigger should fire.

For convenience, you can use an offset value such as `+30` to specify a
trigger_value that is 30 units more than the current usage value. Be sure to
urlencode a `+` as `%2B`.

@param [trigger.UsageCategory] usage_category The usage category that the

trigger should watch.  Use one of the supported {usage
categories}[https://www.twilio.com/docs/usage/api/usage-record#usage-categories]
for this value.

@param [String] callback_method The HTTP method we should use to call

`callback_url`. Can be: `GET` or `POST` and the default is `POST`.

@param [String] friendly_name A descriptive string that you create to describe

the resource. It can be up to 64 characters long.

@param [trigger.Recurring] recurring The frequency of a recurring UsageTrigger.

Can be: `daily`, `monthly`, or `yearly` for recurring triggers or empty for
non-recurring triggers. A trigger will only fire once during each period.
Recurring times are in GMT.

@param [trigger.TriggerField] trigger_by The field in the

{UsageRecord}[https://www.twilio.com/docs/usage/api/usage-record] resource that
should fire the trigger.  Can be: `count`, `usage`, or `price` as described in
the {UsageRecords
documentation}[https://www.twilio.com/docs/usage/api/usage-record#usage-count-price].
 The default is `usage`.

@return [TriggerInstance] Created TriggerInstance

   # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
57 def create(callback_url: nil, trigger_value: nil, usage_category: nil, callback_method: :unset, friendly_name: :unset, recurring: :unset, trigger_by: :unset)
58   data = Twilio::Values.of({
59       'CallbackUrl' => callback_url,
60       'TriggerValue' => trigger_value,
61       'UsageCategory' => usage_category,
62       'CallbackMethod' => callback_method,
63       'FriendlyName' => friendly_name,
64       'Recurring' => recurring,
65       'TriggerBy' => trigger_by,
66   })
67 
68   payload = @version.create('POST', @uri, data: data)
69 
70   TriggerInstance.new(@version, payload, account_sid: @solution[:account_sid], )
71 end
each() { |x| ... } click to toggle source

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

    # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
140 def each
141   limits = @version.read_limits
142 
143   page = self.page(page_size: limits[:page_size], )
144 
145   @version.stream(page,
146                   limit: limits[:limit],
147                   page_limit: limits[:page_limit]).each {|x| yield x}
148 end
get_page(target_url) click to toggle source

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

    # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
186 def get_page(target_url)
187   response = @version.domain.request(
188       'GET',
189       target_url
190   )
191   TriggerPage.new(@version, response, @solution)
192 end
list(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil) click to toggle source

Lists TriggerInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. @param [trigger.Recurring] recurring The frequency of recurring UsageTriggers to

read. Can be: `daily`, `monthly`, or `yearly` to read recurring UsageTriggers.
An empty value or a value of `alltime` reads non-recurring UsageTriggers.

@param [trigger.TriggerField] trigger_by The trigger field of the UsageTriggers

to read.  Can be: `count`, `usage`, or `price` as described in the {UsageRecords
documentation}[https://www.twilio.com/docs/usage/api/usage-record#usage-count-price].

@param [trigger.UsageCategory] usage_category The usage category of the

UsageTriggers to read. Must be a supported {usage
categories}[https://www.twilio.com/docs/usage/api/usage-record#usage-categories].

@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/api/v2010/account/usage/trigger.rb
 93 def list(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil)
 94   self.stream(
 95       recurring: recurring,
 96       trigger_by: trigger_by,
 97       usage_category: usage_category,
 98       limit: limit,
 99       page_size: page_size
100   ).entries
101 end
page(recurring: :unset, trigger_by: :unset, usage_category: :unset, page_token: :unset, page_number: :unset, page_size: :unset) click to toggle source

Retrieve a single page of TriggerInstance records from the API. Request is executed immediately. @param [trigger.Recurring] recurring The frequency of recurring UsageTriggers to

read. Can be: `daily`, `monthly`, or `yearly` to read recurring UsageTriggers.
An empty value or a value of `alltime` reads non-recurring UsageTriggers.

@param [trigger.TriggerField] trigger_by The trigger field of the UsageTriggers

to read.  Can be: `count`, `usage`, or `price` as described in the {UsageRecords
documentation}[https://www.twilio.com/docs/usage/api/usage-record#usage-count-price].

@param [trigger.UsageCategory] usage_category The usage category of the

UsageTriggers to read. Must be a supported {usage
categories}[https://www.twilio.com/docs/usage/api/usage-record#usage-categories].

@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 TriggerInstance

    # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
166 def page(recurring: :unset, trigger_by: :unset, usage_category: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
167   params = Twilio::Values.of({
168       'Recurring' => recurring,
169       'TriggerBy' => trigger_by,
170       'UsageCategory' => usage_category,
171       'PageToken' => page_token,
172       'Page' => page_number,
173       'PageSize' => page_size,
174   })
175 
176   response = @version.page('GET', @uri, params: params)
177 
178   TriggerPage.new(@version, response, @solution)
179 end
stream(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil) click to toggle source

Streams TriggerInstance records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached. @param [trigger.Recurring] recurring The frequency of recurring UsageTriggers to

read. Can be: `daily`, `monthly`, or `yearly` to read recurring UsageTriggers.
An empty value or a value of `alltime` reads non-recurring UsageTriggers.

@param [trigger.TriggerField] trigger_by The trigger field of the UsageTriggers

to read.  Can be: `count`, `usage`, or `price` as described in the {UsageRecords
documentation}[https://www.twilio.com/docs/usage/api/usage-record#usage-count-price].

@param [trigger.UsageCategory] usage_category The usage category of the

UsageTriggers to read. Must be a supported {usage
categories}[https://www.twilio.com/docs/usage/api/usage-record#usage-categories].

@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/api/v2010/account/usage/trigger.rb
123 def stream(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil)
124   limits = @version.read_limits(limit, page_size)
125 
126   page = self.page(
127       recurring: recurring,
128       trigger_by: trigger_by,
129       usage_category: usage_category,
130       page_size: limits[:page_size],
131   )
132 
133   @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
134 end
to_s() click to toggle source

Provide a user friendly representation

    # File lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb
196 def to_s
197   '#<Twilio.Api.V2010.TriggerList>'
198 end