Index: class.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/textmarks/class.php,v
retrieving revision 1.1
diff -u -p -r1.1 class.php
--- class.php	4 Dec 2008 22:24:02 -0000	1.1
+++ class.php	19 Jan 2011 11:27:21 -0000
@@ -5,7 +5,7 @@
 /**
  * @file
  * A class to make the actual API calls to the Textmarks API.
- * 
+ *
  * @ingroup textmarks_settings
  */
 
@@ -22,10 +22,10 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ */
 
 /**
- * TextMarks PHP API Client Library. v2.48a.
+ * TextMarks V2 API Client Library (PHP). v2.60d.
  * ---------------------------------------------------------------------------
  *
  * TextMarks provides a text-messaging platform you can integrate into
@@ -33,28 +33,27 @@
  * users or groups of users.
  *
  * For full online documentation, visit:
- *   http://www.textmarks.com/dev/docs/api/
+ *   http://www.textmarks.com/dev/docs/api2/
  *   http://www.textmarks.com/dev/
  *   http://www.textmarks.com/
  *
- * The XML-RPC HTTP API that this library integrates with is NOT REQUIRED.
+ * The HTTP API that this library integrates with is NOT REQUIRED.
  * You can do all kinds of wonderful things without this API and without
  * writing any code at all.  However if you wish to automate and integrate
  * TextMarks more deeply into your applications, this API may be useful.
  *
  * This optional PHP client library provides one way to integrate with
- * the platform's XML-RPC HTTP API from your PHP applications.
+ * the platform's HTTP API from your PHP applications.
  *
  * This library requires:
  *  - PHP 5.1 or greater.
  *  - libCURL (normally included with PHP).
- *  - SimpleXMLEelement (normally included with PHP).
  *
  * ---------------------------------------------------------------------------
  * @author Dan Kamins [d k a m i n s A.T t e x t m a r k s D.O.T c o m]
  * @package tmAPIClient
  * ---------------------------------------------------------------------------
- * Copyright (c) 2008, TextMarks Inc. All rights reserved.
+ * Copyright (c) 2009, TextMarks Inc. All rights reserved.
  * ---------------------------------------------------------------------------
  *
  * THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
@@ -79,6 +78,20 @@
  */
 /** */
 
+// ---------------------------------------------------------------------------
+
+/*
+ * For PHP prior to 5.2 (which introduced native JSON support),
+ * we include a free JSON library and bind it to json_decode.
+ */
+if (!function_exists('json_decode')) {
+  require_once('JSON.php');
+  function json_decode($json) {
+    $svc = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
+    return $svc->decode($json);
+  }
+}
+
 
 
 // ---------------------------------------------------------------------------
@@ -88,14 +101,14 @@
 /**
  * Exception subclass used by TextMarksAPIClient.
  */
-class TextMarksAPIClientException extends Exception
+class TextMarksV2APIClientException extends Exception
 {
 }
 
 /**
- * Exception subclass used by TextMarksAPIClient for transport-level errors.
+ * Exception subclass used by TextMarksV2APIClient for transport-level errors.
  */
-class TextMarksAPIClientTransportException extends TextMarksAPIClientException
+class TextMarksV2APIClientTransportException extends TextMarksV2APIClientException
 {
 }
 
@@ -106,106 +119,150 @@ class TextMarksAPIClientTransportExcepti
 
 
 /**
- * Abstract TextMarksAPIClient, subclassed by API packages.
+ * TextMarksV2APIClient - construct and call().
  */
-abstract class TextMarksAPIClient
+class TextMarksV2APIClient
 {
-	const API_URL_BASE      = 'http://dev1.api.textmarks.com/';
-
-	// -----------------------------------------------------------------------
-
-	/**
-	 * Create TextMarksAPIClient around indicated authentication info.
-	 *
-	 * @param string  $sApiKey   API Key ( register at http://www.textmarks.com/dev/api/reg/ )
-	 * @param string  $sAuthUser Phone# or TextMarks username to authenticate to API with.
-	 * @param string  $sAuthPass TextMarks Password associated with sAuthUser.
-	 */
-	public function __construct( $sApiKey, $sAuthUser, $sAuthPass )
-	{
-		$this->m_sApiKey    = $sApiKey;
-		$this->m_sAuthUser  = $sAuthUser;
-		$this->m_sAuthPass  = $sAuthPass;
-	}
-
-	/**
-	 * Execute HTTP request (post params to API endpoint) and return string response.
-	 *
-	 * @param string              $sUrl      URL to request by POST.
-	 * @param map(string,string)  $mssParams Params to POST.
-	 * @return string Response (usually XML).
-	 * @throws TextMarksAPIClientTransportException on error.
-	 */
-	protected function _makeHttpCall( $sUrl, $mssParams )
-	{
-		// Convert param map to encoded form (to post):
-		$sPostData = "";
-		foreach ($mssParams as $sK => $sV)
-		{
-			$sPostData .= "&" . urlencode($sK) . "=" . urlencode($sV);
-		}
-
-		// Prep curl:
-		$ch = curl_init();
-		$arsHeaders = array("Content-Type: application/x-www-form-urlencoded",);
-		curl_setopt($ch, CURLOPT_URL, $sUrl);
-		curl_setopt($ch, CURLOPT_HTTPHEADER, $arsHeaders);
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $sPostData);
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // (response as string, not output)
-
-		// Make request (synchronous):
-		$sResponse = curl_exec($ch);
-
-		// Check for transport-level errors:
-		$iCurlErrNo     = curl_errno($ch);
-		$iHttpRespCode  = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-		if ($iCurlErrNo != 0)
-		{
-			curl_close($ch);
-			throw new TextMarksAPIClientTransportException("TextMarksAPIClient ($sUrl) saw CURL error #$iCurlErrNo: " . curl_error($ch), curl_error($ch));
-		}
-		if ($iHttpRespCode != 200)
-		{
-			curl_close($ch);
-			throw new TextMarksAPIClientTransportException("TextMarksAPIClient ($sUrl) saw non-200 HTTP response #$iHttpRespCode.", -1);
-		}
-
-		// No obvious transport-level errors. Return response:
-		return $sResponse;
-	}
-
-	/**
-	 * Execute API call and return XML response.
-	 *
-	 * The API Key and auth params are automatically added.
-	 *
-	 * @param string              $sMethodName     URL to request by POST.
-	 * @param map(string,string)  $mssParams       Params for method.
-	 * @return SimpleXMLElement representing XML response.
-	 * @throws Exception on error.
-	 */
-	protected function _callApi( $sPackageName, $sMethodName, $mssParams )
-	{
-		// Prep:
-		$mssParamsFull = $mssParams; // (copy array to keep original clean)
-		$mssParamsFull['apik']      = $this->m_sApiKey;
-		$mssParamsFull['auth_user'] = $this->m_sAuthUser;
-		$mssParamsFull['auth_pass'] = $this->m_sAuthPass;
-		$sUrl = self::API_URL_BASE . $sPackageName . '/' . $sMethodName . '/';
-
-		// Make actual HTTP call:
-		$sResp = $this->_makeHttpCall( $sUrl, $mssParamsFull );
-
-		// Parse and return XML of response:
-		$xml = new SimpleXMLElement($sResp);
-		return $xml;
-	}
-
-	// -----------------------------------------------------------------------
-
-	protected $m_sApiKey;
-	protected $m_sAuthUser;
-	protected $m_sAuthPass;
+  // Public constants:
+  const HTTP_GET          = 'GET';
+  const HTTP_POST         = 'POST';
+
+  // -----------------------------------------------------------------------
+
+  // Configuration:
+  const API_URL_BASE      = 'http://php1.api2.textmarks.com';
+
+  // -----------------------------------------------------------------------
+
+  /**
+   * Create TextMarksV2APIClient around indicated authentication info (optional).
+   *
+   * @param string  $sApiKey   API Key ( register at http://www.textmarks.com/dev/api/reg/ ). (NULL for none).
+   * @param string  $sAuthUser Phone# or TextMarks username to authenticate to API with. (NULL for none).
+   * @param string  $sAuthPass TextMarks Password associated with sAuthUser. (NULL for none).
+   */
+  public function TextMarksV2APIClient( $sApiKey = NULL, $sAuthUser = NULL, $sAuthPass = NULL )
+  {
+    $this->m_sApiKey    = $sApiKey;
+    $this->m_sAuthUser  = $sAuthUser;
+    $this->m_sAuthPass  = $sAuthPass;
+  }
+
+  /**
+   * Public method to call API.
+   *
+   * The API Key and auth params are automatically added if present.
+   *
+   * @param string              $sPackageName    Package name.
+   * @param string              $sMethodName     Method name.
+   * @param map(string,string)  $mssParams       Params for method.
+   * @param string              $sHttpMethod     'GET' or 'POST'.
+   * @return Decoded (from JSON) response.
+   * @throws Exception on error.
+   */
+  public function call( $sPackageName, $sMethodName, $mssParams, $sHttpMethod = self::HTTP_POST )
+  {
+    return $this->_callJsonApiMethod($sPackageName, $sMethodName, $mssParams, $sHttpMethod);
+  }
+
+
+  // -----------------------------------------------------------------------
+
+
+  /**
+   * Execute HTTP request (post params to API endpoint) and return string response.
+   *
+   * @param string              $sUrl           URL to request (method endpoint).
+   * @param map(string,string)  $mssParams      Request params.
+   * @param string              $sHttpMethod   'GET' or 'POST'.
+   * @return string Response (usually JSON string).
+   * @throws TextMarksV2APIClientTransportException on error.
+   */
+  protected function _rawHttpCall( $sUrl, $mssParams, $sHttpMethod = self::HTTP_POST )
+  {
+    // Convert param map to encoded form (to post):
+    $sPostData = "";
+    foreach ($mssParams as $sK => $sV) {
+      $sPostData .= "&" . urlencode($sK) . "=" . urlencode($sV);
+    }
+
+    // Prep curl:
+    $ch = curl_init();
+    $arsHeaders = array();
+
+    if ($sHttpMethod == 'POST') {
+      curl_setopt($ch, CURLOPT_POST, 1);
+      curl_setopt($ch, CURLOPT_URL, $sUrl);
+      $arsHeaders[] = "Content-Type: application/x-www-form-urlencoded";
+      curl_setopt($ch, CURLOPT_POSTFIELDS, $sPostData);
+    } else {
+      curl_setopt($ch, CURLOPT_HTTPGET, 1);
+      curl_setopt($ch, CURLOPT_URL, $sUrl . "?" . $sPostData);
+    }
+    curl_setopt($ch, CURLOPT_HTTPHEADER, $arsHeaders);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // (response as string, not output)
+
+    // Make request (synchronous):
+    $sResponse = curl_exec($ch);
+
+    // Check for transport-level errors:
+    $iCurlErrNo     = curl_errno($ch);
+    $iHttpRespCode  = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+    if ($iCurlErrNo != 0) {
+      curl_close($ch);
+      throw new TextMarksV2APIClientTransportException("TextMarksV2APIClient ($sUrl) saw CURL error #$iCurlErrNo: " . curl_error($ch), curl_error($ch));
+    }
+    if ($iHttpRespCode != 200) {
+      curl_close($ch);
+      throw new TextMarksV2APIClientTransportException("TextMarksV2APIClient ($sUrl) saw non-200 HTTP response #$iHttpRespCode.", -1);
+    }
+
+    // No obvious transport-level errors. Return response:
+    return $sResponse;
+  }
+
+  /**
+   * Execute API call and return decoded JSON response.
+   *
+   * The API Key and auth params are automatically added.
+   *
+   * @param string              $sPackageName    Package name.
+   * @param string              $sMethodName     Method name.
+   * @param map(string,string)  $mssParams       Params for method.
+   * @param string              $sHttpMethod     'GET' or 'POST'.
+   * @return Decoded (from JSON) response.
+   * @throws Exception on error.
+   */
+  protected function _callJsonApiMethod( $sPackageName, $sMethodName, $mssParams, $sHttpMethod = self::HTTP_POST )
+  {
+    // Prep:
+    $mssParamsFull = $mssParams; // (copy array to keep original clean)
+    if ($this->m_sApiKey !== NULL)   { $mssParamsFull['api_key']   = $this->m_sApiKey; }
+    if ($this->m_sAuthUser !== NULL) { $mssParamsFull['auth_user'] = $this->m_sAuthUser; }
+    if ($this->m_sAuthPass !== NULL) { $mssParamsFull['auth_pass'] = $this->m_sAuthPass; }
+    $sUrl = self::API_URL_BASE . '/' . $sPackageName . '/' . $sMethodName . '/';
+
+    // Make actual HTTP call:
+    $sResp = $this->_rawHttpCall( $sUrl, $mssParamsFull, $sHttpMethod );
+
+    // Parse JSON response:
+    $oDecoded = json_decode($sResp, TRUE);
+
+    // Check API response code:
+    $iResCode = (int) $oDecoded['head']['rescode'];
+    $sResMsg  = $oDecoded['head']['resmsg'];
+    if ($iResCode != 0) {
+      throw new TextMarksV2APIClientException("TextMarksV2APIClient.call($sPackageName.$sMethodName) got API error #$iResCode: $sResMsg", $iResCode);
+    }
+
+    return $oDecoded;
+  }
+
+  // -----------------------------------------------------------------------
+
+  protected $m_sApiKey;
+  protected $m_sAuthUser;
+  protected $m_sAuthPass;
 }
 
 
@@ -213,95 +270,6 @@ abstract class TextMarksAPIClient
 // ---------------------------------------------------------------------------
 
 
-/**
- * API Client for "Messaging" package.
- * See:
- *   http://www.textmarks.com/dev/docs/api/
- */
-class TextMarksAPIClient_Messaging		extends TextMarksAPIClient
-{
-	/**
-	 * Broadcast an alert to a TextMark's subscribers.
-	 * See:
-	 *   http://www.textmarks.com/dev/docs/api/ref/Messaging/postAlert/
-	 *
-	 * @param string $sTextMark   Keyword to broadcast alert on.
-	 * @param string $sMessage    Message to send.
-	 * @throws Exception on error.
-	 */
-	public function postAlert( $sTextMark, $sMessage )
-	{
-		// Call API:
-		$xmlResp = $this->_callApi('Messaging', 'postAlert', array(
-			'tm'     => $sTextMark,
-			'msg'    => $sMessage,
-			));
-
-		// Check API response code:
-		$iResCode = (int) $xmlResp->TMHead->ResCode;
-		$sResMsg  = $xmlResp->TMHead->ResMsg;
-		if ($iResCode != 0)
-		{
-			throw new TextMarksAPIClientException("TextMarksAPIClient_Messaging.postAlert got API error #$iResCode: $sResMsg", $iResCode);
-		}
-	}
-
-	/**
-	 * Send a text message to a single TextMark subscriber.
-	 * See:
-	 *   http://www.textmarks.com/dev/docs/api/ref/Messaging/sendText/
-	 *
-	 * @param string $sTextMark   Keyword the message is associated with.
-	 * @param string $sTo         Phone#/username to send to (must be $sTextMark subscriber).
-	 * @param string $sMessage    Message to send.
-	 * @throws Exception on error.
-	 */
-	public function sendText( $sTextMark, $sTo, $sMessage )
-	{
-		// Call API:
-		$xmlResp = $this->_callApi('Messaging', 'sendText', array(
-			'tm'     => $sTextMark,
-			'to'     => $sTo,
-			'msg'    => $sMessage,
-			));
-
-		// Check API response code:
-		$iResCode = (int) $xmlResp->TMHead->ResCode;
-		$sResMsg  = $xmlResp->TMHead->ResMsg;
-		if ($iResCode != 0)
-		{
-			throw new TextMarksAPIClientException("TextMarksAPIClient_Messaging.sendText got API error #$iResCode: $sResMsg", $iResCode);
-		}
-	}
-
-	/**
-	 * Attempt to subscribe phone# to TextMark.
-	 * See:
-	 *   http://www.textmarks.com/dev/docs/api/ref/Messaging/subscribe/
-	 *
-	 * @param string $sTextMark   Keyword to subscribe to.
-	 * @param string $sPhone      Phone# to subscribe.
-	 * @throws Exception on error.
-	 */
-	public function subscribe( $sTextMark, $sPhone )
-	{
-		// Call API:
-		$xmlResp = $this->_callApi('Messaging', 'subscribe', array(
-			'tm'     => $sTextMark,
-			'phone'  => $sPhone,
-			));
-
-		// Check API response code:
-		$iResCode = (int) $xmlResp->TMHead->ResCode;
-		$sResMsg  = $xmlResp->TMHead->ResMsg;
-		if ($iResCode != 0)
-		{
-			throw new TextMarksAPIClientException("TextMarksAPIClient_Messaging.subscribe got API error #$iResCode: $sResMsg", $iResCode);
-		}
-	}
-}
-
-
 
 // ---------------------------------------------------------------------------
 
@@ -311,43 +279,59 @@ class TextMarksAPIClient_Messaging		exte
  */
 function exampleTextMarksUsage()
 {
-	try
-	{
-		// Try to subscribe a user to a TextMark:
-		$sMyApiKey        = 'MyAPIKEY_12345678';
-		$sMyTextMarksUser = 'mytmuser'; // (or my TextMarks phone#)
-		$sMyTextMarksPass = 'mytmp@$$word';
-		$sKeyword         = 'MYKEYWORD';
-		$sPhone           = '4155551212';
-		$tmapi = new TextMarksAPIClient_Messaging($sMyApiKey, $sMyTextMarksUser, $sMyTextMarksPass);
-		$tmapi->subscribe($sKeyword, $sPhone);
-		echo "<h2>Success! Subscription pending.</h2>";
-
-		// Try to post an alert to a TextMark:
-		$sMyApiKey        = 'MyAPIKEY_12345678';
-		$sMyTextMarksUser = 'mytmuser'; // (or my TextMarks phone#)
-		$sMyTextMarksPass = 'mytmp@$$word';
-		$sKeyword         = 'MYKEYWORD';
-		$sMessage         = "This is an alert sent from the PHP API Client. Did it work?";
-		$tmapi = new TextMarksAPIClient_Messaging($sMyApiKey, $sMyTextMarksUser, $sMyTextMarksPass);
-		$tmapi->postAlert($sKeyword, $sMessage);
-		echo "<h2>Success! Alert sent.</h2>";
-
-		// Try to send a message to a user:
-		$sMyApiKey        = 'MyAPIKEY_12345678';
-		$sMyTextMarksUser = 'mytmuser'; // (or my TextMarks phone#)
-		$sMyTextMarksPass = 'mytmp@$$word';
-		$sKeyword         = 'MYKEYWORD';
-		$sMessage         = "This is a message sent from the PHP API Client. Did it work?";
-		$sTo              = "415-555-1212";
-		$tmapi = new TextMarksAPIClient_Messaging($sMyApiKey, $sMyTextMarksUser, $sMyTextMarksPass);
-		$tmapi->sendText($sKeyword, $sTo, $sMessage);
-		echo "<h2>Success! Alert sent.</h2>";
-	}
-	catch (Exception $e)
-	{
-		echo "Whoops... Exception caught: " . $e;
-	}
+  try
+  {
+    // Most basic echo test:
+    echo "Echo test...\n";
+    $tmapi = new TextMarksV2APIClient();
+    $resp = $tmapi->call('Test', 'echo', array(
+      'str' => "Hello world"
+      ));
+    print_r($resp);
+
+    // Check a keyword status:
+    echo "Keyword status test...\n";
+    $sMyApiKey        = 'MyAPIKEY_12345678';
+    $sKeyword         = 'MYKEYWORD';
+    $tmapi = new TextMarksV2APIClient($sMyApiKey);
+    $resp = $tmapi->call('Anybody', 'keyword_status', array(
+      'keyword' => $sKeyword
+      ));
+    print_r($resp);
+    echo "Keyword Status Code: " . $resp['body']['status'] . "\n";
+
+    // Invite a user to join a TextMark group:
+    echo "Invite a user to join a TextMark group test...\n";
+    $sMyApiKey        = 'MyAPIKEY_12345678';
+    $sKeyword         = 'MYKEYWORD';
+    $sPhone           = '4155551212';
+    $tmapi = new TextMarksV2APIClient($sMyApiKey);
+    $resp = $tmapi->call('Anybody', 'invite_to_group', array(
+      'tm' => $sKeyword,
+      'user' => $sPhone
+      ));
+    print_r($resp);
+
+    // Broadcast a message to a TextMark group:
+    echo "Broadcasting a message to a TextMark group test...\n";
+    $sMyApiKey        = 'MyAPIKEY_12345678';
+    $sMyTextMarksUser = 'mytmuser'; // (or my TextMarks phone#)
+    $sMyTextMarksPass = 'mytmp@$$word';
+    $sKeyword         = 'MYKEYWORD';
+    $sMessage         = "This is an alert sent from the PHP API Client. Did it work?";
+    $tmapi = new TextMarksV2APIClient($sMyApiKey, $sMyTextMarksUser, $sMyTextMarksPass);
+    $resp = $tmapi->call('GroupLeader', 'broadcast_message', array(
+      'tm' => $sKeyword,
+      'msg' => $sMessage
+      ));
+    print_r($resp);
+  }
+  catch (Exception $e)
+  {
+    echo "Whoops... Exception caught!\n";
+    echo "Error code: " . $e->getCode() . "\n";
+    echo "Exception: " . $e . "\n";
+  }
 }
-
+//exampleTextMarksUsage();
 ?>
\ No newline at end of file
Index: textmarks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/textmarks/textmarks.module,v
retrieving revision 1.2
diff -u -p -r1.2 textmarks.module
--- textmarks.module	4 Dec 2008 22:44:21 -0000	1.2
+++ textmarks.module	19 Jan 2011 11:27:22 -0000
@@ -4,46 +4,46 @@
 /**
  * @file
  * A module to interact with the Textmarks API.
- * 
+ *
  * @ingroup textmarks_settings
  */
 
 /*
-	Author: 
-		Justin, justin@urbaninsight.com
-		Urban Insight Inc, http://www.urbaninsight.com
-		
-	Created:
-		20081106
-		
-	Description:
-		his module automates API calls to TextMarks, a gateway service for sending 
-		SMS messages to mobile phones.
-
-		TextMarks lets you register a textmark -- a keyword like MICROSOFT -- that 
-		users text to 41411 to interact with your SMS site. The Textmarks API gateway 
-		lets you subscribe to your Textmark and send broadcast messages to individual 
-		subscribers or all subscribers.
-
-		To use this module, you will need to create a free textmark and user account at their website:
-		http://www.textmarks.com/create/
-
-		TextMarks FAQ:
-		http://www.textmarks.com/info/help/
-
-		TextMarks Developers API guide:
-		http://www.textmarks.com/dev/
-
-		Credit for the core class.php file goes to Textmarks:
-		http://www.textmarks.com/dev/docs/apiclient/php/
-		(Thanks!)
+  Author:
+    Justin, justin@urbaninsight.com
+    Urban Insight Inc, http://www.urbaninsight.com
+
+  Created:
+    20081106
+
+  Description:
+    his module automates API calls to TextMarks, a gateway service for sending
+    SMS messages to mobile phones.
+
+    TextMarks lets you register a textmark -- a keyword like MICROSOFT -- that
+    users text to 41411 to interact with your SMS site. The Textmarks API gateway
+    lets you subscribe to your Textmark and send broadcast messages to individual
+    subscribers or all subscribers.
+
+    To use this module, you will need to create a free textmark and user account at their website:
+    http://www.textmarks.com/create/
+
+    TextMarks FAQ:
+    http://www.textmarks.com/info/help/
+
+    TextMarks Developers API guide:
+    http://www.textmarks.com/dev/
+
+    Credit for the core class.php file goes to Textmarks:
+    http://lite.textmarks.com/dev/docs/api2client/php/
+    (Thanks!)
 */
 
 /**
  * Implementation of hook_perm()
  */
 function textmarks_perm() {
-	return array ('access textmarks content');
+  return array ('access textmarks content');
 }
 
 /**
@@ -52,36 +52,36 @@ function textmarks_perm() {
  */
 function textmarks_menu() {
 
-	$items = array();
-	
-	$items['admin/settings/textmarks'] = array(
-		'title' => t('TextMarks settings'),
-		'description' => t('Set TextMarks API information here.'),
-		'page callback' => 'drupal_get_form',
-		'page arguments' => array('textmarks_settings'),
-		'access arguments' => array('access administration pages'),
-		'type' => MENU_NORMAL_ITEM,
-	);
-	
-	$items['admin/content/textmarksubscribe'] = array(
-		'title' => t('TextMarks subscribe'),
-		'description' => t('Subscribe a mobile phone to your textmark.'),
-		'page callback' => 'textmarks_subscribe',
-		'page arguments' => array('textmarks_subscribe'),
-		'access arguments' => array('access administration pages'),
-		'type' => MENU_NORMAL_ITEM,
-	);
-	
-	$items['admin/content/textmarksend'] = array(
-		'title' => t('TextMarks send'),
-		'description' => t('Send a message to your subscribers.'),
-		'page callback' => 'textmarks_send',
-		'page arguments' => array('textmarks_send'),
-		'access arguments' => array('access administration pages'),
-		'type' => MENU_NORMAL_ITEM,
-	);
-	
-	return $items;
+  $items = array();
+
+  $items['admin/settings/textmarks'] = array(
+    'title' => t('TextMarks settings'),
+    'description' => t('Set TextMarks API information here.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textmarks_settings'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['admin/content/textmarksubscribe'] = array(
+    'title' => t('TextMarks subscribe'),
+    'description' => t('Subscribe a mobile phone to your textmark.'),
+    'page callback' => 'textmarks_subscribe',
+    'page arguments' => array('textmarks_subscribe'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['admin/content/textmarksend'] = array(
+    'title' => t('TextMarks send'),
+    'description' => t('Send a message to your subscribers.'),
+    'page callback' => 'textmarks_send',
+    'page arguments' => array('textmarks_send'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  return $items;
 }
 
 /**
@@ -89,165 +89,168 @@ function textmarks_menu() {
  */
 function textmarks_settings() {
 
-	$form['textmarks_textmark'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Textmark'),
-		'#default_value' => variable_get('textmarks_textmark',null),
-		'#size' => 45,
-		'#maxlength' => 45,
-		'#description' => t('The <a href="http://www.textmarks.com/info/help/#hlpsManaging" target="_blank">textmark</a> you registered.'),
-		'#required' => TRUE,
-	);
-
-	$form['textmarks_apikey'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Textmarks API key'),
-		'#default_value' => variable_get('textmarks_apikey',null),
-		'#size' => 45,
-		'#maxlength' => 45,
-		'#description' => t('The <a href="http://www.textmarks.com/dev/api/reg/" target="_blank">API key</a> you get from Textmakrs for your textmark.'),
-		'#required' => TRUE,
-	);
-	
-	$form['textmarks_username'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Textmarks username'),
-		'#default_value' => variable_get('textmarks_username',null),
-		'#size' => 45,
-		'#maxlength' => 45,
-		'#description' => t('Your login username. Usually your mobile number.'),
-		'#required' => TRUE,
-	);
-	
-	$form['textmarks_password'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Textmarks password'),
-		'#default_value' => variable_get('textmarks_password',null),
-		'#size' => 45,
-		'#maxlength' => 45,
-		'#description' => t('The password for your Textmark account.'),
-		'#required' => TRUE,
-	);
+  $form['textmarks_textmark'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Textmark'),
+    '#default_value' => variable_get('textmarks_textmark',null),
+    '#size' => 45,
+    '#maxlength' => 45,
+    '#description' => t('The <a href="http://www.textmarks.com/info/help/#hlpsManaging" target="_blank">textmark</a> you registered.'),
+    '#required' => TRUE,
+  );
+
+  $form['textmarks_apikey'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Textmarks API key'),
+    '#default_value' => variable_get('textmarks_apikey',null),
+    '#size' => 45,
+    '#maxlength' => 45,
+    '#description' => t('The <a href="http://www.textmarks.com/dev/api/reg/" target="_blank">API key</a> you get from Textmakrs for your textmark.'),
+    '#required' => TRUE,
+  );
+
+  $form['textmarks_username'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Textmarks username'),
+    '#default_value' => variable_get('textmarks_username',null),
+    '#size' => 45,
+    '#maxlength' => 45,
+    '#description' => t('Your login username. Usually your mobile number.'),
+    '#required' => TRUE,
+  );
+
+  $form['textmarks_password'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Textmarks password'),
+    '#default_value' => variable_get('textmarks_password',null),
+    '#size' => 45,
+    '#maxlength' => 45,
+    '#description' => t('The password for your Textmark account.'),
+    '#required' => TRUE,
+  );
 
-	return system_settings_form($form);
+  return system_settings_form($form);
 
 }
 
 /**
  * FAPI definition for the Textmarks send message form.
- * 
+ *
  * @see textmarks_send_form()
  * @see textmarks_needtosetup()
  * @see textmarks_send_form_submit()
  */
 function textmarks_send() {
-	$textmark = variable_get('textmarks_textmark',false);
-	$title = 'Send a Textmarks SMS Message';
-	
-	if($textmark) {
-		$output = "<p>Everyone subscribed to the textmark $textmark will receive this message instantly via SMS. Your message can be 120 characters if you have a free Textmarks plan, or 160 characters if you have a paid account.</p>";
-		$output .= drupal_get_form('textmarks_send_form');
-	}
-	else
-		$output = textmarks_needtosetup();
-	
-	return theme_box($title,$output);
+  $textmark = variable_get('textmarks_textmark',false);
+  $title = 'Send a Textmarks SMS Message';
+
+  if($textmark) {
+    $output = "<p>Everyone subscribed to the textmark $textmark will receive this message instantly via SMS. Your message can be 120 characters if you have a free Textmarks plan, or 160 characters if you have a paid account.</p>";
+    $output .= drupal_get_form('textmarks_send_form');
+  }
+  else
+    $output = textmarks_needtosetup();
+
+  return theme_box($title,$output);
 }
 
 /**
  * The actual form we show to the user to send a message to all subscribers of a textmark
  */
 function textmarks_send_form() {
-	$form['textmarks_message'] = array(
-		'#type' => 'textarea',
-		'#title' => t('Send a text message to all subscribers'),
-		'#default_value' => variable_get('textmarks_message',null),
-		'#rows' => 2, 
-		'#description' => t('Must be 120 characters max (or if you have a paid plan, 160.). The 40 characters are used for ads inserted by Textmark.'),
-		'#required' => TRUE,
-	);
-	
-	$form['textmarks_submit'] = array(
-		'#type' => 'submit',
-		'#title' => t('Send'),
-		'#value' => t('Send'),
-		'#required' => TRUE,
-	);
-	
-	return $form;
+  $form['textmarks_message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Send a text message to all subscribers'),
+    '#default_value' => variable_get('textmarks_message',null),
+    '#rows' => 2,
+    '#description' => t('Must be 120 characters max (or if you have a paid plan, 160.). The 40 characters are used for ads inserted by Textmark.'),
+    '#required' => TRUE,
+  );
+
+  $form['textmarks_submit'] = array(
+    '#type' => 'submit',
+    '#title' => t('Send'),
+    '#value' => t('Send'),
+    '#required' => TRUE,
+  );
+
+  return $form;
 }
 
 /**
  * Our attempt at sending the message the user submits via the Textmarks API
  */
 function textmarks_send_form_submit($form_id, $form_values) {
-	
-	/**
-	 * The main class we use to make the actual calls to the API
-	 * 
-	 * @see textmarks_send_form_submit()
-	 * @see textmarks_subscribe_form_submit()
-	 */
-	require_once('class.php');
-	
-	if(!textmarks_curl_installed()) {
-		form_set_error('textmarks_message', t('You need to install cURL for PHP.'));
-		return false;
-	}
-	
-	try {			
-		$msg = $form_values['values']['textmarks_message'];
-		$tmapi = new TextMarksAPIClient_Messaging( variable_get('textmarks_apikey',null), variable_get('textmarks_username',null), variable_get('textmarks_password',null) );
-		$tmapi->postAlert(variable_get('textmarks_textmark',null),$msg);
-		drupal_set_message("Message <em>$msg</em> sent successfully!");
-	}
-	catch (Exception $e) {
-		form_set_error('textmarks_message', t('There was an error with api call. Here is what the API said:<br />' . $e->getMessage() . '<br /><br />Did you add the api key, username, password and textmark in the <a href="../settings/textmarks/">settings</a> screen?'));
-	}
+
+  /**
+   * The main class we use to make the actual calls to the API
+   *
+   * @see textmarks_send_form_submit()
+   * @see textmarks_subscribe_form_submit()
+   */
+  require_once('class.php');
+
+  if(!textmarks_curl_installed()) {
+    form_set_error('textmarks_message', t('You need to install cURL for PHP.'));
+    return false;
+  }
+
+  try {
+    $msg = $form_values['values']['textmarks_message'];
+    $tmapi = new TextMarksV2APIClient( variable_get('textmarks_apikey',null), variable_get('textmarks_username',null), variable_get('textmarks_password',null) );
+    $tmapi->call('GroupLeader', 'broadcast_message', array(
+      'tm' => variable_get('textmarks_textmark',null),
+      'msg' => $msg,
+    ));
+    drupal_set_message("Message <em>$msg</em> sent successfully!");
+  }
+  catch (Exception $e) {
+    form_set_error('textmarks_message', t('There was an error with api call. Here is what the API said:<br />' . $e->getMessage() . '<br /><br />Did you add the api key, username, password and textmark in the <a href="../settings/textmarks/">settings</a> screen?'));
+  }
 }
 
 /**
  * FAPI definition for the Textmarks subscribe a modile number form.
- * 
+ *
  * @see textmarks_needtosetup()
  * @see textmarks_subscribe_form()
  * @see textmarks_subscribe_form_submit
  */
 function textmarks_subscribe() {
-	$textmark = variable_get('textmarks_textmark',false);
-	$title = 'Subscribe a mobile number';
-	
-	if($textmark) {
-		$output = "<p>Subscribe a mobile number to your textmark <em>$textmark</em>. Subscribers will receive a confirmation text message they must reply to become subscribers.</p>";
-		$output .= drupal_get_form('textmarks_subscribe_form');
-	}
-	else
-		$output = textmarks_needtosetup();
-	
-	return theme_box($title,$output);
+  $textmark = variable_get('textmarks_textmark',false);
+  $title = 'Subscribe a mobile number';
+
+  if($textmark) {
+    $output = "<p>Subscribe a mobile number to your textmark <em>$textmark</em>. Subscribers will receive a confirmation text message they must reply to become subscribers.</p>";
+    $output .= drupal_get_form('textmarks_subscribe_form');
+  }
+  else
+    $output = textmarks_needtosetup();
+
+  return theme_box($title,$output);
 }
 
 /**
  * The actual form we show to the user to subscribe a mobile number to their registered textmark
  */
 function textmarks_subscribe_form() {
-	$form['textmarks_phone'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Subscribe a mobile number to your textmark ' . variable_get('textmarks_textmark','[You need to edit settings]')),
-		'#default_value' => variable_get('textmarks_phone',null),
-		'#rows' => 2, 
-		'#description' => t('A standard US phone number.'),
-		'#required' => TRUE,
-	);
-	
-	$form['textmarks_submit'] = array(
-		'#type' => 'submit',
-		'#title' => t('Send'),
-		'#value' => t('Subscribe'),
-		'#required' => TRUE,
-	);
-	
-	return $form;
+  $form['textmarks_phone'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subscribe a mobile number to your textmark ' . variable_get('textmarks_textmark','[You need to edit settings]')),
+    '#default_value' => variable_get('textmarks_phone',null),
+    '#rows' => 2,
+    '#description' => t('A standard US phone number.'),
+    '#required' => TRUE,
+  );
+
+  $form['textmarks_submit'] = array(
+    '#type' => 'submit',
+    '#title' => t('Send'),
+    '#value' => t('Subscribe'),
+    '#required' => TRUE,
+  );
+
+  return $form;
 }
 
 /**
@@ -255,40 +258,43 @@ function textmarks_subscribe_form() {
  */
 function textmarks_subscribe_form_submit($form_id, $form_values) {
 
-	/**
-	 * The main class we use to make the actual calls to the API
-	 * 
-	 * @see textmarks_send_form_submit()
-	 * @see textmarks_subscribe_form_submit()
-	 */
-	require_once('class.php');
-
-	if(!textmarks_curl_installed()) {
-		form_set_error('textmarks_message', t('You need to install cURL for PHP.'));
-		return false;
-	}
-
-	try {	
-		$number = $form_values['values']['textmarks_phone'];
-		$tmapi = new TextMarksAPIClient_Messaging( variable_get('textmarks_apikey',null), variable_get('textmarks_username',null), variable_get('textmarks_password',null) );
-		$tmapi->subscribe(variable_get('textmarks_textmark',null), $number);
-		drupal_set_message("Mobile number <em>$number</em> subscribe request sent successfully!");
-	}
-	catch (Exception $e) {
-		form_set_error('textmarks_message', t('There was an error with api call. Here is what the API said:<br />' . $e->getMessage() . '<br /><br />Did you add the api key, username, password and textmark in the <a href="../settings/textmarks/">settings</a> screen?'));
-	}
+  /**
+   * The main class we use to make the actual calls to the API
+   *
+   * @see textmarks_send_form_submit()
+   * @see textmarks_subscribe_form_submit()
+   */
+  require_once('class.php');
+
+  if(!textmarks_curl_installed()) {
+    form_set_error('textmarks_message', t('You need to install cURL for PHP.'));
+    return false;
+  }
+
+  try {
+    $number = $form_values['values']['textmarks_phone'];
+    $tmapi = new TextMarksV2APIClient( variable_get('textmarks_apikey',null) );
+    $tmapi->call('Anybody', 'invite_to_group', array(
+      'tm' => variable_get('textmarks_textmark',null),
+      'user' => $number,
+    ));
+    drupal_set_message("Mobile number <em>$number</em> subscribe request sent successfully!");
+  }
+  catch (Exception $e) {
+    form_set_error('textmarks_message', t('There was an error with api call. Here is what the API said:<br />' . $e->getMessage() . '<br /><br />Did you add the api key, username, password and textmark in the <a href="../settings/textmarks/">settings</a> screen?'));
+  }
 }
 
 /**
  * Returns a nicely formatted error message to the _send and _subscribe forms when the user hasn't saved the API login settings.
  */
 function textmarks_needtosetup() {
-	return '<p>You need setup your textmark <a href="textmarks/">settings</a> before you can send message.</p>';
+  return '<p>You need setup your textmark <a href="textmarks/">settings</a> before you can send message.</p>';
 }
 
 /**
  * Checks if cURL is installed on the system
  */
 function textmarks_curl_installed() {
-	return function_exists('curl_exec');
+  return function_exists('curl_exec');
 }
\ No newline at end of file
