-
Notifications
You must be signed in to change notification settings - Fork 0
/
freeAgent.class.php
47 lines (36 loc) · 1.23 KB
/
freeAgent.class.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
class freeAgent
{
const API_URL = 'https://api.freeagent.com/v2/';
protected $token;
protected $ch;
public function __construct($token)
{
$this->token = $token;
$this->ch = curl_init();
$this->cache = $cache;
}
function request($url, $method='GET', $type='application/json')
{
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($this->ch, CURLOPT_USERAGENT, 'PHP Script');
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer $this->token",
"Accept: $type",
"Content-type: $type",
));
return curl_exec($this->ch);
}
function getTimeslips($from_date=null, $to_date=null)
{
$response = json_decode($this->request(self::API_URL.'timeslips'.(is_null($from_date)?'':"?from_date=$from_date&to_date=$to_date")));
return $response->timeslips;
}
function getProject($project_id)
{
$response = json_decode($this->request(self::API_URL.'/projects/'.$project_id));
return $response->project;
}
}