Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/res/NeuronWriter.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
class NeuronWriterAPI
3
+
{
4
+
private $apiEndpoint = 'https://app.neuronwriter.com/neuron-api/0.5/writer';
5
+
private $headers = array();
6
+
7
+
public function __construct($apikey)
8
+
{
9
+
$this->headers = [
10
+
'X-API-KEY: ' . $apikey,
11
+
'Accept: application/json',
12
+
'Content-Type: application/json'
13
+
];
14
+
}
15
+
16
+
private function sendRequest($method, $url, $body = null)
17
+
{
18
+
$curl = curl_init();
19
+
curl_setopt($curl, CURLOPT_URL, $this->apiEndpoint . $url);
20
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
21
+
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
22
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
23
+
24
+
if (!is_null($body)) {
25
+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body));
26
+
}
27
+
28
+
$response = curl_exec($curl);
29
+
curl_close($curl);
30
+
return $response;
31
+
}
32
+
33
+
public function createNewQuery($projectId, $keyword, $engine, $language)
34
+
{
35
+
$payload = [
36
+
'project' => $projectId,
37
+
'keyword' => $keyword,
38
+
'engine' => $engine,
39
+
'language' => $language
40
+
];
41
+
42
+
return $this->sendRequest('POST', '/new-query', $payload);
43
+
}
44
+
45
+
public function getQueryStatus($queryId)
46
+
{
47
+
$retme = false;
48
+
$payload = ['query' => $queryId];
49
+
$response = $this->sendRequest('POST', '/get-query', $payload);
50
+
$responseData = json_decode($response, true);
51
+
if (isset($responseData['status']) && $responseData['status'] === 'ready')
52
+
{
53
+
$retme = $responseData;
54
+
}
55
+
return $retme;
56
+
}
57
+
}
58
+
?>