forked from oSoc13/Westtoer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetcher.php
46 lines (34 loc) · 1.12 KB
/
fetcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* Fetcher
* @author: Ah-Lun Tang ([email protected])
* @license: AGPLv3
*/
# loading vendor components
require_once 'vendor/autoload.php';
use Doctrine\Common\Cache\ArrayCache;
use Guzzle\Http\Client;
use Guzzle\Cache\DoctrineCacheAdapter;
use Guzzle\Plugin\Cache\CachePlugin;
date_default_timezone_set('UTC');
class Fetcher {
private $client;
private $user;
private $pass;
function __construct($uri, $user, $pass) {
$this->client = new Client($uri, array( 'params.cache.override_ttl' => 3600,
'params.cache.revalidate' => 'skip'
));
# add caching object.
$this->client->addSubscriber(new CachePlugin(new DoctrineCacheAdapter(new ArrayCache()), true));
$this->user = $user;
$this->pass = $pass;
}
function get($resource){
# get request object
$request = $this->client->get($resource)->setAuth($this->user, $this->pass);
# get response
$response = $request->send();
return json_decode($response->getBody(),true);
}
}