try/catch with some slight hacks to deal with no error messages available
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 20 Jul 2009 22:14:17 +0000 (18:14 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 20 Jul 2009 22:15:03 +0000 (18:15 -0400)
with our Http_Client library.

framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Oauth.php
framework/Service_Twitter/lib/Horde/Service/Twitter/Statuses.php
framework/Service_Twitter/lib/Horde/Service/Twitter/Timeline.php [deleted file]

index 0adecbc..fa58c71 100644 (file)
@@ -27,7 +27,14 @@ class Horde_Service_Twitter_Request_Oauth extends Horde_Service_Twitter_Request
                        $this->_twitter->auth->oauth,
                        $this->_twitter->auth->getAccessToken());
         $client = new Horde_Http_Client();
-        $response = $client->get($url, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
+        try {
+            $response = $client->get($url, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
+        } catch (Horde_Http_Client_Exception $e) {
+            // Currently we can't obtain any information regarding the resposne
+            // when a 4xx/5xx response is rec'd due to fopen() failing.
+            // For now, fake it and return the error from the exception.
+            return '{"request":"' . $url . '", "error:", "' . $e->getMessage() . '"}';
+        }
 
         return $response->getBody();
     }
@@ -40,7 +47,14 @@ class Horde_Service_Twitter_Request_Oauth extends Horde_Service_Twitter_Request
                        $this->_twitter->auth->getAccessToken());
 
         $client = new Horde_Http_Client();
-        $response = $client->post($url, $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
+        try {
+            $response = $client->post($url, $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
+        } catch (Horde_Http_Client_Exception $e) {
+            // Currently we can't obtain any information regarding the resposne
+            // when a 4xx/5xx response is rec'd due to fopen() failing.
+            // For now, fake it and return the error from the exception.
+            return '{"request":"' . $url . '", "error:", "' . $e->getMessage() . '"}';
+        }
 
         return $response->getBody();
     }
index ee7628c..3a4a998 100644 (file)
@@ -68,4 +68,11 @@ class Horde_Service_Twitter_Statuses
 
         return $this->_twitter->request->post($url, $params);
     }
+
+    public function friendsTimeline($params = array())
+    {
+        $url = $this->_endpoint . 'friends_timeline.' . $this->_format;
+        return $this->_twitter->request->get($url);
+    }
+
 }
diff --git a/framework/Service_Twitter/lib/Horde/Service/Twitter/Timeline.php b/framework/Service_Twitter/lib/Horde/Service/Twitter/Timeline.php
deleted file mode 100644 (file)
index b3d9bbc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<?php