Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 674820e

Browse files
committed
Add Proxy
1 parent 7d51e44 commit 674820e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

SNClient/SNClient.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ class ServiceNowClient
1010
private $instance = NULL;
1111
private $username = NULL;
1212
private $password = NULL;
13+
private $proxy = NULL;
1314

1415
/* Constructor of the class
1516
* Required to get credentials to use authentification on Service-Now.
17+
* Example: $SNClient = new ServiceNowClient();
1618
*/
17-
public function __construct($instance, $username, $password){
19+
public function __construct($instance, $username, $password, $proxy){
1820
$this->instance = $instance;
1921
$this->username = $username;
2022
$this->password = $password;
23+
$this->proxy = $proxy;
2124
}
2225

2326
/* Test authentification on Service-Now by getting incident table with a limit of 1 incident.
@@ -28,6 +31,9 @@ public function Authenticated(){
2831

2932
$ch = curl_init($RESTReq);
3033
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
34+
if(!empty($this->proxy)){
35+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
36+
}
3137
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
3238
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
3339
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
@@ -60,6 +66,9 @@ public function RetrieveAllRecords($table, $parameters = "") {
6066

6167
$ch = curl_init($RESTReq);
6268
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
69+
if(!empty($this->proxy)){
70+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
71+
}
6372
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
6473
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
6574
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
@@ -93,6 +102,9 @@ public function CreateRecord($table, $data)
93102

94103
$ch = curl_init($url);
95104
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
105+
if(!empty($this->proxy)){
106+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
107+
}
96108
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
97109
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
98110
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -128,6 +140,9 @@ public function RetrieveRecord($table, $ID) {
128140

129141
$ch = curl_init($RESTReq);
130142
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
143+
if(!empty($this->proxy)){
144+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
145+
}
131146
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
132147
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
133148
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
@@ -162,6 +177,9 @@ public function ModifyRecord($table, $sys_id, $data)
162177

163178
$ch = curl_init($url);
164179
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
180+
if(!empty($this->proxy)){
181+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
182+
}
165183
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
166184
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
167185
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -196,6 +214,9 @@ public function UpdateRecord($table, $sys_id, $data)
196214

197215
$ch = curl_init($url);
198216
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
217+
if(!empty($this->proxy)){
218+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
219+
}
199220
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
200221
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
201222
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -228,6 +249,9 @@ public function DeleteRecord($table, $sys_id)
228249

229250
$ch = curl_init($url);
230251
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
252+
if(!empty($this->proxy)){
253+
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
254+
}
231255
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
232256
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
233257
curl_setopt($ch, CURLOPT_HTTPHEADER, array(

0 commit comments

Comments
 (0)