/
class.uw-servicenowclient.php
65 lines (48 loc) · 1.48 KB
/
class.uw-servicenowclient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class UW_ServiceNowClient {
public $options;
public function __construct($options=array())
{
$default_options = array(
'base_url' => null,
'username' => null,
'password' => null,
);
$this->options = array_merge($default_options, $options);
}
public function execute($pagename, $params=array(), $headers=array(), $method='GET', $content='')
{
$url = $this->options['base_url'] . '/' . $pagename . '.do?JSONv2&' . http_build_query($params);
$cred = sprintf('Authorization: Basic %s',
base64_encode( $this->options['username'] . ':' . $this->options['password'] ) );
$headers = array_merge(array($cred), $headers);
$opts = array(
'http' => array(
'method' => $method,
'header' => implode("\r\n", $headers),
)
);
$ctx = stream_context_create($opts);
return file_get_contents($url, false, $ctx);
}
public function get($table, $sys_id, $displayvalue='all')
{
$pagename = $table . '_list';
$params = array(
'sysparm_action' => 'get',
'sysparm_sys_id' => $sys_id,
'displayvalue' => $displayvalue,
);
return $this->execute($pagename, $params);
}
public function get_records($table, $query, $displayvalue='all')
{
$pagename = $table . '_list';
$params = array(
'sysparm_action' => 'getRecords',
'sysparm_query' => $query,
'displayvalue' => $displayvalue,
);
return $this->execute($pagename, $params);
}
}