]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/lib/lrddmethod.php
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
[quix0rs-gnu-social.git] / plugins / LRDD / lib / lrddmethod.php
1 <?php
2 /**
3  * Abstract class for LRDD discovery methods
4  *
5  * Objects that extend this class can retrieve an array of
6  * resource descriptor links for the URI. The array consists
7  * of XML_XRD_Element_Link elements.
8  *
9  * @category  Discovery
10  * @package   StatusNet
11  * @author    James Walker <james@status.net>
12  * @copyright 2010 StatusNet, Inc.
13  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
14  * @link      http://status.net/
15  */
16 abstract class LRDDMethod
17 {
18     protected $xrd = null;
19
20     public function __construct() {
21         $this->xrd = new XML_XRD();
22     }
23
24     /**
25      * Discover interesting info about the URI
26      *
27      * @param string $uri URI to inquire about
28      *
29      * @return array of XML_XRD_Element_Link elements to discovered resource descriptors
30      */
31     abstract public function discover($uri);
32
33     protected function fetchUrl($url, $method=HTTPClient::METHOD_GET)
34     {
35         $client  = new HTTPClient();
36
37         // GAAHHH, this method sucks! How about we make a better HTTPClient interface?
38         switch ($method) {
39         case HTTPClient::METHOD_GET:
40             $response = $client->get($url);
41             break;
42         case HTTPClient::METHOD_HEAD:
43             $response = $client->head($url);
44             break;
45         default:
46             throw new Exception('Bad HTTP method.');
47         }
48
49         if ($response->getStatus() != 200) {
50             throw new Exception('Unexpected HTTP status code.');
51         }
52
53         return $response;
54     }
55 }