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.



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

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 value at which the trigger will fire. Must be a positive numeric value.

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

    The usage category the trigger watches

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

    The HTTP method Twilio will use when making a request to the CallbackUrl. GET or POST.

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

    A user-specified, human-readable name for the trigger.

  • 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 that fires the trigger. One of ‘count`, `usage`, or `price`

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 48

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.



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

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



174
175
176
177
178
179
180
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 174

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

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

    Only show UsageTriggers that trigger by this field in the UsagRecord

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

    Only show UsageTriggers that watch this usage category

  • 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



85
86
87
88
89
90
91
92
93
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 85

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

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

    Only show UsageTriggers that trigger by this field in the UsagRecord

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

    Only show UsageTriggers that watch this usage category

  • 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



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 152

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

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

    Only show UsageTriggers that trigger by this field in the UsagRecord

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

    Only show UsageTriggers that watch this usage category

  • 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



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 112

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



184
185
186
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 184

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