@@ -22,8 +22,31 @@ class RRSet extends Model implements Resource
2222 public int $ zone ;
2323
2424 /**
25- * @param string $id
26- * @param GuzzleClient|null $client
25+ * Creates a new RRSet. This is useful if you want to create a new RRSet to pass to the createRRSet method of a Zone.
26+ *
27+ * @param string $name
28+ * @param string $type
29+ * @param array $records
30+ * @param int|null $ttl
31+ * @param array|null $labels
32+ * @return RRSet|null
33+ */
34+ public static function create (string $ name , string $ type , array $ records , ?int $ ttl = null , ?array $ labels = []): ?RRSet
35+ {
36+ return (new RRset ("" ))->setAdditionalData ((object )[
37+ 'name ' => $ name ,
38+ 'type ' => $ type ,
39+ 'ttl ' => $ ttl ,
40+ 'records ' => $ records ,
41+ 'labels ' => (object )$ labels ,
42+ 'protection ' => (object )[],
43+ 'zone ' => 0 ,
44+ ]);
45+ }
46+
47+ /**
48+ * @param string $id
49+ * @param GuzzleClient|null $client
2750 */
2851 public function __construct (string $ id , ?GuzzleClient $ client = null )
2952 {
@@ -45,6 +68,7 @@ public function setAdditionalData($data)
4568 $ this ->labels = get_object_vars ($ data ->labels );
4669 $ this ->protection = RRSetProtection::parse ($ data ->protection );
4770 $ this ->zone = $ data ->zone ;
71+
4872 return $ this ;
4973 }
5074
@@ -61,7 +85,7 @@ public function __toRequest(): array
6185 'ttl ' => $ this ->ttl ,
6286 'records ' => $ this ->records ,
6387 ];
64- if (!empty ($ this ->labels )) {
88+ if (! empty ($ this ->labels )) {
6589 $ r ['labels ' ] = $ this ->labels ;
6690 }
6791
@@ -70,6 +94,7 @@ public function __toRequest(): array
7094
7195 /**
7296 * @return RRSet|null
97+ *
7398 * @throws \LKDev\HetznerCloud\APIException
7499 */
75100 public function reload ()
@@ -79,139 +104,147 @@ public function reload()
79104
80105 /**
81106 * @return APIResponse|null
107+ *
82108 * @throws \LKDev\HetznerCloud\APIException
83109 */
84110 public function delete (): ?APIResponse
85111 {
86- $ response = $ this ->httpClient ->delete ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id );
87- if (!HetznerAPIClient::hasError ($ response )) {
112+ $ response = $ this ->httpClient ->delete ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id );
113+ if (! HetznerAPIClient::hasError ($ response )) {
88114 return APIResponse::create ([
89- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
115+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
90116 ], $ response ->getHeaders ());
91117 }
92118
93119 return null ;
94120 }
95121
96122 /**
97- * @param array $data
123+ * @param array $data
98124 * @return APIResponse|null
125+ *
99126 * @throws \LKDev\HetznerCloud\APIException
100127 */
101128 public function update (array $ data ): ?APIResponse
102129 {
103- $ response = $ this ->httpClient ->put ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id , [
130+ $ response = $ this ->httpClient ->put ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id , [
104131 'json ' => $ data ,
105132 ]);
106- if (!HetznerAPIClient::hasError ($ response )) {
133+ if (! HetznerAPIClient::hasError ($ response )) {
107134 return APIResponse::create ([
108- 'rrset ' => self ::parse (json_decode ((string )$ response ->getBody ())->rrset ),
135+ 'rrset ' => self ::parse (json_decode ((string ) $ response ->getBody ())->rrset ),
109136 ], $ response ->getHeaders ());
110137 }
111138
112139 return null ;
113140 }
114141
115142 /**
116- * @param bool $change
143+ * @param bool $change
117144 * @return APIResponse|null
145+ *
118146 * @throws \LKDev\HetznerCloud\APIException
119147 */
120148 public function changeProtection (bool $ change ): ?APIResponse
121149 {
122- $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/change_protection ' , [
150+ $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/change_protection ' , [
123151 'json ' => [
124152 'change ' => $ change ,
125153 ],
126154 ]);
127- if (!HetznerAPIClient::hasError ($ response )) {
155+ if (! HetznerAPIClient::hasError ($ response )) {
128156 return APIResponse::create ([
129- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
157+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
130158 ], $ response ->getHeaders ());
131159 }
160+
132161 return null ;
133162 }
134163
135164 /**
136- * @param int $ttl
165+ * @param int $ttl
137166 * @return APIResponse|null
167+ *
138168 * @throws \LKDev\HetznerCloud\APIException
139169 */
140170 public function changeTTL (int $ ttl ): ?APIResponse
141171 {
142- $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/change_ttl ' , [
172+ $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/change_ttl ' , [
143173 'json ' => [
144174 'ttl ' => $ ttl ,
145175 ],
146176 ]);
147- if (!HetznerAPIClient::hasError ($ response )) {
177+ if (! HetznerAPIClient::hasError ($ response )) {
148178 return APIResponse::create ([
149- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
179+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
150180 ], $ response ->getHeaders ());
151181 }
152182
153183 return null ;
154184 }
155185
156186 /**
157- * @param array<Record> $records
187+ * @param array<Record> $records
158188 * @return APIResponse|null
189+ *
159190 * @throws \LKDev\HetznerCloud\APIException
160191 */
161192 public function setRecords (array $ records ): ?APIResponse
162193 {
163- $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/set_records ' , [
194+ $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/set_records ' , [
164195 'json ' => [
165196 'records ' => $ records ,
166197 ],
167198 ]);
168- if (!HetznerAPIClient::hasError ($ response )) {
199+ if (! HetznerAPIClient::hasError ($ response )) {
169200 return APIResponse::create ([
170- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
201+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
171202 ], $ response ->getHeaders ());
172203 }
173204
174205 return null ;
175206 }
176207
177208 /**
178- * @param array<Record> $records
179- * @param int|null $ttl
209+ * @param array<Record> $records
210+ * @param int|null $ttl
180211 * @return APIResponse|null
212+ *
181213 * @throws \LKDev\HetznerCloud\APIException
182214 */
183215 public function addRecords (array $ records , ?int $ ttl = null ): ?APIResponse
184216 {
185- $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/add_records ' , [
217+ $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/add_records ' , [
186218 'json ' => [
187219 'records ' => $ records ,
188220 'ttl ' => $ ttl ,
189221 ],
190222 ]);
191- if (!HetznerAPIClient::hasError ($ response )) {
223+ if (! HetznerAPIClient::hasError ($ response )) {
192224 return APIResponse::create ([
193- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
225+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
194226 ], $ response ->getHeaders ());
195227 }
196228
197229 return null ;
198230 }
199231
200232 /**
201- * @param array<Record> $records
233+ * @param array<Record> $records
202234 * @return APIResponse|null
235+ *
203236 * @throws \LKDev\HetznerCloud\APIException
204237 */
205238 public function removeRecords (array $ records )
206239 {
207- $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/remove_records ' , [
240+ $ response = $ this ->httpClient ->post ('zones/ ' . $ this ->zone . '/rrsets/ ' . $ this ->id . '/actions/remove_records ' , [
208241 'json ' => [
209242 'records ' => $ records ,
210243 ],
211244 ]);
212- if (!HetznerAPIClient::hasError ($ response )) {
245+ if (! HetznerAPIClient::hasError ($ response )) {
213246 return APIResponse::create ([
214- 'action ' => Action::parse (json_decode ((string )$ response ->getBody ())->action ),
247+ 'action ' => Action::parse (json_decode ((string ) $ response ->getBody ())->action ),
215248 ], $ response ->getHeaders ());
216249 }
217250
0 commit comments