1 | <?php |
||
15 | class Request |
||
16 | { |
||
17 | /** |
||
18 | * Contains QuickPay_Client instance |
||
19 | * |
||
20 | * @access protected |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * __construct function. |
||
26 | * |
||
27 | * Instantiates the object |
||
28 | * |
||
29 | * @access public |
||
30 | */ |
||
31 | 6 | public function __construct($client) |
|
35 | |||
36 | /** |
||
37 | * GET function. |
||
38 | * |
||
39 | * Performs an API GET request |
||
40 | * |
||
41 | * @access public |
||
42 | * @param string $path |
||
43 | * @param array $query |
||
44 | * @return Response |
||
45 | */ |
||
46 | 4 | public function get($path, $query = array()) |
|
47 | { |
||
48 | // Add query parameters to $path? |
||
49 | 4 | if (!empty($query)) { |
|
50 | if (strpos($path, '?') === false) { |
||
51 | $path .= '?' . http_build_query($query, '', '&'); |
||
52 | } else { |
||
53 | $path .= ini_get('arg_separator.output') . http_build_query($query, '', '&'); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | // Set the request params |
||
58 | 4 | $this->setUrl($path); |
|
59 | |||
60 | // Start the request and return the response |
||
61 | 4 | return $this->execute('GET'); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * POST function. |
||
66 | * |
||
67 | * Performs an API POST request |
||
68 | * |
||
69 | * @access public |
||
70 | * @return Response |
||
71 | */ |
||
72 | 2 | public function post($path, $form = array()) |
|
80 | |||
81 | /** |
||
82 | * PUT function. |
||
83 | * |
||
84 | * Performs an API PUT request |
||
85 | * |
||
86 | * @access public |
||
87 | * @return Response |
||
88 | */ |
||
89 | public function put($path, $form = array()) |
||
97 | |||
98 | /** |
||
99 | * PATCH function. |
||
100 | * |
||
101 | * Performs an API PATCH request |
||
102 | * |
||
103 | * @access public |
||
104 | * @return Response |
||
105 | */ |
||
106 | public function patch($path, $form = array()) |
||
114 | |||
115 | /** |
||
116 | * DELETE function. |
||
117 | * |
||
118 | * Performs an API DELETE request |
||
119 | * |
||
120 | * @access public |
||
121 | * @return Response |
||
122 | */ |
||
123 | public function delete($path, $form = array()) |
||
131 | |||
132 | /** |
||
133 | * setUrl function. |
||
134 | * |
||
135 | * Takes an API request string and appends it to the API url |
||
136 | * |
||
137 | * @access protected |
||
138 | * @return void |
||
139 | */ |
||
140 | 6 | protected function setUrl($params) |
|
141 | { |
||
142 | 6 | curl_setopt($this->client->ch, CURLOPT_URL, Constants::API_URL . trim($params, '/')); |
|
143 | 6 | } |
|
144 | |||
145 | /** |
||
146 | * EXECUTE function. |
||
147 | * |
||
148 | * Performs the prepared API request |
||
149 | * |
||
150 | * @access protected |
||
151 | * @param string $request_type |
||
152 | * @param array $form |
||
153 | * @return Response |
||
154 | */ |
||
155 | 6 | protected function execute($request_type, $form = array()) |
|
191 | } |
||
192 |