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
27
28
# 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:



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

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.



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 135

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



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

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



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

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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 160

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



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 118

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



192
193
194
# File 'lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb', line 192

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