-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
189 lines (145 loc) · 3.99 KB
/
functions.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
function send_request($REQ,$METHOD){
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt_array($curl, array(
CURLOPT_URL => $REQ ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $METHOD ,
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer mwOk6IyKkIW7CjtS2xSJVzX5HndPyFcDyPmecNQ6",
"Postman-Token: d43a8ea2-eb20-481e-8db8-a44bf86ec331",
"cache-control: no-cache",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
if ($response == NULL) echo 'No Response';
echo $response."end response\r";
}
return $response;
}
///////////////////////
function send_patch_request($REQ){
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data=array("data" => array("status" => "complete"));
$data2=array("fields"=>"status");
curl_setopt_array($curl, array(
CURLOPT_URL => $REQ ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH" ,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer mwOk6IyKkIW7CjtS2xSJVzX5HndPyFcDyPmecNQ6",
"Postman-Token: d43a8ea2-eb20-481e-8db8-a44bf86ec331",
"cache-control: no-cache",
"Content-Type: application/json",
// "{'data':{'status':'pending'}}"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
if ($response == NULL) echo 'mafesh';
// echo $response;
}
return $response;
}
///////////////////////
/**
* JSON data to html table
*
* @param object $data
*
*/
function jsonToTable ($data)
{
$table = '
<table class="json-table" border=1>
';
foreach ($data as $key => $value) {
$table .= '
<tr valign="top">
';
if ( ! is_numeric($key)) {
$table .= '
<td>
<strong>'. $key .'</strong>
</td>
<td>
';
} else {
$table .= '
<td colspan="2">
';
}
if (is_object($value) || is_array($value)) {
$table .= jsonToTable($value);
} else {
$table .= $value;
}
$table .= '
</td>
</tr>
';
}
$table .= '
</table>
';
return $table;
}
////////////////////////
function send_patch_request_cf($REQ,$instance_id,$cf_id,$cf_value){
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data=array("data" => array( "custom_field_values" => array("id" => $instance_id, "value" => $cf_value )));
$json=json_encode($data);
echo $json;
curl_setopt_array($curl, array(
CURLOPT_URL => $REQ ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH" ,
CURLOPT_POSTFIELDS => $json ,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer mwOk6IyKkIW7CjtS2xSJVzX5HndPyFcDyPmecNQ6",
"Postman-Token: d43a8ea2-eb20-481e-8db8-a44bf86ec331",
"cache-control: no-cache",
"Content-Type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
if ($response == NULL) echo 'mafesh';
// echo $response;
}
return $response;
}
?>