@@ -47,8 +47,7 @@ public function __construct( $apiKey, $apiSecret ) {
4747 *
4848 * @return array
4949 */
50- protected function headers (): array
51- {
50+ protected function headers (): array {
5251 return [
5352 'Authorization ' => 'Bearer ' . $ this ->generateJWT (),
5453 'Content-Type ' => 'application/json ' ,
@@ -78,8 +77,7 @@ protected function generateJWT() {
7877 * @param array $fields
7978 * @return array|mixed
8079 */
81- protected function get ($ method , $ fields = [])
82- {
80+ protected function get ($ method , $ fields = []) {
8381 try {
8482 $ response = $ this ->client ->request ('GET ' , $ this ->apiPoint . $ method , [
8583 'query ' => $ fields ,
@@ -101,8 +99,7 @@ protected function get($method, $fields = [])
10199 * @param $fields
102100 * @return array|mixed
103101 */
104- protected function post ($ method , $ fields )
105- {
102+ protected function post ($ method , $ fields ) {
106103 $ body = \json_encode ($ fields , JSON_PRETTY_PRINT );
107104
108105 try {
@@ -124,8 +121,7 @@ protected function post($method, $fields)
124121 * @param $fields
125122 * @return array|mixed
126123 */
127- protected function patch ($ method , $ fields )
128- {
124+ protected function patch ($ method , $ fields ) {
129125 $ body = \json_encode ($ fields , JSON_PRETTY_PRINT );
130126
131127 try {
@@ -140,8 +136,35 @@ protected function patch($method, $fields)
140136 }
141137 }
142138
143- protected function delete ($ method )
144- {
139+ /**
140+ * Put
141+ *
142+ * @param $method
143+ * @param $fields
144+ * @return array|mixed
145+ */
146+ protected function put ($ method , $ fields ) {
147+ $ body = \json_encode ($ fields , JSON_PRETTY_PRINT );
148+
149+ try {
150+ $ response = $ this ->client ->request ('PUT ' , $ this ->apiPoint . $ method ,
151+ ['body ' => $ body , 'headers ' => $ this ->headers ()]);
152+
153+ return $ this ->result ($ response );
154+
155+ } catch (ClientException $ e ) {
156+
157+ return (array )json_decode ($ e ->getResponse ()->getBody ()->getContents ());
158+ }
159+ }
160+
161+ /**
162+ * Delete
163+ *
164+ * @param $method
165+ * @return array|mixed
166+ */
167+ protected function delete ($ method ) {
145168 try {
146169 $ response = $ this ->client ->request ('DELETE ' , $ this ->apiPoint . $ method ,
147170 [ 'headers ' => $ this ->headers ()]);
@@ -160,8 +183,7 @@ protected function delete($method)
160183 * @param Response $response
161184 * @return mixed
162185 */
163- protected function result (Response $ response )
164- {
186+ protected function result (Response $ response ) {
165187 $ result = json_decode ((string )$ response ->getBody (), true );
166188
167189 $ result ['code ' ] = $ response ->getStatusCode ();
0 commit comments