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

Inherits:
ListResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, account_sid: nil) ⇒ TriggerList

Initialize the TriggerList

Parameters:

  • version (Version)

    Version that contains the resource

  • account_sid (String) (defaults to: nil)

    A 34 character string that uniquely identifies this resource.


22
23
24
25
26
27
28
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 22

def initialize(version, account_sid: nil)
  super(version)

  # Path Solution
  @solution = {account_sid: }
  @uri = "/Accounts/#{@solution[:account_sid]}/Usage/Triggers.json"
end

Instance Method Details

#create(callback_url: nil, trigger_value: nil, usage_category: nil, callback_method: :unset, friendly_name: :unset, recurring: :unset, trigger_by: :unset) ⇒ TriggerInstance

Create the TriggerInstance

Parameters:

  • callback_url (String) (defaults to: nil)

    The URL we should call using `callback_method` when the trigger fires.

  • trigger_value (String) (defaults to: nil)

    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`.

  • usage_category (trigger.UsageCategory) (defaults to: nil)

    The usage category that the trigger should watch. Use one of the supported usage categories for this value.

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

    The HTTP method we should use to call `callback_url`. Can be: `GET` or `POST` and the default is `POST`.

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

    A descriptive string that you create to describe the resource. It can be up to 64 characters long.

  • recurring (trigger.Recurring) (defaults to: :unset)

    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.

  • trigger_by (trigger.TriggerField) (defaults to: :unset)

    The field in the UsageRecord resource that should fire the trigger. Can be: `count`, `usage`, or `price` as described in the UsageRecords documentation.

    The default is `usage`.
    

Returns:


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 57

def create(callback_url: nil, trigger_value: nil, usage_category: nil, callback_method: :unset, friendly_name: :unset, recurring: :unset, trigger_by: :unset)
  data = Twilio::Values.of({
      'CallbackUrl' => callback_url,
      'TriggerValue' => trigger_value,
      'UsageCategory' => usage_category,
      'CallbackMethod' => callback_method,
      'FriendlyName' => friendly_name,
      'Recurring' => recurring,
      'TriggerBy' => trigger_by,
  })

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

  TriggerInstance.new(@version, payload, account_sid: @solution[:account_sid], )
end

#eachObject

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


140
141
142
143
144
145
146
147
148
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 140

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

Parameters:

  • target_url (String)

    API-generated URL for the requested results page

Returns:

  • (Page)

    Page of TriggerInstance


186
187
188
189
190
191
192
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 186

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

#list(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil) ⇒ Array

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

Parameters:

  • recurring (trigger.Recurring) (defaults to: :unset)

    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.

  • trigger_by (trigger.TriggerField) (defaults to: :unset)

    The trigger field of the UsageTriggers to read. Can be: `count`, `usage`, or `price` as described in the UsageRecords documentation.

  • usage_category (trigger.UsageCategory) (defaults to: :unset)

    The usage category of the UsageTriggers to read. Must be a supported usage categories.

  • 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


93
94
95
96
97
98
99
100
101
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 93

def list(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil)
  self.stream(
      recurring: recurring,
      trigger_by: trigger_by,
      usage_category: usage_category,
      limit: limit,
      page_size: page_size
  ).entries
end

#page(recurring: :unset, trigger_by: :unset, usage_category: :unset, page_token: :unset, page_number: :unset, page_size: :unset) ⇒ Page

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

Parameters:

  • recurring (trigger.Recurring) (defaults to: :unset)

    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.

  • trigger_by (trigger.TriggerField) (defaults to: :unset)

    The trigger field of the UsageTriggers to read. Can be: `count`, `usage`, or `price` as described in the UsageRecords documentation.

  • usage_category (trigger.UsageCategory) (defaults to: :unset)

    The usage category of the UsageTriggers to read. Must be a supported usage categories.

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


166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 166

def page(recurring: :unset, trigger_by: :unset, usage_category: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
  params = Twilio::Values.of({
      'Recurring' => recurring,
      'TriggerBy' => trigger_by,
      'UsageCategory' => usage_category,
      'PageToken' => page_token,
      'Page' => page_number,
      'PageSize' => page_size,
  })

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

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

#stream(recurring: :unset, trigger_by: :unset, usage_category: :unset, limit: nil, page_size: nil) ⇒ Enumerable

Streams TriggerInstance records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached.

Parameters:

  • recurring (trigger.Recurring) (defaults to: :unset)

    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.

  • trigger_by (trigger.TriggerField) (defaults to: :unset)

    The trigger field of the UsageTriggers to read. Can be: `count`, `usage`, or `price` as described in the UsageRecords documentation.

  • usage_category (trigger.UsageCategory) (defaults to: :unset)

    The usage category of the UsageTriggers to read. Must be a supported usage categories.

  • 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


123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 123

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

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

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

#to_sObject

Provide a user friendly representation


196
197
198
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 196

def to_s
  '#<Twilio.Api.V2010.TriggerList>'
end