1: <?php
2: 3: 4: 5: 6: 7:
8: namespace GLFramework\HTTP;
9:
10: use GLFramework\Bootstrap;
11:
12: class API
13: {
14: private $config;
15:
16: 17: 18: 19:
20: public function __construct($config = null)
21: {
22: if($config == null)
23: {
24: $config = Bootstrap::getSingleton()->getConfig();
25: }
26: $this->config = $config;
27: }
28:
29: public function getEndpoint()
30: {
31: return $this->config['api']['endpoint'];
32: }
33:
34: public function getURI($baseUri)
35: {
36: return $this->getEndpoint() . $baseUri;
37: }
38:
39: public function getAuth()
40: {
41: return array("X-Authorization: " . $this->config['api']['autorization']);
42: }
43:
44:
45: public function post($uri, $fields)
46: {
47: $url = $this->getURI($uri);
48: return post($url, $fields, $this->getAuth());
49: }
50: public function get($uri, $fields = array())
51: {
52: $fields_string = "";
53: foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
54: rtrim($fields_string, '&');
55: $url = $this->getURI($uri) . "?" . $fields_string;
56: return get($url, $this->getAuth());
57: }
58: }