+ /**
+ * Inject API key into query before sending out...
+ *
+ * @param string $url
+ * @return HTTPResponse
+ */
+ protected function query($url)
+ {
+ // http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/shorten
+ $params = http_build_query(array(
+ 'login' => $this->getLogin(),
+ 'apiKey' => $this->getApiKey()), '', '&');
+ $serviceUrl = sprintf($this->serviceUrl, urlencode($url)) . '&' . $params;
+
+ $request = HTTPClient::start();
+ return $request->get($serviceUrl);
+ }
+
+ /**
+ * JSON decode for API result
+ */
+ protected function decode($url, $response)
+ {
+ $msg = "bit.ly returned unknown response with unknown message for $url";
+ if ($response->isOk()) {
+ $body = $response->getBody();
+ common_log(LOG_INFO, $body);
+ $json = json_decode($body, true);
+ if ($json['status_code'] == 200) {
+ if (isset($json['data']['url'])) {
+ common_log(LOG_INFO, "bit.ly returned ".$json['data']['url']." as short URL for $url");
+ return $json['data']['url'];
+ }
+ $msg = "bit.ly returned ".$json['status_code']." response, but didn't find expected URL $url in $body";
+ }else{
+ $msg = "bit.ly returned ".$json['status_code']." response with ".$json['status_txt']." for $url";
+ }
+ }
+ common_log(LOG_ERR, $msg);
+ return null;
+ }
+
+ function onPluginVersion(array &$versions)