1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30:56 +01:00
phorge-phorge/externals/twilio-php/docs/usage/rest/usage-triggers.rst
Bob Trahan e96c363eef Add SMS support
Summary:
Provides a working SMS implementation with support for Twilio.

This version doesn't really retry if we get any gruff at all. Future versions should retry.

Test Plan: used bin/sms to send messages and look at them.

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: aurelijus, epriestley, Korvin

Maniphest Tasks: T920

Differential Revision: https://secure.phabricator.com/D8930
2014-05-09 12:47:21 -07:00

92 lines
2.6 KiB
ReStructuredText
Executable file

==============
Usage Triggers
==============
Twilio offers a Usage Trigger API so you can get notifications when your Twilio
usage exceeds a given level. Here are some examples of how you can
use PHP to create new usage triggers or modify existing triggers.
Retrieve A Usage Trigger's Properties
=====================================
If you know the Sid of your usage trigger, retrieving it is easy.
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
$usageSid = 'UT123';
$usageTrigger = $client->account->usage_triggers->get($usageSid);
echo $usageTrigger->usage_category;
Update Properties on a UsageTrigger
===================================
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
$usageSid = 'UT123';
$usageTrigger = $client->account->usage_triggers->get($usageSid);
$usageTrigger->update(array(
'FriendlyName' => 'New usage trigger friendly name',
'CallbackUrl' => 'http://example.com/new-trigger-url',
));
Retrieve All Triggers
=====================
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
foreach ($client->account->usage_triggers as $trigger) {
echo "Category: {$trigger->usage_category}\nTriggerValue: {$trigger->trigger_value}\n";
}
Filter Trigger List By Category
===============================
Pass filters to the `getIterator` function to create a filtered list.
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
foreach ($client->account->usage_triggers->getIterator(
0, 50, array(
'UsageCategory' => 'sms',
)) as $trigger
) {
echo "Value: " . $trigger->trigger_value . "\n";
}
Create a New Trigger
====================
Pass a usage category, a value and a callback URL to the `create` method.
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
$trigger = $client->account->usage_triggers->create(
'totalprice',
'250.75',
'http://example.com/usage'
);
Create a Recurring Trigger
==========================
To have your trigger reset once every day, month, or year, pass the
`Recurring` key as part of the params array. A list of optional
trigger parameters can be found in the `Usage Triggers Documentation
<http://www.twilio.com/docs/api/rest/usage-triggers#list-post-optional-paramete
rs>`_.
.. code-block:: php
$client = new Services_Twilio('AC123', '456bef');
$trigger = $client->account->usage_triggers->create(
'totalprice',
'250.75',
'http://example.com/usage',
array('Recurring' => 'monthly', 'TriggerBy' => 'price')
);