Initial commit
This commit is contained in:
34
inc/lib/Narodmon.php
Normal file
34
inc/lib/Narodmon.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class Narodmon
|
||||
{
|
||||
private const API_ENDPOINT = 'http://narodmon.ru/post';
|
||||
private string $deviceMac;
|
||||
|
||||
private array $data = [];
|
||||
|
||||
public function __construct(string $deviceMac)
|
||||
{
|
||||
$this->deviceMac = $deviceMac;
|
||||
}
|
||||
|
||||
public function add(string $name, int|float $value): self
|
||||
{
|
||||
$this->data[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
$data = array_merge($this->data, ['ID' => $this->deviceMac]);
|
||||
$ch = curl_init(self::API_ENDPOINT);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
$reply = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user