Skip to content
Browse files

...

  • Loading branch information...
1 parent 63381db commit 3f6135e2d7b920a507e9cdb8dec3aa3bd27eee7f @maca134 committed
View
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
View
163 .gitignore
@@ -0,0 +1,163 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
View
36 LICENSE 100755 → 100644
@@ -1,19 +1,19 @@
-Copyright (C) <2012> by <Matthew McConnell>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+Copyright (C) <2012> by <Matthew McConnell>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
View
266 README.md 100755 → 100644
@@ -1,134 +1,134 @@
-Twilio
-======
-
-Twilio is a package to allow interaction with the [Twilio](https://www.twilio.com) service.
-
-Installation
-------------
-
-1. Clone (`git clone git://github.com/maca134/fuelphp-twilio`) / [download](https://github.com/maca134/fuelphp-twilio/zipball/master)
-2. Copy to fuel/packages/
-4. Copy fuel/packages/twilio/config/twilio.php to fuel/app/config/
-5. Add your Twilio credentials and defaults for each twiml element.
-
-# Introduction
-
-## Rest API
-
-This package will allow you to send requests to Twilio:
-
-- [Accounts](https://www.twilio.com/docs/api/rest/account)
-- [MakeCall](https://www.twilio.com/docs/api/rest/making-calls)
-- [Recordings](https://www.twilio.com/docs/api/rest/recording)
-- [SmsMessage](https://www.twilio.com/docs/api/rest/sending-sms)
-- [Transcriptions](https://www.twilio.com/docs/api/rest/transcription)
-
-## [TwiML](https://www.twilio.com/docs/api/twiml): Twilio Markup Language
-
-It also includes an object based implementation of Twilio's [TwiML](https://www.twilio.com/docs/api/twiml).
-
-Here are the TwiML elements:
-
-* [Say](https://www.twilio.com/docs/api/2010-04-01/twiml/say)
-* [Play](https://www.twilio.com/docs/api/2010-04-01/twiml/play)
-* [Gather](https://www.twilio.com/docs/api/2010-04-01/twiml/gather)
- * [Say](https://www.twilio.com/docs/api/2010-04-01/twiml/say)
- * [Play](https://www.twilio.com/docs/api/2010-04-01/twiml/play)
- * [Pause](https://www.twilio.com/docs/api/2010-04-01/twiml/pause)
-* [Record](https://www.twilio.com/docs/api/2010-04-01/twiml/record)
-* [Sms](https://www.twilio.com/docs/api/2010-04-01/twiml/sms)
-* [Dial](https://www.twilio.com/docs/api/2010-04-01/twiml/dial)
- * [Number](https://www.twilio.com/docs/api/2010-04-01/twiml/number)
- * [Client](https://www.twilio.com/docs/api/2010-04-01/twiml/client)
- * [Conference](https://www.twilio.com/docs/api/2010-04-01/twiml/conference)
-* [Hangup](https://www.twilio.com/docs/api/2010-04-01/twiml/hangup)
-* [Redirect](https://www.twilio.com/docs/api/2010-04-01/twiml/redirect)
-* [Reject](https://www.twilio.com/docs/api/2010-04-01/twiml/reject)
-* [Pause](https://www.twilio.com/docs/api/2010-04-01/twiml/pause)
-
-# Configuration
-
-Copy config/twilio.php to app/config/twilio.php and change whatever setting in need of changing.
-
-# Rest API Examples
-
-## Make a call
-
- $call = Twilio\Twilio::request('MakeCall');
- $response = $call->create(array(
- 'To' => '+4412345678901',
- 'From' => '+4416789012345',
- 'Url' => Uri::create('welcome/call')
- ));
-
-## Send an SMS message
-
- $sms = Twilio\Twilio::request('SmsMessage');
- $response = $sms->create(array(
- 'To' => '+4412345678901',
- 'From' => '+4416789012345',
- 'Body' => 'SMS content'
- ));
-
-# TwiML Examples
-
-## Simple Example
-
- $twiml = Twilio\Twilio::twiml();
- $twiml->say('Hello World!')->pause('', array('length' => '5'));
- $twiml->render();
-
-Will render:
-
- <?xml version="1.0" encoding="UTF-8" ?>
- <Response>
- <Say voice="man" language="en" loop="1">Hello World!</Say>
- <Pause length="5" />
- </Gather>
- </Response>
-
-## Grabbing key presses during a call
-
- $question = Twilio\Twilio::twiml();
- $question->say('Please press 1 or 2')->pause()->play('http://some.place.com/music.mp3');
-
- $twiml = Twilio\Twilio::twiml();
- $twiml->pause()->gather($question, array(
- 'action' => Uri::create('twilio/next_action'),
- 'numDigits' => '1'
- )
- );
- $response = $twiml->render();
-
-## Sending an SMS message
-
- $twiml = Twilio\Twilio::twiml();
- $twiml->sms($message, array('from' => '+441234567890'));
-
-# Notes
-
-Only the TwiML elements Gather and Dial have nested objects.
-
-Gather can have the following nested variables:
-
-- Say
-- Play
-- Pause
-
-Dial can have:
-
-- A string, telephone number
-- Number
-- Client
-- Conference
-
-# Get In Touch
-
-You can get in touch either through GitHub or you can email me at [maca134@googlemail.com](mailto:maca134@googlemail.com).
-
-Checkout my site at [http://maca134.co.uk](maca134.co.uk)
-
-# Thanks
-
- - [Twilio](https://www.twilio.com)
+Twilio
+======
+
+Twilio is a package to allow interaction with the [Twilio](https://www.twilio.com) service.
+
+Installation
+------------
+
+1. Clone (`git clone git://github.com/maca134/fuelphp-twilio`) / [download](https://github.com/maca134/fuelphp-twilio/zipball/master)
+2. Copy to fuel/packages/
+4. Copy fuel/packages/twilio/config/twilio.php to fuel/app/config/
+5. Add your Twilio credentials and defaults for each twiml element.
+
+# Introduction
+
+## Rest API
+
+This package will allow you to send requests to Twilio:
+
+- [Accounts](https://www.twilio.com/docs/api/rest/account)
+- [MakeCall](https://www.twilio.com/docs/api/rest/making-calls)
+- [Recordings](https://www.twilio.com/docs/api/rest/recording)
+- [SmsMessage](https://www.twilio.com/docs/api/rest/sending-sms)
+- [Transcriptions](https://www.twilio.com/docs/api/rest/transcription)
+
+## [TwiML](https://www.twilio.com/docs/api/twiml): Twilio Markup Language
+
+It also includes an object based implementation of Twilio's [TwiML](https://www.twilio.com/docs/api/twiml).
+
+Here are the TwiML elements:
+
+* [Say](https://www.twilio.com/docs/api/2010-04-01/twiml/say)
+* [Play](https://www.twilio.com/docs/api/2010-04-01/twiml/play)
+* [Gather](https://www.twilio.com/docs/api/2010-04-01/twiml/gather)
+ * [Say](https://www.twilio.com/docs/api/2010-04-01/twiml/say)
+ * [Play](https://www.twilio.com/docs/api/2010-04-01/twiml/play)
+ * [Pause](https://www.twilio.com/docs/api/2010-04-01/twiml/pause)
+* [Record](https://www.twilio.com/docs/api/2010-04-01/twiml/record)
+* [Sms](https://www.twilio.com/docs/api/2010-04-01/twiml/sms)
+* [Dial](https://www.twilio.com/docs/api/2010-04-01/twiml/dial)
+ * [Number](https://www.twilio.com/docs/api/2010-04-01/twiml/number)
+ * [Client](https://www.twilio.com/docs/api/2010-04-01/twiml/client)
+ * [Conference](https://www.twilio.com/docs/api/2010-04-01/twiml/conference)
+* [Hangup](https://www.twilio.com/docs/api/2010-04-01/twiml/hangup)
+* [Redirect](https://www.twilio.com/docs/api/2010-04-01/twiml/redirect)
+* [Reject](https://www.twilio.com/docs/api/2010-04-01/twiml/reject)
+* [Pause](https://www.twilio.com/docs/api/2010-04-01/twiml/pause)
+
+# Configuration
+
+Copy config/twilio.php to app/config/twilio.php and change whatever setting in need of changing.
+
+# Rest API Examples
+
+## Make a call
+
+ $call = Twilio\Twilio::request('MakeCall');
+ $response = $call->create(array(
+ 'To' => '+4412345678901',
+ 'From' => '+4416789012345',
+ 'Url' => Uri::create('welcome/call')
+ ));
+
+## Send an SMS message
+
+ $sms = Twilio\Twilio::request('SmsMessage');
+ $response = $sms->create(array(
+ 'To' => '+4412345678901',
+ 'From' => '+4416789012345',
+ 'Body' => 'SMS content'
+ ));
+
+# TwiML Examples
+
+## Simple Example
+
+ $twiml = Twilio\Twilio::twiml();
+ $twiml->say('Hello World!')->pause('', array('length' => '5'));
+ $twiml->render();
+
+Will render:
+
+ <?xml version="1.0" encoding="UTF-8" ?>
+ <Response>
+ <Say voice="man" language="en" loop="1">Hello World!</Say>
+ <Pause length="5" />
+ </Gather>
+ </Response>
+
+## Grabbing key presses during a call
+
+ $question = Twilio\Twilio::twiml();
+ $question->say('Please press 1 or 2')->pause()->play('http://some.place.com/music.mp3');
+
+ $twiml = Twilio\Twilio::twiml();
+ $twiml->pause()->gather($question, array(
+ 'action' => Uri::create('twilio/next_action'),
+ 'numDigits' => '1'
+ )
+ );
+ $response = $twiml->render();
+
+## Sending an SMS message
+
+ $twiml = Twilio\Twilio::twiml();
+ $twiml->sms($message, array('from' => '+441234567890'));
+
+# Notes
+
+Only the TwiML elements Gather and Dial have nested objects.
+
+Gather can have the following nested variables:
+
+- Say
+- Play
+- Pause
+
+Dial can have:
+
+- A string, telephone number
+- Number
+- Client
+- Conference
+
+# Get In Touch
+
+You can get in touch either through GitHub or you can email me at [maca134@googlemail.com](mailto:maca134@googlemail.com).
+
+Checkout my site at [http://maca134.co.uk](maca134.co.uk)
+
+# Thanks
+
+ - [Twilio](https://www.twilio.com)
- [TinyHttp](https://gist.github.com/618157)
View
82 bootstrap.php 100755 → 100644
@@ -1,41 +1,41 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-Autoloader::add_core_namespace('Twilio');
-
-Autoloader::add_classes(array(
- 'Twilio\\Twilio' => __DIR__ . '/classes/twilio.php',
- 'Twilio\\Twilio_Twiml' => __DIR__ . '/classes/twilio/twiml.php',
- 'Twilio\\Twilio_Twiml_Gather' => __DIR__ . '/classes/twilio/twiml/gather.php',
- 'Twilio\\Twilio_Twiml_Hangup' => __DIR__ . '/classes/twilio/twiml/hangup.php',
- 'Twilio\\Twilio_Twiml_Pause' => __DIR__ . '/classes/twilio/twiml/pause.php',
- 'Twilio\\Twilio_Twiml_Play' => __DIR__ . '/classes/twilio/twiml/play.php',
- 'Twilio\\Twilio_Twiml_Record' => __DIR__ . '/classes/twilio/twiml/record.php',
- 'Twilio\\Twilio_Twiml_Redirect' => __DIR__ . '/classes/twilio/twiml/redirect.php',
- 'Twilio\\Twilio_Twiml_Reject' => __DIR__ . '/classes/twilio/twiml/reject.php',
- 'Twilio\\Twilio_Twiml_Say' => __DIR__ . '/classes/twilio/twiml/say.php',
- 'Twilio\\Twilio_Twiml_Sms' => __DIR__ . '/classes/twilio/twiml/sms.php',
- 'Twilio\\Twilio_Twiml_Verb' => __DIR__ . '/classes/twilio/twiml/verb.php',
- 'Twilio\\Twilio_Twiml_Dial' => __DIR__ . '/classes/twilio/twiml/dial.php',
- 'Twilio\\Twilio_Twiml_Client' => __DIR__ . '/classes/twilio/twiml/client.php',
- 'Twilio\\Twilio_Twiml_Conference' => __DIR__ . '/classes/twilio/twiml/conference.php',
- 'Twilio\\Twilio_Twiml_Number' => __DIR__ . '/classes/twilio/twiml/number.php',
- 'Twilio\\Twilio_Twiml_Nest' => __DIR__ . '/classes/twilio/twiml/nest.php',
- 'Twilio\\Twilio_Request' => __DIR__ . '/classes/twilio/request.php',
- 'Twilio\\Twilio_Request_TinyHttp' => __DIR__ . '/classes/twilio/request/tinyhttp.php',
- 'Twilio\\Twilio_Request_Base' => __DIR__ . '/classes/twilio/request/base.php',
- 'Twilio\\Twilio_Request_SmsMessage' => __DIR__ . '/classes/twilio/request/smsmessage.php',
- 'Twilio\\Twilio_Request_MakeCall' => __DIR__ . '/classes/twilio/request/makecall.php',
- 'Twilio\\Twilio_Request_Accounts' => __DIR__ . '/classes/twilio/request/accounts.php',
- 'Twilio\\Twilio_Request_Recordings' => __DIR__ . '/classes/twilio/request/recordings.php',
- 'Twilio\\Twilio_Request_Transcriptions' => __DIR__ . '/classes/twilio/request/transcriptions.php',
-));
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+Autoloader::add_core_namespace('Twilio');
+
+Autoloader::add_classes(array(
+ 'Twilio\\Twilio' => __DIR__ . '/classes/twilio.php',
+ 'Twilio\\Twilio_Twiml' => __DIR__ . '/classes/twilio/twiml.php',
+ 'Twilio\\Twilio_Twiml_Gather' => __DIR__ . '/classes/twilio/twiml/gather.php',
+ 'Twilio\\Twilio_Twiml_Hangup' => __DIR__ . '/classes/twilio/twiml/hangup.php',
+ 'Twilio\\Twilio_Twiml_Pause' => __DIR__ . '/classes/twilio/twiml/pause.php',
+ 'Twilio\\Twilio_Twiml_Play' => __DIR__ . '/classes/twilio/twiml/play.php',
+ 'Twilio\\Twilio_Twiml_Record' => __DIR__ . '/classes/twilio/twiml/record.php',
+ 'Twilio\\Twilio_Twiml_Redirect' => __DIR__ . '/classes/twilio/twiml/redirect.php',
+ 'Twilio\\Twilio_Twiml_Reject' => __DIR__ . '/classes/twilio/twiml/reject.php',
+ 'Twilio\\Twilio_Twiml_Say' => __DIR__ . '/classes/twilio/twiml/say.php',
+ 'Twilio\\Twilio_Twiml_Sms' => __DIR__ . '/classes/twilio/twiml/sms.php',
+ 'Twilio\\Twilio_Twiml_Verb' => __DIR__ . '/classes/twilio/twiml/verb.php',
+ 'Twilio\\Twilio_Twiml_Dial' => __DIR__ . '/classes/twilio/twiml/dial.php',
+ 'Twilio\\Twilio_Twiml_Client' => __DIR__ . '/classes/twilio/twiml/client.php',
+ 'Twilio\\Twilio_Twiml_Conference' => __DIR__ . '/classes/twilio/twiml/conference.php',
+ 'Twilio\\Twilio_Twiml_Number' => __DIR__ . '/classes/twilio/twiml/number.php',
+ 'Twilio\\Twilio_Twiml_Nest' => __DIR__ . '/classes/twilio/twiml/nest.php',
+ 'Twilio\\Twilio_Request' => __DIR__ . '/classes/twilio/request.php',
+ 'Twilio\\Twilio_Request_TinyHttp' => __DIR__ . '/classes/twilio/request/tinyhttp.php',
+ 'Twilio\\Twilio_Request_Base' => __DIR__ . '/classes/twilio/request/base.php',
+ 'Twilio\\Twilio_Request_SmsMessage' => __DIR__ . '/classes/twilio/request/smsmessage.php',
+ 'Twilio\\Twilio_Request_MakeCall' => __DIR__ . '/classes/twilio/request/makecall.php',
+ 'Twilio\\Twilio_Request_Accounts' => __DIR__ . '/classes/twilio/request/accounts.php',
+ 'Twilio\\Twilio_Request_Recordings' => __DIR__ . '/classes/twilio/request/recordings.php',
+ 'Twilio\\Twilio_Request_Transcriptions' => __DIR__ . '/classes/twilio/request/transcriptions.php',
+));
View
0 classes/twilio.php 100755 → 100644
File mode changed.
View
270 classes/twilio/request.php 100755 → 100644
@@ -1,135 +1,135 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-/**
- * Exception for Twilio_Request
- */
-class Twilio_Request_Exception extends \FuelException {}
-
-abstract class Twilio_Request {
-
- /**
- * @var string Request user agent
- */
- private $useragent = 'fuel-twilio/0.1';
-
- /**
- * @var string Twilio api url
- */
- private $url = 'https://api.twilio.com';
-
- /**
- * @var string SSL certificate filename
- */
- private $cainfo = 'twilio_ssl_certificate.crt';
-
- /**
- * @var array Request headers
- */
- private $headers = array('Accept-Charset: utf-8');
-
- /**
- * @var Twilio_Request_TinyHttp TinyHTTP object
- */
- private $_http;
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array();
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '';
-
- /**
- * Returns a new Twilio_Request object
- *
- * @return Twilio_Request
- */
- public static function forge() {
- return new static();
- }
-
- /**
- * Twilio_Request constructor
- *
- * @throws Twilio_Request_Exception
- */
- public function __construct() {
- $this->cainfo = realpath(dirname(__FILE__) . '/../' . $this->cainfo);
-
- if (!in_array('curl', get_loaded_extensions())) {
- throw new Twilio_Request_Exception("It looks like you do not have curl installed.\n" .
- "Curl is required to make HTTP requests using the twilio-php\n" .
- "library. For install instructions, visit the following page:\n" .
- "http://php.net/manual/en/curl.installation.php"
- );
- }
- $this->_http = new Twilio_Request_TinyHttp(
- $this->url,
- array("curlopts" => array(
- CURLOPT_USERAGENT => $this->useragent,
- CURLOPT_HTTPHEADER => $this->headers,
- CURLOPT_CAINFO => $this->cainfo,
- ))
- );
- \Config::load('twilio', true);
- $this->_http->authenticate(\Config::get('twilio.account_sid'), \Config::get('twilio.auth_token'));
- }
-
- /**
- * Sends the Twilio request
- *
- * @param string $res
- * @param string $body
- * @param string $method
- * @return stdClass An json_decoded object of the response
- * @throws Twilio_Request_Exception
- */
- protected function send($res, $body = '', $method = 'POST') {
- $method = strtolower($method);
- if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
- throw new Twilio_Request_Exception('Invalid http method');
- }
- if ($method == 'get') {
- $res .= (!empty($body)) ? '?' . $body : '';
- $body = '';
- }
- $response = $this->_http->$method($res, array(), $body);
- return json_decode($response[2]);
- }
-
- /**
- * Creates and returns a http query string
- *
- * @param array $attr An associative array of attributes
- * @return string A http query string
- */
- protected function create_post($attr = array()) {
- $post = array();
-
- foreach ($this->defaults as $k => $v) {
- if (isset($attr[$k]))
- $v = $attr[$k];
- if ($v !== false) {
- $post[$k] = $v;
- }
- }
- return http_build_query($attr);
- }
-
-}
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+/**
+ * Exception for Twilio_Request
+ */
+class Twilio_Request_Exception extends \FuelException {}
+
+abstract class Twilio_Request {
+
+ /**
+ * @var string Request user agent
+ */
+ private $useragent = 'fuel-twilio/0.1';
+
+ /**
+ * @var string Twilio api url
+ */
+ private $url = 'https://api.twilio.com';
+
+ /**
+ * @var string SSL certificate filename
+ */
+ private $cainfo = 'twilio_ssl_certificate.crt';
+
+ /**
+ * @var array Request headers
+ */
+ private $headers = array('Accept-Charset: utf-8');
+
+ /**
+ * @var Twilio_Request_TinyHttp TinyHTTP object
+ */
+ private $_http;
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array();
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '';
+
+ /**
+ * Returns a new Twilio_Request object
+ *
+ * @return Twilio_Request
+ */
+ public static function forge() {
+ return new static();
+ }
+
+ /**
+ * Twilio_Request constructor
+ *
+ * @throws Twilio_Request_Exception
+ */
+ public function __construct() {
+ $this->cainfo = realpath(dirname(__FILE__) . '/../' . $this->cainfo);
+
+ if (!in_array('curl', get_loaded_extensions())) {
+ throw new Twilio_Request_Exception("It looks like you do not have curl installed.\n" .
+ "Curl is required to make HTTP requests using the twilio-php\n" .
+ "library. For install instructions, visit the following page:\n" .
+ "http://php.net/manual/en/curl.installation.php"
+ );
+ }
+ $this->_http = new Twilio_Request_TinyHttp(
+ $this->url,
+ array("curlopts" => array(
+ CURLOPT_USERAGENT => $this->useragent,
+ CURLOPT_HTTPHEADER => $this->headers,
+ CURLOPT_CAINFO => $this->cainfo,
+ ))
+ );
+ \Config::load('twilio', true);
+ $this->_http->authenticate(\Config::get('twilio.account_sid'), \Config::get('twilio.auth_token'));
+ }
+
+ /**
+ * Sends the Twilio request
+ *
+ * @param string $res
+ * @param string $body
+ * @param string $method
+ * @return stdClass An json_decoded object of the response
+ * @throws Twilio_Request_Exception
+ */
+ protected function send($res, $body = '', $method = 'POST') {
+ $method = strtolower($method);
+ if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
+ throw new Twilio_Request_Exception('Invalid http method');
+ }
+ if ($method == 'get') {
+ $res .= (!empty($body)) ? '?' . $body : '';
+ $body = '';
+ }
+ $response = $this->_http->$method($res, array(), $body);
+ return json_decode($response[2]);
+ }
+
+ /**
+ * Creates and returns a http query string
+ *
+ * @param array $attr An associative array of attributes
+ * @return string A http query string
+ */
+ protected function create_post($attr = array()) {
+ $post = array();
+
+ foreach ($this->defaults as $k => $v) {
+ if (isset($attr[$k]))
+ $v = $attr[$k];
+ if ($v !== false) {
+ $post[$k] = $v;
+ }
+ }
+ return http_build_query($attr);
+ }
+
+}
View
76 classes/twilio/request/accounts.php 100755 → 100644
@@ -1,39 +1,39 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Request_Accounts extends Twilio_Request implements Twilio_Request_Base {
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array();
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '/2010-04-01/Accounts/%s.json';
-
- /**
- * Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return type
- */
- public function create($attr = array()) {
- $res = sprintf($this->res, \Config::get('twilio.account_sid'));
- return $this->send($res, '', 'GET');
- }
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Request_Accounts extends Twilio_Request implements Twilio_Request_Base {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array();
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '/2010-04-01/Accounts/%s.json';
+
+ /**
+ * Executes the request, returning the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return type
+ */
+ public function create($attr = array()) {
+ $res = sprintf($this->res, \Config::get('twilio.account_sid'));
+ return $this->send($res, '', 'GET');
+ }
+
}
View
36 classes/twilio/request/base.php 100755 → 100644
@@ -1,19 +1,19 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-interface Twilio_Request_Base {
-
- public function create($attr);
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+interface Twilio_Request_Base {
+
+ public function create($attr);
}
View
106 classes/twilio/request/makecall.php 100755 → 100644
@@ -1,54 +1,54 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Request_MakeCall extends Twilio_Request implements Twilio_Request_Base {
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array(
- 'From' => '',
- 'To' => '',
- 'Url' => '',
- 'ApplicationSid' => false,
- 'Method' => 'POST',
- 'FallbackUrl' => false,
- 'FallbackMethod' => false,
- 'StatusCallback' => false,
- 'StatusCallbackMethod' => false,
- 'SendDigits' => false,
- 'IfMachine' => false,
- 'Timeout' => false,
- 'Record' => false,
- );
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '/2010-04-01/Accounts/%s/Calls.json';
-
- /**
- * Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
- */
- public function create($attr = array()) {
- $res = sprintf($this->res, \Config::get('twilio.account_sid'));
- $body = $this->create_post($attr);
- return $this->send($res, $body);
- }
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Request_MakeCall extends Twilio_Request implements Twilio_Request_Base {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array(
+ 'From' => '',
+ 'To' => '',
+ 'Url' => '',
+ 'ApplicationSid' => false,
+ 'Method' => 'POST',
+ 'FallbackUrl' => false,
+ 'FallbackMethod' => false,
+ 'StatusCallback' => false,
+ 'StatusCallbackMethod' => false,
+ 'SendDigits' => false,
+ 'IfMachine' => false,
+ 'Timeout' => false,
+ 'Record' => false,
+ );
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '/2010-04-01/Accounts/%s/Calls.json';
+
+ /**
+ * Executes the request, returning the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
+ */
+ public function create($attr = array()) {
+ $res = sprintf($this->res, \Config::get('twilio.account_sid'));
+ $body = $this->create_post($attr);
+ return $this->send($res, $body);
+ }
+
}
View
148 classes/twilio/request/recordings.php 100755 → 100644
@@ -1,75 +1,75 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Request_Recordings extends Twilio_Request implements Twilio_Request_Base {
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array(
- 'Sid' => false,
- 'CallSid' => false,
- 'DateCreated' => false,
- 'Page' => false,
- 'PageSize' => 50
- );
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '/2010-04-01/Accounts/%s/Recordings%s.json';
-
- /**
- * Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
- */
- public function create($attr = array()) {
- $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
-
- $accoundsid = \Config::get('twilio.account_sid');
- $accoundsid .= (!empty($attr['CallSid'])) ? '/Calls/' . $attr['CallSid'] : '';
-
- $res = sprintf($this->res, $accoundsid, $sid, '');
- $type = (empty($attr['Sid'])) ? 'list' : 'single';
-
- unset($attr['Sid'], $attr['CallSid']);
-
- $body = $this->create_post($attr);
- $response = $this->send($res, $body, 'GET');
-
- if ($type == 'list' && count($response->recordings)) {
- foreach ($response->recordings as $i => $recording) {
- $response->recordings[$i]->file = str_replace('.json', '.mp3', $recording->uri);
- }
- } else {
- $response->file = str_replace('.json', '.mp3', $response->uri);
- }
- return $response;
- }
-
- /**
- * Executes the request, deleting the recording
- *
- * @param string $sid
- * @return stdClass An json_decoded object of the response
- */
- public function delete($sid) {
- $res = sprintf($this->res, \Config::get('twilio.account_sid'), '/' . $sid, '');
- return $this->send($res, '', 'DELETE');
- }
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Request_Recordings extends Twilio_Request implements Twilio_Request_Base {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array(
+ 'Sid' => false,
+ 'CallSid' => false,
+ 'DateCreated' => false,
+ 'Page' => false,
+ 'PageSize' => 50
+ );
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '/2010-04-01/Accounts/%s/Recordings%s.json';
+
+ /**
+ * Executes the request, returning the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
+ */
+ public function create($attr = array()) {
+ $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
+
+ $accoundsid = \Config::get('twilio.account_sid');
+ $accoundsid .= (!empty($attr['CallSid'])) ? '/Calls/' . $attr['CallSid'] : '';
+
+ $res = sprintf($this->res, $accoundsid, $sid, '');
+ $type = (empty($attr['Sid'])) ? 'list' : 'single';
+
+ unset($attr['Sid'], $attr['CallSid']);
+
+ $body = $this->create_post($attr);
+ $response = $this->send($res, $body, 'GET');
+
+ if ($type == 'list' && count($response->recordings)) {
+ foreach ($response->recordings as $i => $recording) {
+ $response->recordings[$i]->file = str_replace('.json', '.mp3', $recording->uri);
+ }
+ } else {
+ $response->file = str_replace('.json', '.mp3', $response->uri);
+ }
+ return $response;
+ }
+
+ /**
+ * Executes the request, deleting the recording
+ *
+ * @param string $sid
+ * @return stdClass An json_decoded object of the response
+ */
+ public function delete($sid) {
+ $res = sprintf($this->res, \Config::get('twilio.account_sid'), '/' . $sid, '');
+ return $this->send($res, '', 'DELETE');
+ }
+
}
View
102 classes/twilio/request/smsmessage.php 100755 → 100644
@@ -1,52 +1,52 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Request_SmsMessage extends Twilio_Request implements Twilio_Request_Base {
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array(
- 'From' => '',
- 'To' => '',
- 'Body' => '',
- 'StatusCallback' => false,
- 'ApplicationSid' => false,
- 'Sid' => false,
- );
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '/2010-04-01/Accounts/%s/SMS/Messages%s.json';
-
- /**
- * Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
- */
- public function create($attr = array()) {
- $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
-
- $res = sprintf($this->res, \Config::get('twilio.account_sid'), $sid);
-
- unset($attr['Sid']);
-
- $body = $this->create_post($attr);
- return $this->send($res, $body);
- }
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Request_SmsMessage extends Twilio_Request implements Twilio_Request_Base {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array(
+ 'From' => '',
+ 'To' => '',
+ 'Body' => '',
+ 'StatusCallback' => false,
+ 'ApplicationSid' => false,
+ 'Sid' => false,
+ );
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '/2010-04-01/Accounts/%s/SMS/Messages%s.json';
+
+ /**
+ * Executes the request, returning the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
+ */
+ public function create($attr = array()) {
+ $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
+
+ $res = sprintf($this->res, \Config::get('twilio.account_sid'), $sid);
+
+ unset($attr['Sid']);
+
+ $body = $this->create_post($attr);
+ return $this->send($res, $body);
+ }
+
}
View
212 classes/twilio/request/tinyhttp.php 100755 → 100644
@@ -1,107 +1,107 @@
-<?php
-
-/**
- * Based on TinyHttp.
- *
- * @package Twilio
- * @version 1
- * @author Neuman Vong
- * @license BSD License
- * @copyright Copyright 2011, Neuman Vong
- * @link https://gist.github.com/618157
- */
-
-namespace Twilio;
-
-class Twilio_Request_TinyHttpException extends \FuelException {}
-
-class Twilio_Request_TinyHttp {
- private $user, $pass, $scheme, $host, $port, $debug, $curlopts;
-
- public function __construct($uri = '', $kwargs = array()) {
- foreach (parse_url($uri) as $name => $value) $this->$name = $value;
- $this->debug = isset($kwargs['debug']) ? !!$kwargs['debug'] : NULL;
- $this->curlopts = isset($kwargs['curlopts']) ? $kwargs['curlopts'] : array();
- }
-
- public function __call($name, $args) {
- list($res, $req_headers, $req_body) = $args + array(0, array(), '');
-
- $opts = $this->curlopts + array(
- CURLOPT_URL => "$this->scheme://$this->host$res",
- CURLOPT_HEADER => TRUE,
- CURLOPT_RETURNTRANSFER => TRUE,
- CURLOPT_INFILESIZE => -1,
- CURLOPT_POSTFIELDS => NULL,
- CURLOPT_TIMEOUT => 60,
- );
-
- foreach ($req_headers as $k => $v) $opts[CURLOPT_HTTPHEADER][] = "$k: $v";
- if ($this->port) $opts[CURLOPT_PORT] = $this->port;
- if ($this->debug) $opts[CURLINFO_HEADER_OUT] = TRUE;
- if ($this->user && $this->pass) $opts[CURLOPT_USERPWD] = "$this->user:$this->pass";
- switch ($name) {
- case 'get':
- $opts[CURLOPT_HTTPGET] = TRUE;
- break;
- case 'post':
- $opts[CURLOPT_POST] = TRUE;
- $opts[CURLOPT_POSTFIELDS] = $req_body;
- break;
- case 'put':
- $opts[CURLOPT_PUT] = TRUE;
- if (strlen($req_body)) {
- if ($buf = fopen('php://memory', 'w+')) {
- fwrite($buf, $req_body);
- fseek($buf, 0);
- $opts[CURLOPT_INFILE] = $buf;
- $opts[CURLOPT_INFILESIZE] = strlen($req_body);
- } else throw new Twilio_TinyHttpException('unable to open temporary file');
- }
- break;
- case 'head':
- $opts[CURLOPT_NOBODY] = TRUE;
- break;
- default:
- $opts[CURLOPT_CUSTOMREQUEST] = strtoupper($name);
- break;
- }
- try {
- if ($curl = curl_init()) {
- if (curl_setopt_array($curl, $opts)) {
- if ($response = curl_exec($curl)) {
- $parts = explode("\r\n\r\n", $response, 3);
- list($head, $body) = ($parts[0] == 'HTTP/1.1 100 Continue')
- ? array($parts[1], $parts[2])
- : array($parts[0], $parts[1]);
- $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if ($this->debug) {
- error_log(
- curl_getinfo($curl, CURLINFO_HEADER_OUT) .
- $req_body
- );
- }
- $header_lines = explode("\r\n", $head);
- array_shift($header_lines);
- foreach ($header_lines as $line) {
- list($key, $value) = explode(":", $line, 2);
- $headers[$key] = trim($value);
- }
- curl_close($curl);
- if (isset($buf) && is_resource($buf)) fclose($buf);
- return array($status, $headers, $body);
- } else throw new Twilio_TinyHttpException(curl_error($curl));
- } else throw new Twilio_TinyHttpException(curl_error($curl));
- } else throw new Twilio_TinyHttpException('unable to initialize cURL');
- } catch (ErrorException $e) {
- if (is_resource($curl)) curl_close($curl);
- if (isset($buf) && is_resource($buf)) fclose($buf);
- throw $e;
- }
- }
-
- public function authenticate($user, $pass) {
- $this->user = $user;
- $this->pass = $pass;
- }
+<?php
+
+/**
+ * Based on TinyHttp.
+ *
+ * @package Twilio
+ * @version 1
+ * @author Neuman Vong
+ * @license BSD License
+ * @copyright Copyright 2011, Neuman Vong
+ * @link https://gist.github.com/618157
+ */
+
+namespace Twilio;
+
+class Twilio_Request_TinyHttpException extends \FuelException {}
+
+class Twilio_Request_TinyHttp {
+ private $user, $pass, $scheme, $host, $port, $debug, $curlopts;
+
+ public function __construct($uri = '', $kwargs = array()) {
+ foreach (parse_url($uri) as $name => $value) $this->$name = $value;
+ $this->debug = isset($kwargs['debug']) ? !!$kwargs['debug'] : NULL;
+ $this->curlopts = isset($kwargs['curlopts']) ? $kwargs['curlopts'] : array();
+ }
+
+ public function __call($name, $args) {
+ list($res, $req_headers, $req_body) = $args + array(0, array(), '');
+
+ $opts = $this->curlopts + array(
+ CURLOPT_URL => "$this->scheme://$this->host$res",
+ CURLOPT_HEADER => TRUE,
+ CURLOPT_RETURNTRANSFER => TRUE,
+ CURLOPT_INFILESIZE => -1,
+ CURLOPT_POSTFIELDS => NULL,
+ CURLOPT_TIMEOUT => 60,
+ );
+
+ foreach ($req_headers as $k => $v) $opts[CURLOPT_HTTPHEADER][] = "$k: $v";
+ if ($this->port) $opts[CURLOPT_PORT] = $this->port;
+ if ($this->debug) $opts[CURLINFO_HEADER_OUT] = TRUE;
+ if ($this->user && $this->pass) $opts[CURLOPT_USERPWD] = "$this->user:$this->pass";
+ switch ($name) {
+ case 'get':
+ $opts[CURLOPT_HTTPGET] = TRUE;
+ break;
+ case 'post':
+ $opts[CURLOPT_POST] = TRUE;
+ $opts[CURLOPT_POSTFIELDS] = $req_body;
+ break;
+ case 'put':
+ $opts[CURLOPT_PUT] = TRUE;
+ if (strlen($req_body)) {
+ if ($buf = fopen('php://memory', 'w+')) {
+ fwrite($buf, $req_body);
+ fseek($buf, 0);
+ $opts[CURLOPT_INFILE] = $buf;
+ $opts[CURLOPT_INFILESIZE] = strlen($req_body);
+ } else throw new Twilio_TinyHttpException('unable to open temporary file');
+ }
+ break;
+ case 'head':
+ $opts[CURLOPT_NOBODY] = TRUE;
+ break;
+ default:
+ $opts[CURLOPT_CUSTOMREQUEST] = strtoupper($name);
+ break;
+ }
+ try {
+ if ($curl = curl_init()) {
+ if (curl_setopt_array($curl, $opts)) {
+ if ($response = curl_exec($curl)) {
+ $parts = explode("\r\n\r\n", $response, 3);
+ list($head, $body) = ($parts[0] == 'HTTP/1.1 100 Continue')
+ ? array($parts[1], $parts[2])
+ : array($parts[0], $parts[1]);
+ $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+ if ($this->debug) {
+ error_log(
+ curl_getinfo($curl, CURLINFO_HEADER_OUT) .
+ $req_body
+ );
+ }
+ $header_lines = explode("\r\n", $head);
+ array_shift($header_lines);
+ foreach ($header_lines as $line) {
+ list($key, $value) = explode(":", $line, 2);
+ $headers[$key] = trim($value);
+ }
+ curl_close($curl);
+ if (isset($buf) && is_resource($buf)) fclose($buf);
+ return array($status, $headers, $body);
+ } else throw new Twilio_TinyHttpException(curl_error($curl));
+ } else throw new Twilio_TinyHttpException(curl_error($curl));
+ } else throw new Twilio_TinyHttpException('unable to initialize cURL');
+ } catch (ErrorException $e) {
+ if (is_resource($curl)) curl_close($curl);
+ if (isset($buf) && is_resource($buf)) fclose($buf);
+ throw $e;
+ }
+ }
+
+ public function authenticate($user, $pass) {
+ $this->user = $user;
+ $this->pass = $pass;
+ }
}
View
100 classes/twilio/request/transcriptions.php 100755 → 100644
@@ -1,51 +1,51 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Request_Transcriptions extends Twilio_Request implements Twilio_Request_Base {
-
- /**
- * @var array Stored default attributes
- */
- protected $defaults = array(
- 'Sid' => false,
- 'RecordingSid' => false,
- 'DateCreated' => false,
- 'Page' => false,
- 'PageSize' => 50
- );
-
- /**
- * @var string Stores Request URI
- */
- protected $res = '/2010-04-01/Accounts/%s/Transcriptions%s.json';
-
- /**
- * Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
- */
- public function create($attr = array()) {
- $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
- $accoundsid = \Config::get('twilio.account_sid');
- $accoundsid .= (!empty($attr['RecordingSid'])) ? '/Recordings/' . $attr['RecordingSid'] : '';
- $res = sprintf($this->res, $accoundsid, $sid, '');
- unset($attr['Sid'], $attr['RecordingSid']);
- $body = $this->create_post($attr);
- $response = $this->send($res, $body, 'GET');
- return $response;
- }
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Request_Transcriptions extends Twilio_Request implements Twilio_Request_Base {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $defaults = array(
+ 'Sid' => false,
+ 'RecordingSid' => false,
+ 'DateCreated' => false,
+ 'Page' => false,
+ 'PageSize' => 50
+ );
+
+ /**
+ * @var string Stores Request URI
+ */
+ protected $res = '/2010-04-01/Accounts/%s/Transcriptions%s.json';
+
+ /**
+ * Executes the request, returning the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
+ */
+ public function create($attr = array()) {
+ $sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
+ $accoundsid = \Config::get('twilio.account_sid');
+ $accoundsid .= (!empty($attr['RecordingSid'])) ? '/Recordings/' . $attr['RecordingSid'] : '';
+ $res = sprintf($this->res, $accoundsid, $sid, '');
+ unset($attr['Sid'], $attr['RecordingSid']);
+ $body = $this->create_post($attr);
+ $response = $this->send($res, $body, 'GET');
+ return $response;
+ }
+
}
View
248 classes/twilio/twiml.php 100755 → 100644
@@ -1,124 +1,124 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Twiml_Exception extends \FuelException {
-
-}
-
-class Twilio_Twiml {
-
- /**
- * Returns a new Twilio_Request object
- *
- * @return Twilio_Request
- */
- public static function forge() {
- return new static();
- }
-
- /**
- * @var array An array of verbs
- */
- private $verbs = array();
-
- /**
- * @var array An array of allowed verbs
- */
- private $allowed_verbs = array(
- 'say',
- 'play',
- 'record',
- 'sms',
- 'hangup',
- 'redirect',
- 'reject',
- 'pause',
- 'dial',
- 'gather',
- 'say',
- 'play',
- 'pause',
- 'number',
- 'client',
- 'conference'
- );
-
- /**
- *
- * @param string $verb Name the of the element
- * @param array $args Method arguments
- * @return Twilio_Twiml Return the object to enable chaining
- * @throws Twilio_Twiml_Exception
- */
- public function __call($verb, $args = array()) {
- if ($verb == 'render') {
- return $this->render();
- }
-
- if (!in_array($verb, $this->allowed_verbs) and !array_key_exists($verb, $this->allowed_verbs)) {
- throw new Twilio_Twiml_Exception($verb . ' is invalid');
- }
- if (in_array($verb, $this->allowed_verbs)) {
- $noun = (isset($args[0])) ? $args[0] : '';
- $attr = (isset($args[1])) ? $args[1] : '';
- return $this->verb($verb, $attr, $noun);
- }
- }
-
- /**
- *
- * @param string $verb
- * @param array $attr An associative array of attributes
- * @param mixed $noun The element noun
- * @return Twilio_Twiml Return the object to enable chaining
- * @throws Twilio_Twiml_Exception
- */
- private function verb($verb, $attr = array(), $noun = '') {
- $class = 'Twilio_Twiml_' . ucwords(strtolower($verb));
- if (class_exists($class)) {
- $this->verbs[] = new $class($attr, $noun);
- } else {
- throw new Twilio_Twiml_Exception($class . ' does not exist.');
- }
- return $this;
- }
-
- /**
- * Renders the Twiml document
- *
- * @return string An Twiml document
- */
- public function render() {
- $nl = "\n";
- $twiml = '<?xml version="1.0" encoding="UTF-8" ?>' . $nl;
- $twiml .= '<Response>' . $nl;
- foreach ($this->verbs as $verb) {
- $twiml .= $verb->render() . $nl;
- }
- $twiml .= '</Response>' . $nl;
- return $twiml;
- }
-
- /**
- * Returns an array of verbs
- *
- * @return array An array of verbs
- */
- public function verbs() {
- return $this->verbs;
- }
-
-}
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Twiml_Exception extends \FuelException {
+
+}
+
+class Twilio_Twiml {
+
+ /**
+ * Returns a new Twilio_Request object
+ *
+ * @return Twilio_Request
+ */
+ public static function forge() {
+ return new static();
+ }
+
+ /**
+ * @var array An array of verbs
+ */
+ private $verbs = array();
+
+ /**
+ * @var array An array of allowed verbs
+ */
+ private $allowed_verbs = array(
+ 'say',
+ 'play',
+ 'record',
+ 'sms',
+ 'hangup',
+ 'redirect',
+ 'reject',
+ 'pause',
+ 'dial',
+ 'gather',
+ 'say',
+ 'play',
+ 'pause',
+ 'number',
+ 'client',
+ 'conference'
+ );
+
+ /**
+ *
+ * @param string $verb Name the of the element
+ * @param array $args Method arguments
+ * @return Twilio_Twiml Return the object to enable chaining
+ * @throws Twilio_Twiml_Exception
+ */
+ public function __call($verb, $args = array()) {
+ if ($verb == 'render') {
+ return $this->render();
+ }
+
+ if (!in_array($verb, $this->allowed_verbs) and !array_key_exists($verb, $this->allowed_verbs)) {
+ throw new Twilio_Twiml_Exception($verb . ' is invalid');
+ }
+ if (in_array($verb, $this->allowed_verbs)) {
+ $noun = (isset($args[0])) ? $args[0] : '';
+ $attr = (isset($args[1])) ? $args[1] : '';
+ return $this->verb($verb, $attr, $noun);
+ }
+ }
+
+ /**
+ *
+ * @param string $verb
+ * @param array $attr An associative array of attributes
+ * @param mixed $noun The element noun
+ * @return Twilio_Twiml Return the object to enable chaining
+ * @throws Twilio_Twiml_Exception
+ */
+ private function verb($verb, $attr = array(), $noun = '') {
+ $class = 'Twilio_Twiml_' . ucwords(strtolower($verb));
+ if (class_exists($class)) {
+ $this->verbs[] = new $class($attr, $noun);
+ } else {
+ throw new Twilio_Twiml_Exception($class . ' does not exist.');
+ }
+ return $this;
+ }
+
+ /**
+ * Renders the Twiml document
+ *
+ * @return string An Twiml document
+ */
+ public function render() {
+ $nl = "\n";
+ $twiml = '<?xml version="1.0" encoding="UTF-8" ?>' . $nl;
+ $twiml .= '<Response>' . $nl;
+ foreach ($this->verbs as $verb) {
+ $twiml .= $verb->render() . $nl;
+ }
+ $twiml .= '</Response>' . $nl;
+ return $twiml;
+ }
+
+ /**
+ * Returns an array of verbs
+ *
+ * @return array An array of verbs
+ */
+ public function verbs() {
+ return $this->verbs;
+ }
+
+}
+
View
34 classes/twilio/twiml/client.php 100755 → 100644
@@ -1,18 +1,18 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Twiml_Client extends Twilio_Twiml_Verb {
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Twiml_Client extends Twilio_Twiml_Verb {
+
}
View
60 classes/twilio/twiml/conference.php 100755 → 100644
@@ -1,31 +1,31 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Twiml_Conference extends Twilio_Twiml_Verb {
-
- /**
- * @var array Stored default attributes
- */
- protected $default = array(
- 'muted' => 'false',
- 'beep' => 'true',
- 'startConferenceOnEnter' => 'true',
- 'endConferenceOnExit' => 'false',
- 'waitUrl' => '',
- 'waitMethod' => 'POST',
- 'maxParticipants' => '40',
- );
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Twiml_Conference extends Twilio_Twiml_Verb {
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $default = array(
+ 'muted' => 'false',
+ 'beep' => 'true',
+ 'startConferenceOnEnter' => 'true',
+ 'endConferenceOnExit' => 'false',
+ 'waitUrl' => '',
+ 'waitMethod' => 'POST',
+ 'maxParticipants' => '40',
+ );
+
}
View
90 classes/twilio/twiml/dial.php 100755 → 100644
@@ -1,45 +1,45 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Twiml_Dial extends Twilio_Twiml_Nest {
-
- /**
- * @var array Stored an array of allowed_nested objects
- */
- protected $noun = array();
-
- /**
- * @var array Stored default attributes
- */
- protected $default = array(
- 'action' => '',
- 'method' => 'POST',
- 'timeout' => '30',
- 'hangupOnStar' => 'false',
- 'timeLimit' => '14400',
- 'callerId' => '',
- 'record' => 'false',
- );
-
- /**
- * @var array An array of allowed nested objects
- */
- protected $allowed_nested = array(
- 'Twilio\\Twilio_Twiml_Number',
- 'Twilio\\Twilio_Twiml_Client',
- 'Twilio\\Twilio_Twiml_Conference'
- );
-
-}
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Twiml_Dial extends Twilio_Twiml_Nest {
+
+ /**
+ * @var array Stored an array of allowed_nested objects
+ */
+ protected $noun = array();
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $default = array(
+ 'action' => '',
+ 'method' => 'POST',
+ 'timeout' => '30',
+ 'hangupOnStar' => 'false',
+ 'timeLimit' => '14400',
+ 'callerId' => '',
+ 'record' => 'false',
+ );
+
+ /**
+ * @var array An array of allowed nested objects
+ */
+ protected $allowed_nested = array(
+ 'Twilio\\Twilio_Twiml_Number',
+ 'Twilio\\Twilio_Twiml_Client',
+ 'Twilio\\Twilio_Twiml_Conference'
+ );
+
+}
View
84 classes/twilio/twiml/gather.php 100755 → 100644
@@ -1,43 +1,43 @@
-<?php
-
-/**
- * A package to use Twilio api https://www.twilio.com.
- *
- * @package Twilio
- * @version 0.1
- * @author Matthew McConnell
- * @license MIT License
- * @copyright 2012 Matthew McConnell
- * @link http://maca134.co.uk
- */
-
-namespace Twilio;
-
-class Twilio_Twiml_Gather extends Twilio_Twiml_Nest {
-
- /**
- * @var array Stored an array of allowed_nested objects
- */
- protected $noun = array();
-
- /**
- * @var array Stored default attributes
- */
- protected $default = array(
- 'action' => '',
- 'method' => 'POST',
- 'timeout' => 5,
- 'finishOnKey' => '#',
- 'numDigits' => ''
- );
-
- /**
- * @var array An array of allowed nested objects
- */
- protected $allowed_nested = array(
- 'Twilio\\Twilio_Twiml_Say',
- 'Twilio\\Twilio_Twiml_Play',
- 'Twilio\\Twilio_Twiml_Pause'
- );
-
+<?php
+
+/**
+ * A package to use Twilio api https://www.twilio.com.
+ *
+ * @package Twilio
+ * @version 0.1
+ * @author Matthew McConnell
+ * @license MIT License
+ * @copyright 2012 Matthew McConnell
+ * @link http://maca134.co.uk
+ */
+
+namespace Twilio;
+
+class Twilio_Twiml_Gather extends Twilio_Twiml_Nest {
+
+ /**
+ * @var array Stored an array of allowed_nested objects
+ */
+ protected $noun = array();
+
+ /**
+ * @var array Stored default attributes
+ */
+ protected $default = array(
+ 'action' => '',
+ 'method' => 'POST',
+ 'timeout' => 5,
+ 'finishOnKey' => '#',
+ 'numDigits' => ''
+ );
+
+ /**
+ * @var array An array of allowed nested objects
+ */
+ protected $allowed_nested = array(
+ 'Twilio\\Twilio_Twiml_Say',
+ 'Twilio\\Twilio_Twiml_Play',
+ 'Twilio\\Twilio_Twiml_Pause'
+ );
+
}
View
44 classes/twilio/twiml/hangup.php 100755 → 100644
@@ -1,23 +1,23 @@