-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPI.php
74 lines (64 loc) · 1.59 KB
/
API.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
66
67
68
69
70
71
72
73
74
<?php
/**
* API class
*
* @package Framework
*/
require_once('/opt/tools/.passwd');
/**
* API class.
*
* @author Marco Ceppi <[email protected]>
* @package Framework
* @subpackage API
*/
class API
{
static $server;
public static function digest()
{
return base64_encode(API_USERNAME . ':' . API_PASSWORD);
}
// This needs to be a call to the API!
public static function get( $server, $path )
{
$context = stream_context_create(array
(
'http' => array
(
'method' => 'GET',
'header' => 'Authorization: Basic ' . static::digest()
)
));
return @file_get_contents('https://' . $server . ':9001/' . $path, false, $context);
}
public static function set( $server, $path, $data )
{
$content_type = (is_array($data)) ? 'application/json' : 'plain/text';
$context = stream_context_create(array
(
'http' => array(
'method' => 'POST',
'header' => sprintf("Authorization: Basic %s\r\n", static::digest()). "Content-type: $content_type\r\n",
'content' => (is_array($data)) ? json_encode($data) : $data
)
));
return (@file_get_contents('https://' . $server . ':9001/'. $path, false, $context) === false) ? false : true;
}
public static function del( $server, $path )
{
return static::delete($server, $path);
}
public static function delete( $server, $path )
{
$context = stream_context_create(array
(
'http' => array
(
'method' => 'DELETE',
'header' => 'Authorization: Basic ' . static::digest()
)
));
return (!@file_get_contents('https://' . $server . ':9001/'. $path, false, $context)) ? false : true;
}
}