From e357e13d69c75a55369c6495d09792f3e19269e2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 21 Sep 2010 17:08:40 -0700 Subject: Image file attachment support for Yammer import --- plugins/YammerImport/sn_yammerclient.php | 51 ++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'plugins/YammerImport/sn_yammerclient.php') diff --git a/plugins/YammerImport/sn_yammerclient.php b/plugins/YammerImport/sn_yammerclient.php index 21caa7b7c..f7382abae 100644 --- a/plugins/YammerImport/sn_yammerclient.php +++ b/plugins/YammerImport/sn_yammerclient.php @@ -38,25 +38,34 @@ class SN_YammerClient } /** - * Make an HTTP hit with OAuth headers and return the response body on success. + * Make an HTTP GET request with OAuth headers and return an HTTPResponse + * with the returned body and codes. * - * @param string $path URL chunk for the API method - * @param array $params - * @return array + * @param string $url + * @return HTTPResponse * - * @throws Exception for HTTP error + * @throws Exception on low-level network error */ - protected function fetch($path, $params=array()) + protected function httpGet($url) { - $url = $this->apiBase . '/' . $path; - if ($params) { - $url .= '?' . http_build_query($params, null, '&'); - } $headers = array('Authorization: ' . $this->authHeader()); $client = HTTPClient::start(); - $response = $client->get($url, $headers); + return $client->get($url, $headers); + } + /** + * Make an HTTP GET request with OAuth headers and return the response body + * on success. + * + * @param string $url + * @return string + * + * @throws Exception on low-level network or HTTP error + */ + public function fetchUrl($url) + { + $response = $this->httpGet($url); if ($response->isOk()) { return $response->getBody(); } else { @@ -64,6 +73,24 @@ class SN_YammerClient } } + /** + * Make an HTTP hit with OAuth headers and return the response body on success. + * + * @param string $path URL chunk for the API method + * @param array $params + * @return string + * + * @throws Exception on low-level network or HTTP error + */ + protected function fetchApi($path, $params=array()) + { + $url = $this->apiBase . '/' . $path; + if ($params) { + $url .= '?' . http_build_query($params, null, '&'); + } + return $this->fetchUrl($url); + } + /** * Hit the main Yammer API point and decode returned JSON data. * @@ -75,7 +102,7 @@ class SN_YammerClient */ protected function api($method, $params=array()) { - $body = $this->fetch("api/v1/$method.json", $params); + $body = $this->fetchApi("api/v1/$method.json", $params); $data = json_decode($body, true); if (!$data) { throw new Exception("Invalid JSON response from Yammer API"); -- cgit v1.2.3-54-g00ecf