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

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

Parameters:

  • callback_url (String) (defaults to: nil)

    Twilio will make a request to this url when the trigger fires.

  • trigger_value (String) (defaults to: nil)

    The trigger will fire when usage reaches this value. For convenience, you can use an offset like ‘+30`, which tells Twilio to create the UsageTrigger with its TriggerValue 30 units higher than the current usage. (just be sure to urlencode the `+` as `%2B`).

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

    The trigger will watch this usage category. One of the supported [usage categories](www.twilio.com/docs/api/rest/usage-records#usage-categories).

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

    Twilio will use this HTTP method when making a request to the CallbackUrl. ‘GET` or `POST`. The default is `POST`.

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

    A human readable description of the new trigger. Maximum 64 characters.

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

    How this trigger recurs. Empty for non-recurring triggers. One of ‘daily`, `monthly`, or `yearly` for recurring triggers. A trigger will only fire once during each recurring period. Recurring periods are in GMT.

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

    The field in the [UsageRecord](www.twilio.com/docs/api/rest/usage-records) that will fire the trigger. One of ‘count`, `usage`, or `price` as described in the [UsageRecords documentation](www.twilio.com/docs/api/rest/usage-records#usage-count-price). The default is `usage`.

Returns:



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

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.



145
146
147
148
149
150
151
152
153
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 145

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



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

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)

    Only show UsageTriggers that count over this interval. One of ‘daily`, `monthly`, or `yearly`. To retrieve non-recurring triggers, leave this empty or use `alltime`.

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

    Only show UsageTriggers that trigger by this field in the UsageRecord. Must be one of: ‘count`, `usage`, or `price` as described in the [UsageRecords documentation](www.twilio.com/docs/api/rest/usage-records#usage-count-price).

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

    Only show UsageTriggers that watch this usage category. Must be one of the supported [usage categories](www.twilio.com/docs/api/rest/usage-records#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



97
98
99
100
101
102
103
104
105
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 97

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)

    Only show UsageTriggers that count over this interval. One of ‘daily`, `monthly`, or `yearly`. To retrieve non-recurring triggers, leave this empty or use `alltime`.

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

    Only show UsageTriggers that trigger by this field in the UsageRecord. Must be one of: ‘count`, `usage`, or `price` as described in the [UsageRecords documentation](www.twilio.com/docs/api/rest/usage-records#usage-count-price).

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

    Only show UsageTriggers that watch this usage category. Must be one of the supported [usage categories](www.twilio.com/docs/api/rest/usage-records#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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 172

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
  )
  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)

    Only show UsageTriggers that count over this interval. One of ‘daily`, `monthly`, or `yearly`. To retrieve non-recurring triggers, leave this empty or use `alltime`.

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

    Only show UsageTriggers that trigger by this field in the UsageRecord. Must be one of: ‘count`, `usage`, or `price` as described in the [UsageRecords documentation](www.twilio.com/docs/api/rest/usage-records#usage-count-price).

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

    Only show UsageTriggers that watch this usage category. Must be one of the supported [usage categories](www.twilio.com/docs/api/rest/usage-records#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



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 128

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



204
205
206
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 204

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