-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTnsReservationModel.php
84 lines (67 loc) · 1.97 KB
/
TnsReservationModel.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
<?php
/**
* @model Tnsreserv
* https://api.test.inetwork.com/v1.0/accounts/tnsreservation
*
*
*
* provides:
* get/0
*
*/
namespace Iris;
use AllowDynamicProperties;
#[AllowDynamicProperties]
final class TnsReservations extends RestEntry{
public function __construct($parent) {
$this->parent = $parent;
parent::_init($this->parent->get_rest_client(), $this->parent->get_relative_namespace());
}
public function create($data, $save = true) {
$tns_res = new TnsReservation($this, $data);
if($save)
$tns_res->save();
return $tns_res;
}
public function tnsreservation($id) {
$r = new TnsReservation($this, ["ReservationId" => $id]);
return $r->get();
}
public function get_appendix() {
return '/tnreservation';
}
}
#[AllowDynamicProperties]
final class TnsReservation extends RestEntry{
use BaseModel;
protected $fields = array(
"ReservedTn" => array("type" => "string"),
"ReservationId" => array("type" => "string"),
"ReservationExpires" => array("type" => "string"),
"AccountId" => array("type" => "string")
);
public function __construct($parent, $data)
{
$this->set_data($data);
$this->parent = $parent;
parent::_init($parent->get_rest_client(), $parent->get_relative_namespace());
}
public function save() {
$header = parent::post(null, "Reservation", $this->to_array());
$splitted = explode("/", $header['Location']);
$this->ReservationId = end($splitted);
}
public function get() {
$data = parent::_get($this->get_id());
$this->set_data($data['Reservation']);
return $this;
}
public function delete() {
parent::_delete($this->get_id());
}
public function get_id() {
if(!isset($this->ReservationId))
throw new \Exception('ReservationId should be provided');
return $this->ReservationId;
}
}