Completed
Pull Request — master (#694)
by Georg
25:17
created

ProxyController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A proxy() 0 17 2
1
<?php
2
/**
3
 * ownCloud - Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2016 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
use GuzzleHttp\Exception\ClientException;
25
use OCA\Calendar\Http\StreamResponse;
26
use OCP\AppFramework\Http\JSONResponse;
27
28
use OCP\AppFramework\Controller;
29
use OCP\Http\Client\IClientService;
30
use OCP\IRequest;
31
32
class ProxyController extends Controller {
33
34
	/**
35
	 * @var IClientService
36
	 */
37
	protected $client;
38
39
	/**
40
	 * @param string $appName
41
	 * @param IRequest $request an instance of the request
42
	 * @param IClientService $client
43
	 */
44
	public function __construct($appName, IRequest $request,
45
								IClientService $client) {
46
		parent::__construct($appName, $request);
47
		$this->client = $client;
48
	}
49
50
	/**
51
	 * @NoAdminRequired
52
	 *
53
	 * @param $url
54
	 * @return StreamResponse|JSONResponse
55
	 */
56
	public function proxy($url) {
57
		$client = $this->client->newClient();
58
		try {
59
			$clientResponse = $client->get($url, [
60
				'stream' => true,
61
			]);
62
			$response = new StreamResponse($clientResponse->getBody());
63
			$response->setHeaders([
64
				'Content-Type' => 'text/calendar',
65
			]);
66
		} catch (ClientException $e) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
67
			$error_code = $e->getResponse()->getStatusCode();
68
			$response = new JSONResponse();
69
			$response->setStatus($error_code);
70
		}
71
		return $response;
72
	}
73
}
74