1010
1111use LKDev \HetznerCloud \HetznerAPIClient ;
1212use LKDev \HetznerCloud \Models \Model ;
13+ use LKDev \HetznerCloud \RequestOpts ;
1314
1415/**
1516 *
@@ -31,31 +32,37 @@ class SSHKeys extends Model
3132 * @throws \LKDev\HetznerCloud\APIException
3233 */
3334 public function create (
34- string $ name ,
35- string $ publicKey
36- ): SSHKey {
37- $ response = $ this ->httpClient ->post ('ssh_keys ' , [
38- 'json ' => [
39- 'name ' => $ name ,
40- 'public_key ' => $ publicKey ,
41- ],
42- ]);
43- if (! HetznerAPIClient::hasError ($ response )) {
44- return SSHKey::parse (json_decode ((string ) $ response ->getBody ())->ssh_key );
45- }
35+ string $ name ,
36+ string $ publicKey
37+ ): SSHKey
38+ {
39+ $ response = $ this ->httpClient ->post ('ssh_keys ' , [
40+ 'json ' => [
41+ 'name ' => $ name ,
42+ 'public_key ' => $ publicKey ,
43+ ],
44+ ]);
45+ if (!HetznerAPIClient::hasError ($ response )) {
46+ return SSHKey::parse (json_decode ((string )$ response ->getBody ())->ssh_key );
47+ }
4648 }
4749
4850 /**
4951 * Returns all ssh key objects.
5052 *
5153 * @see https://docs.hetzner.cloud/#resources-ssh-keys-get
54+ * @param RequestOpts $requestOpts
5255 * @return array
5356 * @throws \LKDev\HetznerCloud\APIException
5457 */
55- public function all ():array {
56- $ response = $ this ->httpClient ->get ('ssh_keys ' );
57- if (!HetznerAPIClient::hasError ($ response )){
58- return self ::parse (json_decode ((string ) $ response ->getBody ()))->sshKeys ;
58+ public function all (RequestOpts $ requestOpts ): array
59+ {
60+ if ($ requestOpts == null ) {
61+ $ requestOpts = new RequestOpts ();
62+ }
63+ $ response = $ this ->httpClient ->get ('ssh_keys ' . $ requestOpts ->buildQuery ());
64+ if (!HetznerAPIClient::hasError ($ response )) {
65+ return self ::parse (json_decode ((string )$ response ->getBody ()))->sshKeys ;
5966 }
6067 }
6168
@@ -67,29 +74,32 @@ public function all():array{
6774 * @return \LKDev\HetznerCloud\Models\SSHKeys\SSHKey
6875 * @throws \LKDev\HetznerCloud\APIException
6976 */
70- public function get (int $ sshKeyId ): SSHKey {
71- $ response = $ this ->httpClient ->get ('ssh_keys/ ' .$ sshKeyId );
72- if (! HetznerAPIClient::hasError ($ response )) {
73- return SSHKey::parse (json_decode ((string ) $ response ->getBody ())->ssh_key );
77+ public function get (int $ sshKeyId ): SSHKey
78+ {
79+ $ response = $ this ->httpClient ->get ('ssh_keys/ ' . $ sshKeyId );
80+ if (!HetznerAPIClient::hasError ($ response )) {
81+ return SSHKey::parse (json_decode ((string )$ response ->getBody ())->ssh_key );
7482 }
7583 }
84+
7685 /**
7786 * @param $input
7887 * @return $this
7988 */
80- public function setAdditionalData ( $ input )
89+ public function setAdditionalData ($ input )
8190 {
8291 $ this ->sshKeys = collect ($ input ->ssh_keys )->map (function ($ sshKey , $ key ) {
8392 return SSHKey::parse ($ sshKey );
8493 })->toArray ();
8594
8695 return $ this ;
8796 }
97+
8898 /**
8999 * @param $input
90100 * @return $this|static
91101 */
92- public static function parse ( $ input )
102+ public static function parse ($ input )
93103 {
94104 return (new self ())->setAdditionalData ($ input );
95105 }
0 commit comments