-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestclient.php
71 lines (53 loc) · 2.06 KB
/
restclient.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Siesta;
require_once('request.php');
require_once('restutils.php');
interface SiestaRestClient {
public function get($url, $data);
public function post($url, $data);
public function put($url, $data);
public function delete($url, $data);
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';
}
class restclient implements SiestaRestClient {
protected $config = null;
protected $request;
public function __construct($config = array()) {
$this->config = array_merge(
array(
'multipart' => false,
'curl_opts' => array(),
'oauth_opts' => array(),
'headers' => array()
),
$config
);
$this->setup_request();
}
public function get($url = null,$data = null) {
$this->request->method = self::METHOD_GET;
return $this->rest($url,$data);
}
public function post($url = null,$data = null) {
$this->request->method = self::METHOD_POST;
return $this->rest($url,$data);
}
public function put($url = null,$data = null) {
$this->request->method = self::METHOD_PUT;
return $this->rest($url,$data);
}
public function delete($url = null,$data = null) {
$this->request->method = self::METHOD_DELETE;
return $this->rest($url,$data);
}
private function rest($url,$data) {
$data = \Siesta\Utils\util::format_data($data,'json');
return $this->request->execute($url,$data);
}
private function setup_request() {
$this->request = new \Siesta\request($this->config);
}
}