@@ -67,6 +67,54 @@ public function dataGet($url, $headers = null, $options = array()) {
67
67
return (isset ($ json ['data ' ])) ? $ json ['data ' ] : $ json ['message ' ];
68
68
}
69
69
70
+ /**
71
+ * @param $url
72
+ * @param array $body
73
+ * @param array $headers
74
+ * @param array $options
75
+ * @return mixed
76
+ */
77
+ public function dataPut ($ url , $ body = null , $ headers = null , $ options = array ()) {
78
+ try {
79
+ if (is_array ($ body )) {
80
+ $ options ['form_params ' ] = $ body ;
81
+ }
82
+ if (is_array ($ headers )) {
83
+ $ options ['headers ' ] = $ headers ;
84
+ }
85
+ if (is_array ($ options ) && isset ($ options ['query ' ])) {
86
+ $ options ['query ' ] = array_merge ($ options ['query ' ], $ this ->defaultQuery );
87
+ }
88
+
89
+ $ response = $ this ->request ('PUT ' , $ url , $ options );
90
+ $ this ->checkErrors ($ response );
91
+ $ json = json_decode ($ response ->getBody (), true );
92
+ } catch (RequestException $ e ) {
93
+ if ($ e ->hasResponse ()) {
94
+ $ response = json_decode ($ e ->getResponse ()->getBody (), true );
95
+ $ msg = isset ($ response ['message ' ]) ? $ response ['message ' ] : 'Unknown error ' ;
96
+ if ($ e ->getResponse ()->getStatusCode () == 503 ) {
97
+ throw new NitrapiMaintenanceException ($ msg );
98
+ }
99
+ if ($ e ->getResponse ()->getStatusCode () == 428 ) {
100
+ throw new NitrapiConcurrencyException ($ msg );
101
+ }
102
+ throw new NitrapiHttpErrorException ($ msg );
103
+ }
104
+ throw new NitrapiHttpErrorException ($ e ->getMessage ());
105
+ }
106
+
107
+ if (isset ($ json ['data ' ]) && is_array ($ json ['data ' ])) {
108
+ return $ json ['data ' ];
109
+ }
110
+
111
+ if (!empty ($ json ['message ' ])) {
112
+ return $ json ['message ' ];
113
+ }
114
+
115
+ return true ;
116
+ }
117
+
70
118
/**
71
119
* @param $url
72
120
* @param array $body
0 commit comments