Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit ca2fd033071412378b8ed9b48de979c345d33dc4 @avalanche123 committed Jul 31, 2011
Showing with 6,483 additions and 0 deletions.
  1. +32 −0 README.md
  2. +32 −0 app/code/community/Avalanche/Twilio/Block/Client.php
  3. +15 −0 app/code/community/Avalanche/Twilio/Block/Page/Head.php
  4. +58 −0 app/code/community/Avalanche/Twilio/Block/System/Config/Fieldset/Hint.php
  5. +12 −0 app/code/community/Avalanche/Twilio/Block/System/Config/Form/Field/ApplicationSid.php
  6. +12 −0 app/code/community/Avalanche/Twilio/Block/System/Config/Form/Field/VerifiedNumbers.php
  7. +29 −0 app/code/community/Avalanche/Twilio/Block/Twiml.php
  8. +22 −0 app/code/community/Avalanche/Twilio/Helper/Data.php
  9. +15 −0 app/code/community/Avalanche/Twilio/Model/System/Config/Backend/Application.php
  10. +28 −0 app/code/community/Avalanche/Twilio/Model/System/Config/Source/ApplicationSid.php
  11. +28 −0 app/code/community/Avalanche/Twilio/Model/System/Config/Source/VerifiedNumbers.php
  12. +24 −0 app/code/community/Avalanche/Twilio/Model/Twilio.php
  13. +27 −0 app/code/community/Avalanche/Twilio/controllers/TwilioController.php
  14. +125 −0 app/code/community/Avalanche/Twilio/etc/config.xml
  15. +117 −0 app/code/community/Avalanche/Twilio/etc/system.xml
  16. +35 −0 app/design/adminhtml/default/default/layout/twilio.xml
  17. +35 −0 app/design/adminhtml/default/default/template/twilio/system/config/fieldset/hint.phtml
  18. +38 −0 app/design/frontend/base/default/layout/twilio.xml
  19. +30 −0 app/design/frontend/base/default/template/twilio/client.phtml
  20. +1 −0 app/design/frontend/base/default/template/twilio/page/head.phtml
  21. +6 −0 app/design/frontend/base/default/template/twilio/twiml.phtml
  22. +29 −0 app/etc/modules/Avalanche_Twilio.xml
  23. 0 app/locale/en_US/Avalanche_Twilio.csv
  24. +1 −0 lib/Twilio/.gitignore
  25. +8 −0 lib/Twilio/AUTHORS
  26. +22 −0 lib/Twilio/LICENSE
  27. +38 −0 lib/Twilio/Makefile
  28. +59 −0 lib/Twilio/README.md
  29. +158 −0 lib/Twilio/Services/Twilio.php
  30. +78 −0 lib/Twilio/Services/Twilio/ArrayDataProxy.php
  31. +78 −0 lib/Twilio/Services/Twilio/AutoPagingIterator.php
  32. +163 −0 lib/Twilio/Services/Twilio/CachingDataProxy.php
  33. +346 −0 lib/Twilio/Services/Twilio/Capability.php
  34. +44 −0 lib/Twilio/Services/Twilio/DataProxy.php
  35. +55 −0 lib/Twilio/Services/Twilio/InstanceResource.php
  36. +147 −0 lib/Twilio/Services/Twilio/ListResource.php
  37. +74 −0 lib/Twilio/Services/Twilio/Page.php
  38. +41 −0 lib/Twilio/Services/Twilio/PartialApplicationHelper.php
  39. +36 −0 lib/Twilio/Services/Twilio/RequestValidator.php
  40. +85 −0 lib/Twilio/Services/Twilio/Resource.php
  41. +26 −0 lib/Twilio/Services/Twilio/Rest/Account.php
  42. +10 −0 lib/Twilio/Services/Twilio/Rest/Accounts.php
  43. +6 −0 lib/Twilio/Services/Twilio/Rest/Application.php
  44. +12 −0 lib/Twilio/Services/Twilio/Rest/Applications.php
  45. +7 −0 lib/Twilio/Services/Twilio/Rest/AvailablePhoneNumber.php
  46. +30 −0 lib/Twilio/Services/Twilio/Rest/AvailablePhoneNumbers.php
  47. +18 −0 lib/Twilio/Services/Twilio/Rest/Call.php
  48. +26 −0 lib/Twilio/Services/Twilio/Rest/Calls.php
  49. +12 −0 lib/Twilio/Services/Twilio/Rest/Conference.php
  50. +6 −0 lib/Twilio/Services/Twilio/Rest/Conferences.php
  51. +6 −0 lib/Twilio/Services/Twilio/Rest/IncomingPhoneNumber.php
  52. +10 −0 lib/Twilio/Services/Twilio/Rest/IncomingPhoneNumbers.php
  53. +6 −0 lib/Twilio/Services/Twilio/Rest/Notification.php
  54. +6 −0 lib/Twilio/Services/Twilio/Rest/Notifications.php
  55. +6 −0 lib/Twilio/Services/Twilio/Rest/OutgoingCallerId.php
  56. +12 −0 lib/Twilio/Services/Twilio/Rest/OutgoingCallerIds.php
  57. +10 −0 lib/Twilio/Services/Twilio/Rest/Participant.php
  58. +6 −0 lib/Twilio/Services/Twilio/Rest/Participants.php
  59. +6 −0 lib/Twilio/Services/Twilio/Rest/Recording.php
  60. +6 −0 lib/Twilio/Services/Twilio/Rest/Recordings.php
  61. +6 −0 lib/Twilio/Services/Twilio/Rest/Sandbox.php
  62. +6 −0 lib/Twilio/Services/Twilio/Rest/ShortCode.php
  63. +6 −0 lib/Twilio/Services/Twilio/Rest/ShortCodes.php
  64. +6 −0 lib/Twilio/Services/Twilio/Rest/SmsMessage.php
  65. +24 −0 lib/Twilio/Services/Twilio/Rest/SmsMessages.php
  66. +6 −0 lib/Twilio/Services/Twilio/Rest/Transcription.php
  67. +6 −0 lib/Twilio/Services/Twilio/Rest/Transcriptions.php
  68. +25 −0 lib/Twilio/Services/Twilio/RestException.php
  69. +98 −0 lib/Twilio/Services/Twilio/TinyHttp.php
  70. +103 −0 lib/Twilio/Services/Twilio/Twiml.php
  71. +130 −0 lib/Twilio/docs/Makefile
  72. +3 −0 lib/Twilio/docs/_themes/.gitignore
  73. +45 −0 lib/Twilio/docs/_themes/LICENSE
  74. +25 −0 lib/Twilio/docs/_themes/README.rst
  75. +86 −0 lib/Twilio/docs/_themes/flask_theme_support.py
  76. +19 −0 lib/Twilio/docs/_themes/kr/layout.html
  77. +19 −0 lib/Twilio/docs/_themes/kr/relations.html
  78. +469 −0 lib/Twilio/docs/_themes/kr/static/flasky.css_t
  79. +70 −0 lib/Twilio/docs/_themes/kr/static/small_flask.css
  80. +7 −0 lib/Twilio/docs/_themes/kr/theme.conf
  81. +22 −0 lib/Twilio/docs/_themes/kr_small/layout.html
  82. +287 −0 lib/Twilio/docs/_themes/kr_small/static/flasky.css_t
  83. +10 −0 lib/Twilio/docs/_themes/kr_small/theme.conf
  84. +743 −0 lib/Twilio/docs/api/rest.rst
  85. +21 −0 lib/Twilio/docs/api/services.rst
  86. +223 −0 lib/Twilio/docs/conf.py
  87. +137 −0 lib/Twilio/docs/index.rst
  88. +2 −0 lib/Twilio/docs/requirements.txt
  89. +203 −0 lib/Twilio/docs/usage/rest.rst
  90. +55 −0 lib/Twilio/docs/usage/token-generation.rst
  91. +49 −0 lib/Twilio/docs/usage/twiml.rst
  92. +48 −0 lib/Twilio/docs/usage/validation.rst
  93. +109 −0 lib/Twilio/package.php
  94. +133 −0 lib/Twilio/package.xml
  95. +20 −0 lib/Twilio/tests/Bootstrap.php
  96. +96 −0 lib/Twilio/tests/CapabilityTest.php
  97. +48 −0 lib/Twilio/tests/RequestValidatorTest.php
  98. +138 −0 lib/Twilio/tests/ResourcesTest.php
  99. +219 −0 lib/Twilio/tests/TwilioTest.php
  100. +336 −0 lib/Twilio/tests/TwimlTest.php
  101. +7 −0 lib/Twilio/tests/phpunit.xml
  102. BIN skin/adminhtml/default/default/images/twilio.png
  103. +6 −0 skin/adminhtml/default/default/twilio.css
  104. +2 −0 skin/frontend/base/default/css/twilio.css
  105. BIN skin/frontend/base/default/images/twilio-poweredbysmall.png
@@ -0,0 +1,32 @@
+# About
+This module integrates Twilio(http://www.twilio.com/) in Magento(http://www.magentocommerce.com/). This module allows Magento customers to call customer support number directly from their browser.
+
+# Installation
+To install the module, simply copy the contents of this repository to the root directory of your Magento installation
+
+# Configuration
+After the module has been installed, make sure to reload Magento's cache from the administrative interface. After reloading the cache, you should see "Twilio" section in the "Services" menu group of the configurations screen of the admin area.
+
+* Goto System > Configuration from the top navigation menu.
+* Click "Twilio" under "Services" group in the left menu bar.
+* Fill in your Twilio AccountSid and AuthToken.
+* Press "Save" and wait for the green confirmation box.
+
+Now you should be able to pick a Twilio application that the browser client will be using in the "Contacts" section of the admin menu.
+
+* Navigate to the main configuration area like in previous steps.
+* Click "Contacts" under "General" group in the left menu bar.
+* Unfold "Twilio Customer Service Calls" section.
+* Pick a Twilio application from the dropdown.
+* Pick a caller id from the dropdown.
+* Specify customer service phone number that Twilio will connect your customers with.
+
+> NOTE: if you can't find an Application or a Caller id to use, make sure that you have them created in your Twilio account's dashboard.
+
+# Usage
+
+After the previous steps have been completed, a customer section will be added to right column of the home page screen, feel free to move it to correct location and style it properly, everything is done using Magento templating system.
+
+# Contributing
+
+This is an alpha stability project and will definitely have bugs. Use GitHub issues to report any and feel free to fork the project and submit pull requests upstream, I'm usually pretty responsive.
@@ -0,0 +1,32 @@
+<?php
+
+class Avalanche_Twilio_Block_Client extends Mage_Core_Block_Template
+{
+ protected $clientId;
+
+ public function setClientId($clientId)
+ {
+ $this->clientId = $clientId;
+ }
+
+ protected function getCapability()
+ {
+ return Mage::getSingleton('twilio/twilio')->getCapability();
+ }
+
+ public function getOutboundToken()
+ {
+ $capability = $this->getCapability();
+
+ $capability->allowClientOutgoing(Mage::getStoreConfig('contacts/twilio/application_sid'));
+ return $capability->generateToken();
+ }
+
+ public function getInboundToken()
+ {
+ $capability = $this->getCapability();
+
+ $capability->allowClientIncoming($this->clientId);
+ return $capability->generateToken();
+ }
+}
@@ -0,0 +1,15 @@
+<?php
+
+require_once 'Twilio/Services/Twilio.php';
+
+class Avalanche_Twilio_Block_Page_Head extends Mage_Core_Block_Template
+{
+ /**
+ * Initialize template
+ *
+ */
+ protected function _construct()
+ {
+ $this->setTemplate('twilio/page/head.phtml');
+ }
+}
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category Mage
+ * @package Mage_Paypal
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+
+/**
+ * Renderer for Twilio banner in System Configuration
+ * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
+ */
+class Avalanche_Twilio_Block_System_Config_Fieldset_Hint
+ extends Mage_Adminhtml_Block_Abstract
+ implements Varien_Data_Form_Element_Renderer_Interface
+{
+ protected $_template = 'twilio/system/config/fieldset/hint.phtml';
+
+ /**
+ * Render fieldset html
+ *
+ * @param Varien_Data_Form_Element_Abstract $element
+ * @return string
+ */
+ public function render(Varien_Data_Form_Element_Abstract $element)
+ {
+ return $this->toHtml();
+ }
+
+ public function getFormElementId($name)
+ {
+ return sprintf('contacts_twilio_%s', $name);
+ }
+
+ public function getRowId($name)
+ {
+ return sprintf('row_contacts_twilio_%s', $name);
+ }
+}
@@ -0,0 +1,12 @@
+<?php
+
+class Avalanche_Twilio_Block_System_Config_Form_Field_ApplicationSid extends Mage_Adminhtml_Block_System_Config_Form_Field
+{
+// protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
+// {
+// $html = $element->getElementHtml();
+// $html .= 'Don\'t see an application to use? <a href="https://www.twilio.com/user/account/apps" target="_blank">Register a new application</a>';
+//
+// return $html;
+// }
+}
@@ -0,0 +1,12 @@
+<?php
+
+class Avalanche_Twilio_Block_System_Config_Form_Field_VerifiedNumbers extends Mage_Adminhtml_Block_System_Config_Form_Field
+{
+// protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
+// {
+// $html = $element->getElementHtml();
+// $html .= 'Don\'t see a number to use? <a href="https://www.twilio.com/user/account/phone-numbers" target="_blank">Register a new number</a>';
+//
+// return $html;
+// }
+}
@@ -0,0 +1,29 @@
+<?php
+
+class Avalanche_Twilio_Block_Twiml extends Mage_Core_Block_Template
+{
+ protected $phoneNumber;
+ protected $callerId;
+
+ public function setPhoneNumber($phoneNumber)
+ {
+ $this->phoneNumber = $phoneNumber;
+
+ return $this;
+ }
+
+ public function setCallerId($callerId)
+ {
+ $this->callerId = $callerId;
+ }
+
+ public function getCallerIdString()
+ {
+ return ' callerId="'. $this->callerId .'"';
+ }
+
+ public function getRecepient()
+ {
+ return "<Number>" . $this->phoneNumber . "</Number>";
+ }
+}
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * @category Avalanche
+ * @package Avalanche_Twilio
+ * @copyright Copyright (c) 2011 Bulat Shakirzyanov <mallluhuct@gmail.com>
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+class Avalanche_Twilio_Helper_Data extends Mage_Core_Helper_Abstract
+{
+}
@@ -0,0 +1,15 @@
+<?php
+
+class Avalanche_Twilio_Model_System_Config_Backend_Application extends Mage_Core_Model_Config_Data
+{
+ protected function _beforeSave()
+ {
+ if ($this->isValueChanged()) {
+ $twilio = Mage::getSingleton('twilio/twilio');
+ $twilio->account->applications
+ ->get($this->getValue())
+ ->update('VoiceUrl', Mage::getBaseUrl().'twilio/twilio/twiml')
+ ;
+ }
+ }
+}
@@ -0,0 +1,28 @@
+<?php
+
+require_once 'Twilio/Services/Twilio.php';
+
+class Avalanche_Twilio_Model_System_Config_Source_ApplicationSid
+{
+
+ /**
+ * Options getter
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ $client = Mage::getSingleton('twilio/twilio');
+ $values = array();
+
+ foreach ($client->account->applications as $app) {
+ $values[] = array(
+ 'value' => $app->sid,
+ 'label' => $app->friendly_name . ' (' . $app->sid . ')'
+ );
+ }
+
+ return $values;
+ }
+
+}
@@ -0,0 +1,28 @@
+<?php
+
+require_once 'Twilio/Services/Twilio.php';
+
+class Avalanche_Twilio_Model_System_Config_Source_VerifiedNumbers
+{
+
+ /**
+ * Options getter
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ $client = Mage::getSingleton('twilio/twilio');
+ $values = array();
+
+ foreach ($client->account->outgoing_caller_ids as $number) {
+ $values[] = array(
+ 'value' => $number->phone_number,
+ 'label' => $number->friendly_name,
+ );
+ }
+
+ return $values;
+ }
+
+}
@@ -0,0 +1,24 @@
+<?php
+
+require_once 'Twilio/Services/Twilio.php';
+
+class Avalanche_Twilio_Model_Twilio extends Services_Twilio
+{
+ protected $accountSid;
+ protected $authToken;
+
+ public function __construct()
+ {
+ $decryptor = Mage::helper('core');
+
+ $this->accountSid = $decryptor->decrypt(Mage::getStoreConfig('twilio/config/account_sid'));
+ $this->authToken = $decryptor->decrypt(Mage::getStoreConfig('twilio/config/auth_token'));
+
+ parent::__construct($this->accountSid, $this->authToken);
+ }
+
+ public function getCapability()
+ {
+ return new Services_Twilio_Capability($this->accountSid, $this->authToken);
+ }
+}
@@ -0,0 +1,27 @@
+<?php
+
+class Avalanche_Twilio_TwilioController extends Mage_Core_Controller_Front_Action
+{
+ protected $failed;
+
+ public function twimlAction()
+ {
+ $this->loadLayout();
+
+ $this->getResponse()
+ ->setHttpResponseCode(200)
+ ->setHeader('Content-type', 'text/xml', true)
+ ;
+
+ $block = $this->getLayout()->getBlock('twiml');
+ $phoneNumber = Mage::getStoreConfig('contacts/twilio/phone_number');
+ $callerId = Mage::getStoreConfig('contacts/twilio/caller_id');
+
+ if ($phoneNumber && $callerId) {
+ $block->setPhoneNumber($phoneNumber);
+ $block->setCallerId($callerId);
+ }
+
+ $this->renderLayout();
+ }
+}
Oops, something went wrong.

0 comments on commit ca2fd03

Please sign in to comment.