commit | author | age
|
64d311
|
1 |
<?php |
JK |
2 |
require_once(dirname(__FILE__).'/msapi_config.php'); |
|
3 |
|
|
4 |
class msapi extends msapi_config { |
|
5 |
public $url; |
|
6 |
|
|
7 |
function __construct($url) { |
|
8 |
$this->url = $url; |
|
9 |
} |
|
10 |
|
|
11 |
function execute($params) { |
|
12 |
if(!is_array($params)) { |
|
13 |
throw new Exception('Przekazany parametr nie jest tablicą'); |
|
14 |
} |
|
15 |
|
|
16 |
foreach($params as $name => &$param) { |
|
17 |
if(substr($name, 0, 1)!='$' && is_string($param)) { |
|
18 |
$param = '\''.$param.'\''; |
|
19 |
} |
|
20 |
} |
|
21 |
unset($param); |
|
22 |
$params['$format'] = 'json'; |
|
23 |
|
|
24 |
$context = stream_context_create(array( |
|
25 |
'http' => array( |
|
26 |
'request_fulluri' => TRUE, |
|
27 |
'header' => 'Authorization: Basic '.base64_encode(':'.$this->accountKey) |
|
28 |
), |
|
29 |
)); |
|
30 |
|
|
31 |
$content = file_get_contents($this->url.'?'.http_build_query($params, '', '&'), FALSE, $context); |
|
32 |
if(!$content) { |
|
33 |
return FALSE; |
|
34 |
} |
|
35 |
|
|
36 |
$content = json_decode($content, TRUE); |
|
37 |
if(!$content) { |
|
38 |
return FALSE; |
|
39 |
} |
|
40 |
|
|
41 |
return $content; |
|
42 |
} |
|
43 |
} |
|
44 |
?> |