Permalink
Browse files

Added current code to the repository.

  • Loading branch information...
jstump
jstump committed Apr 12, 2008
0 parents commit 2a9c6086b52a880b6d4a35f05e7b958cbc166415
Showing with 1,706 additions and 0 deletions.
  1. +170 −0 Services/Twitter.php
  2. +70 −0 Services/Twitter/Account.php
  3. +213 −0 Services/Twitter/Common.php
  4. +152 −0 Services/Twitter/DirectMessages.php
  5. +107 −0 Services/Twitter/Exception.php
  6. +60 −0 Services/Twitter/Favorites.php
  7. +92 −0 Services/Twitter/Friendships.php
  8. +60 −0 Services/Twitter/Notifications.php
  9. +207 −0 Services/Twitter/Statuses.php
  10. +94 −0 Services/Twitter/Users.php
  11. +24 −0 tests/005-services-twitter-statuses-public-timeline.phpt
  12. +24 −0 tests/006-services-twitter-statuses-friends-timeline.phpt
  13. +24 −0 tests/007-services-twitter-statuses-user-timeline.phpt
  14. +15 −0 tests/010-services-twitter-statuses-show.phpt
  15. +20 −0 tests/015-services-twitter-statuses-replies.phpt
  16. +23 −0 tests/020-services-twitter-statuses-update.phpt
  17. +28 −0 tests/025-services-twitter-statuses-destroy.phpt
  18. +39 −0 tests/026-services-twitter-statuses-friends.phpt
  19. +30 −0 tests/027-services-twitter-statuses-followers.phpt
  20. +30 −0 tests/028-services-twitter-statuses-featured.phpt
  21. +19 −0 tests/030-services-twitter-exception.phpt
  22. +23 −0 tests/100-services-twitter-users-show.phpt
  23. +39 −0 tests/200-services-twitter-direct-messages.phpt
  24. +24 −0 tests/205-services-twitter-direct-messages-sent.phpt
  25. +16 −0 tests/210-services-twitter-direct-messages-new.phpt
  26. +24 −0 tests/215-services-twitter-direct-messages-destroy.phpt
  27. +16 −0 tests/300-services-twitter-friendships-create.phpt
  28. +16 −0 tests/305-services-twitter-friendships-destroy.phpt
  29. +15 −0 tests/400-services-twitter-account-verify-credentials.phpt
  30. +32 −0 tests/tests-config.php.example
@@ -0,0 +1,170 @@
+<?php
+
+/**
+ * An interface for Twitter's HTTP API
+ *
+ * PHP version 5.1.0+
+ *
+ * Copyright (c) 2007, The PEAR Group
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the The PEAR Group nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_TinyURL
+ * @author Joe Stump <joe@joestump.net>
+ * @copyright 1997-2007 Joe Stump <joe@joestump.net>
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id$
+ * @link http://twitter.com/help/api
+ * @link http://twitter.com
+ */
+
+require_once 'Services/Twitter/Exception.php';
+require_once 'Services/Twitter/Common.php';
+
+/**
+ * Services_Twitter
+ *
+ * <code>
+ * <?php
+ * require_once 'Services/Twitter.php';
+ *
+ * $username = 'You_Username';
+ * $password = 'Your_Password';
+ *
+ * try {
+ * $twitter = new Services_TinyURL($username, $password);
+ * $msg = $twitter->statuses->update("I'm coding with PEAR right now!");
+ * print_r($msg); // Should be a SimpleXMLElement structure
+ * } catch (Services_Twitter_Exception $e) {
+ * echo $e->getMessage();
+ * }
+ * ?>
+ * </code>
+ *
+ * @category Services
+ * @package Services_Twitter
+ * @author Joe Stump <joe@joestump.net>
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://twitter.com
+ */
+class Services_Twitter extends Services_Twitter_Common
+{
+ /**
+ * Twitter API error codes
+ *
+ * @global integer ERROR_UNKNOWN An unknown error occurred
+ * @global integer ERROR_REQUEST Bad request sent
+ * @global integer ERROR_AUTH Not authorized to do action
+ * @global integer ERROR_FORBIDDEN Forbidden from doing action
+ * @global integer ERROR_NOT_FOUND Item requested not found
+ * @global integer ERROR_INTERNAL Internal Twitter error
+ * @global integer ERROR_DOWN Twitter is down
+ * @global integer ERROR_UNAVAILABLE API is overloaded
+ */
+ const ERROR_UNKNOWN = 1;
+ const ERROR_REQUEST = 400;
+ const ERROR_AUTH = 401;
+ const ERROR_FORBIDDEN = 403;
+ const ERROR_NOT_FOUND = 404;
+ const ERROR_INTERNAL = 500;
+ const ERROR_DOWN = 502;
+ const ERROR_UNAVAILABLE = 503;
+
+ /**
+ * Public URI of Twitter's API
+ *
+ * @var string $uri URI of Twitter API
+ * @see Services_Twitter_Common::sendRequest()
+ */
+ static public $uri = 'http://twitter.com';
+
+ /**
+ * Supported areas / methods of Twitter's API
+ *
+ * @var array $methods
+ * @see Services_Twitter::__get()
+ */
+ static protected $methods = array(
+ 'statuses' => 'Statuses',
+ 'users' => 'Users',
+ 'direct_messages' => 'DirectMessages',
+ 'friendships' => 'Friendships',
+ 'account' => 'Account'
+ );
+
+ /**
+ * Instances of Twitter methods
+ *
+ * @var array $instances
+ * @see Services_Twitter::__get(), Services_Twitter::$methods
+ */
+ static protected $instances = array();
+
+ /**
+ * Lazily load Twitter API drivers
+ *
+ * @param string $var Method to load
+ *
+ * @throws Services_Twitter_Exception
+ * @return object Instance of API driver
+ * @see Services_Twitter::factory()
+ */
+ public function __get($var)
+ {
+ if (!isset(self::$methods[$var])) {
+ throw new Services_Twitter_Exception(
+ 'Method (' . $var . ') is not implemented'
+ );
+ }
+
+ return $this->factory(self::$methods[$var]);
+ }
+
+ /**
+ * Instantiate API driver
+ *
+ * @param string $method API driver to load
+ *
+ * @return object Instance of API driver
+ */
+ protected function factory($method)
+ {
+ if (isset(self::$instances[$method])) {
+ return self::$instances[$method];
+ }
+
+ $file = 'Services/Twitter/' . $method . '.php';
+ include_once $file;
+
+ $class = 'Services_Twitter_' . $method;
+ self::$instances[$method] = new $class($this->user, $this->pass);
+ return self::$instances[$method];
+ }
+}
+
+?>
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * An interface for Twitter's HTTP API
+ *
+ * PHP version 5.1.0+
+ *
+ * Copyright (c) 2007, The PEAR Group
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the The PEAR Group nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_TinyURL
+ * @author Joe Stump <joe@joestump.net>
+ * @copyright 1997-2007 Joe Stump <joe@joestump.net>
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id$
+ * @link http://twitter.com/help/api
+ * @link http://twitter.com
+ */
+
+/**
+ * Services_Twitter_Account
+ *
+ * @category Services
+ * @package Services_Twitter
+ * @author Joe Stump <joe@joestump.net>
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://twitter.com
+ */
+class Services_Twitter_Account extends Services_Twitter_Common
+{
+ /**
+ * Verify a user's credentials
+ *
+ * @return boolean
+ * @see Services_Twitter_Common::sendRequest()
+ */
+ public function verify_credentials()
+ {
+ $res = $this->sendRequest('/account/verify_credentials');
+ return ((string)$res === 'true');
+ }
+}
+
+?>
Oops, something went wrong.

0 comments on commit 2a9c608

Please sign in to comment.