1 | <?php |
||
8 | class Request |
||
9 | { |
||
10 | /** |
||
11 | * Contains Economic_Client instance. |
||
12 | */ |
||
13 | protected $client; |
||
14 | |||
15 | /** |
||
16 | * __construct function. |
||
17 | * |
||
18 | * Instantiates the object |
||
19 | * |
||
20 | * @param Client $client |
||
21 | */ |
||
22 | 17 | public function __construct(Client $client) |
|
26 | |||
27 | /** |
||
28 | * GET function. |
||
29 | * |
||
30 | * Performs an API GET request |
||
31 | * |
||
32 | * @param string $path |
||
33 | * @param array $query |
||
34 | * |
||
35 | * @throws Exception |
||
36 | * |
||
37 | * @return Response |
||
38 | */ |
||
39 | 13 | public function get($path, $query = []) |
|
40 | { |
||
41 | // Add query parameters to $path? |
||
42 | 13 | if (!empty($query)) { |
|
43 | 8 | if (strpos($path, '?') === false) { |
|
44 | 7 | $path .= '?'.http_build_query($query, '', '&'); |
|
45 | } else { |
||
46 | 1 | $path .= ini_get('arg_separator.output').http_build_query($query, '', '&'); |
|
47 | } |
||
48 | } |
||
49 | |||
50 | // Start the request and return the response |
||
51 | 13 | return $this->execute('GET', $path); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * POST function. |
||
56 | * |
||
57 | * Performs an API POST request |
||
58 | * |
||
59 | * @param string $path |
||
60 | * @param array $form |
||
61 | * |
||
62 | * @throws Exception |
||
63 | * |
||
64 | * @return Response |
||
65 | */ |
||
66 | 1 | public function post($path, $form = []) |
|
71 | |||
72 | /** |
||
73 | * PUT function. |
||
74 | * |
||
75 | * Performs an API PUT request |
||
76 | * |
||
77 | * @param string $path |
||
78 | * @param array $form |
||
79 | * |
||
80 | * @throws Exception |
||
81 | * |
||
82 | * @return Response |
||
83 | */ |
||
84 | 1 | public function put($path, $form = []) |
|
89 | |||
90 | /** |
||
91 | * PATCH function. |
||
92 | * |
||
93 | * Performs an API PATCH request |
||
94 | * |
||
95 | * @param string $path |
||
96 | * @param array $form |
||
97 | * |
||
98 | * @throws Exception |
||
99 | * |
||
100 | * @return Response |
||
101 | */ |
||
102 | 1 | public function patch($path, $form = []) |
|
107 | |||
108 | /** |
||
109 | * DELETE function. |
||
110 | * |
||
111 | * Performs an API DELETE request |
||
112 | * |
||
113 | * @param string $path |
||
114 | * @param array $form |
||
115 | * |
||
116 | * @throws Exception |
||
117 | * |
||
118 | * @return Response |
||
119 | */ |
||
120 | 1 | public function delete($path, $form = []) |
|
125 | |||
126 | /** |
||
127 | * @param string $request_type |
||
128 | * @param array $form |
||
129 | * @param string $path |
||
130 | * |
||
131 | * @throws Exception |
||
132 | * |
||
133 | * @return Response |
||
134 | */ |
||
135 | 17 | protected function execute($request_type, $path, $form = []) |
|
194 | } |
||
195 |