summaryrefslogtreecommitdiff
path: root/plugins/YammerImport/sn_yammerclient.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-09-21 17:08:40 -0700
committerBrion Vibber <brion@pobox.com>2010-09-28 07:44:21 -0700
commite357e13d69c75a55369c6495d09792f3e19269e2 (patch)
treedba5bf176ff174bda74fc659ab5d05cd4c848a65 /plugins/YammerImport/sn_yammerclient.php
parentb18c7ee3eb4b9615636f79327e0d09b85393a900 (diff)
Image file attachment support for Yammer import
Diffstat (limited to 'plugins/YammerImport/sn_yammerclient.php')
-rw-r--r--plugins/YammerImport/sn_yammerclient.php51
1 files changed, 39 insertions, 12 deletions
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 {
@@ -65,6 +74,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.
*
* @param string $method
@@ -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");