1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Subscription extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
|
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
|
|
parent::__construct($client); |
15
|
|
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/subscription"); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple subscriptions |
20
|
|
|
* @param string subscription id, leave null for list of boxes |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($subscriptionId = null) |
25
|
|
|
{ |
26
|
|
|
if (is_null($subscriptionId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl()); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$subscriptionId); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create new subscription |
34
|
|
|
* @param object Containing all the information of a subscription |
35
|
|
|
* @return object Result of the request |
36
|
|
|
*/ |
37
|
|
|
public function Create($subscription) |
38
|
|
|
{ |
39
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $subscription); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create new subscription |
44
|
|
|
* @param id of the subscription |
45
|
|
|
* @param object Containing all the information of a subscription |
46
|
|
|
* @return object Result of the request |
47
|
|
|
*/ |
48
|
|
|
public function Update($subscription) |
49
|
|
|
{ |
50
|
|
|
if (!isset($subscription['subscriptionid'])) { |
51
|
|
|
throw new \Exception('subscription must contain subscriptionid'); |
52
|
|
|
} |
53
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$subscription['subscriptionid'], $subscription); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Delete a subscription object by subscription id |
58
|
|
|
* @param string Id of the subscription |
59
|
|
|
* @return object Result of the request |
60
|
|
|
*/ |
61
|
|
|
public function Delete($subscriptionId) |
62
|
|
|
{ |
63
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$subscriptionId); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|