-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROS7Rest.php
144 lines (122 loc) · 4.46 KB
/
ROS7Rest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
class ROS7Rest
{
public $secure = false;
public $path;
public $requestData;
private $secrets;
public function __construct($secrets)
{
$this->secrets = $secrets;
/***[
"username" => "",
"password" => "",
"url" => ""
];******/
}
//get->to get records
function ros7GET()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->secrets["url"] . $this->path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->secure);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->secure);
curl_setopt($ch, CURLOPT_USERPWD, $this->secrets["username"] . ":" . $this->secrets["password"]);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $return;
}
//post->universal methos to all console commands
function ros7POST()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->secrets["url"] . $this->path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->secure);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->secure);
curl_setopt($ch, CURLOPT_POST, true);
if (isset($this->requestData)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestData);
}
curl_setopt($ch, CURLOPT_USERPWD, $this->secrets["username"] . ":" . $this->secrets["password"]);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $return;
}
//put->create a new record
function ros7PUT()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->secrets["url"] . $this->path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->secure);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->secure);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
if (isset($this->requestData)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestData);
}
curl_setopt($ch, CURLOPT_USERPWD, $this->secrets["username"] . ":" . $this->secrets["password"]);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $return;
}
//delete->delete a signle record
function ros7DELETE()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->secrets["url"] . $this->path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->secure);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->secure);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_USERPWD, $this->secrets["username"] . ":" . $this->secrets["password"]);
$return = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $return;
}
//patch->update single record
function ros7PATCH()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->secrets["url"] . $this->path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->secure);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->secure);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
if (isset($this->requestData)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestData);
}
curl_setopt($ch, CURLOPT_USERPWD, $this->secrets["username"] . ":" . $this->secrets["password"]);
$return = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $return;
}
public function __destruct()
{
}
}