1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Openstreetmap
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die();
11
12 use Joomla\Registry\Registry;
13
14 /**
15 * Joomla Platform class for generating Openstreetmap API access token.
16 *
17 * @since 13.1
18 * @deprecated 4.0 Use the `joomla/openstreetmap` package via Composer instead
19 */
20 class JOpenstreetmapOauth extends JOAuth1Client
21 {
22 /**
23 * Options for the JOpenstreetmapOauth object.
24 *
25 * @var Registry
26 * @since 13.1
27 */
28 protected $options;
29
30 /**
31 * Constructor.
32 *
33 * @param Registry $options JOpenstreetmapOauth options object.
34 * @param JHttp $client The HTTP client object.
35 * @param JInput $input The input object
36 *
37 * @since 13.1
38 */
39 public function __construct(Registry $options = null, JHttp $client = null, JInput $input = null)
40 {
41 $this->options = isset($options) ? $options : new Registry;
42
43 $this->options->def('accessTokenURL', 'http://www.openstreetmap.org/oauth/access_token');
44 $this->options->def('authoriseURL', 'http://www.openstreetmap.org/oauth/authorize');
45 $this->options->def('requestTokenURL', 'http://www.openstreetmap.org/oauth/request_token');
46
47 /*
48 $this->options->def('accessTokenURL', 'http://api06.dev.openstreetmap.org/oauth/access_token');
49 $this->options->def('authoriseURL', 'http://api06.dev.openstreetmap.org/oauth/authorize');
50 $this->options->def('requestTokenURL', 'http://api06.dev.openstreetmap.org/oauth/request_token');
51 */
52
53 // Call the JOauth1Client constructor to setup the object.
54 parent::__construct($this->options, $client, $input, null, '1.0');
55 }
56
57 /**
58 * Method to verify if the access token is valid by making a request to an API endpoint.
59 *
60 * @return boolean Returns true if the access token is valid and false otherwise.
61 *
62 * @since 13.1
63 */
64 public function verifyCredentials()
65 {
66 return true;
67 }
68
69 /**
70 * Method to validate a response.
71 *
72 * @param string $url The request URL.
73 * @param JHttpResponse $response The response to validate.
74 *
75 * @return void
76 *
77 * @since 13.1
78 * @throws DomainException
79 */
80 public function validateResponse($url, $response)
81 {
82 if ($response->code != 200)
83 {
84 $error = htmlspecialchars($response->body, ENT_COMPAT, 'UTF-8');
85
86 throw new DomainException($error, $response->code);
87 }
88 }
89 }
90