-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.php
57 lines (48 loc) · 1.18 KB
/
API.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
<?php
namespace RockLiteApi;
use ProcessWire\RockLite;
use ProcessWire\Wire;
use ProcessWire\WireHttp;
class API extends Wire
{
public $url = "https://connect.mailerlite.com/";
public $rocklite;
public function __construct(RockLite $rocklite)
{
$this->rocklite = $rocklite;
}
public function get($url)
{
return json_decode(
$this->http()->get($this->url($url))
);
}
public function http(): WireHttp
{
if ($this->http) return $this->http;
/** @var WireHttp $http */
$http = $this->wire(new WireHttp());
$http->setHeader('Content-Type', 'application/json');
$http->setHeader('Accept', 'application/json');
$http->setHeader('Authorization', 'Bearer ' . $this->rocklite->apikey);
return $this->http = $http;
}
public function post($url, $data)
{
return json_decode(
$this->http()->post($this->url($url), json_encode($data))
);
}
public function subscribe($mail, $fields = [], $groups = [])
{
return $this->post("/api/subscribers", [
'email' => $mail,
'fields' => (object)$fields,
'groups' => $groups,
]);
}
public function url($url)
{
return $this->url . ltrim($url, "/");
}
}