[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/twilio-php/docs/usage/rest/ -> usage-records.rst (source)

   1  =============
   2  Usage Records
   3  =============
   4  
   5  Twilio offers a Usage Record API so you can better measure how much you've been
   6  using Twilio. Here are some examples of how you can use PHP to access the usage
   7  API.
   8  
   9  Retrieve All Usage Records
  10  ==========================
  11  
  12  .. code-block:: php
  13  
  14      $client = new Services_Twilio('AC123', '456bef');
  15      foreach ($client->account->usage_records as $record) {
  16          echo "Record: $record";
  17      }
  18  
  19  Retrieve Usage Records For A Time Interval
  20  ==========================================
  21  
  22  UsageRecords support `several convenience subresources
  23  <http://www.twilio.com/docs/api/rest/usage-records#list-subresources>`_ that
  24  can be accessed as properties on the `record` object.
  25  
  26  .. code-block:: php
  27  
  28      $client = new Services_Twilio('AC123', '456bef');
  29      foreach ($client->account->usage_records->last_month as $record) {
  30          echo "Record: $record";
  31      }
  32  
  33  Retrieve All Time Usage for A Usage Category
  34  ============================================
  35  
  36  By default, Twilio will return your all-time usage for a given usage category.
  37  
  38  .. code-block:: php
  39  
  40      $client = new Services_Twilio('AC123', '456bef');
  41      $callRecord = $client->account->usage_records->getCategory('calls');
  42      echo $callRecord->usage;
  43  
  44  Retrieve All Usage for a Given Time Period
  45  ==========================================
  46  
  47  You can filter your UsageRecord list by providing `StartDate` and `EndDate`
  48  parameters.
  49  
  50  .. code-block:: php
  51  
  52      $client = new Services_Twilio('AC123', '456bef');
  53      foreach ($client->account->usage_records->getIterator(0, 50, array(
  54          'StartDate' => '2012-08-01',
  55          'EndDate'   => '2012-08-31',
  56      )) as $record) {
  57          echo $record->description . "\n";
  58          echo $record->usage . "\n";
  59      }
  60  
  61  Retrieve Today's SMS Usage
  62  ==========================
  63  
  64  You can use the `today` record subresource, and then retrieve the record
  65  directly with the `getCategory` function.
  66  
  67  .. code-block:: php
  68  
  69      $client = new Services_Twilio('AC123', '456bef');
  70      // You can substitute 'yesterday', 'all_time' for 'today' below
  71      $smsRecord = $client->account->usage_records->today->getCategory('sms');
  72      echo $smsRecord->usage;
  73  
  74  Retrieve Daily Usage Over a One-Month Period
  75  =============================================
  76  
  77  The code below will retrieve daily summaries of recordings usage for August
  78  2012. To retrieve all categories of usage, remove the 'Category' filter from
  79  the `getIterator` array.
  80  
  81  .. code-block:: php
  82  
  83      $client = new Services_Twilio('AC123', '456bef');
  84      foreach ($client->account->usage_records->daily->getIterator(0, 50, array(
  85          'StartDate' => '2012-08-01',
  86          'EndDate'   => '2012-08-31',
  87          'Category'  => 'recordings',
  88      )) as $record) {
  89          echo $record->usage;
  90      }
  91  


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1