1 | <?php |
||
25 | class Communique { |
||
26 | |||
27 | /** |
||
28 | * The base path of the API. All other API paths will be used relative to this |
||
29 | * @var String |
||
30 | */ |
||
31 | private $_BASE_URL; |
||
32 | |||
33 | /** |
||
34 | * An array of interceptors used for processing the requests |
||
35 | * @var Array |
||
36 | */ |
||
37 | private $_interceptors = array(); |
||
38 | |||
39 | /** |
||
40 | * An implementation of \Communique\HTTPClient |
||
41 | * @var \Communique\HTTPClient |
||
42 | */ |
||
43 | private $_http; |
||
44 | |||
45 | /** |
||
46 | * Constructs Communique REST library. |
||
47 | * @param String $base_url The base URL of the API you wish to make requests to. All other paths referenced will be treated as relative to this. |
||
48 | * @param array $interceptors An array of any interceptors you wish to use to modify the request. An interceptor could do anything from JSON parsing to OAuth request signing. |
||
49 | * @param \Communique\HTTPClient $http_client The HTTP client you wish to make the request with |
||
50 | * @throws \Communique\CommuniqueException |
||
51 | */ |
||
52 | public function __construct($base_url = '', array $interceptors = array(), $http_client = null) { |
||
68 | |||
69 | /** |
||
70 | * Makes the HTTP request using the chosen HTTP client. |
||
71 | * @param \Communique\RESTClientRequest $request A RESTClientRequest object encapsulating the request |
||
72 | * @param callable $debug A debugging callback to be run after the request has finished. This function is expected to accept two parameters, \Communique\RESTClientRequest and \Communique\RESTClientResponse |
||
73 | * @return \Communique\RESTClientResponse A RESTClientResponse object encapsulating the response |
||
74 | */ |
||
75 | protected function _call(\Communique\RESTClientRequest $request, $debug = null) { |
||
88 | |||
89 | /** |
||
90 | * Make an HTTP GET request |
||
91 | * @param String $url The API to make the request to |
||
92 | * @param mixed $payload The request payload (this will be url encoded and added as query string parameters) |
||
93 | * @param array $headers Any headers you want to add to the request(optional) |
||
94 | * @param callable $debug A function to be used for request debugging. |
||
95 | * This function should accept two parameters, one for the request object one for the response object. |
||
96 | * @return \Communique\RESTClientResponse REST response encapsulation object |
||
97 | */ |
||
98 | public function get($url, $payload = array(), array $headers = array(), $debug = null) { |
||
102 | |||
103 | /** |
||
104 | * Make an HTTP PUT request |
||
105 | * @param String $url The API to make the request to |
||
106 | * @param mixed $payload The payload of the request(any data you wish to send across) |
||
107 | * @param array $headers Any headers you want to add to the request(optional) |
||
108 | * @param callable $debug A function to be used for request debugging. |
||
109 | * This function should accept two parameters, one for the request object one for the response object. |
||
110 | * @return \Communique\RESTClientResponse REST response encapsulation object |
||
111 | */ |
||
112 | public function put($url, $payload, array $headers = array(), $debug = null) { |
||
116 | |||
117 | /** |
||
118 | * Make an HTTP POST request |
||
119 | * @param String $url The API to make the request to |
||
120 | * @param mixed $payload The payload of the request(any data you wish to send across) |
||
121 | * @param array $headers Any headers you want to add to the request(optional) |
||
122 | * @param callable $debug A function to be used for request debugging. |
||
123 | * This function should accept two parameters, one for the request object one for the response object. |
||
124 | * @return \Communique\RESTClientResponse REST response encapsulation object |
||
125 | */ |
||
126 | public function post($url, $payload, array $headers = array(), $debug = null) { |
||
130 | |||
131 | /** |
||
132 | * Make an HTTP DELETE request |
||
133 | * @param String $url The API to make the request to |
||
134 | * @param mixed $payload The payload of the request(any data you wish to send across) |
||
135 | * @param array $headers Any headers you want to add to the request(optional) |
||
136 | * @param callable $debug A function to be used for request debugging. |
||
137 | * This function should accept two parameters, one for the request object one for the response object. |
||
138 | * @return \Communique\RESTClientResponse REST response encapsulation object |
||
139 | */ |
||
140 | public function delete($url, $payload = array(), array $headers = array(), $debug = null) { |
||
144 | } |