@@ -64,9 +64,9 @@ public function __construct( $api_key, $format = 'json', $no_json_callback = 1 )
6464 private function fetch ( $ request ) {
6565
6666 if ( preg_match ( '#\?# ' , $ request ) ) {
67- $ request .= '&apiKey= ' . static ::$ api_key ;
67+ $ request .= '&apiKey= ' . static ::$ api_key . " &rand= " . mt_rand ( 1000000 , 10000000 ) ;
6868 } else {
69- $ request .= '?apiKey= ' .static ::$ api_key ;
69+ $ request .= '?apiKey= ' .static ::$ api_key . " &rand= " . mt_rand ( 1000000 , 10000000 ) ;
7070 }
7171
7272 $ request .= '&format= ' . static ::$ format ;
@@ -126,17 +126,20 @@ public function get_monitors( $search = '', $monitors = null, $custom_up_ratio =
126126 $ request .= '&customUptimeRatio= ' . $ this ->get_implode ( $ custom_up_ratio );
127127 }
128128 $ result = $ this ->fetch ( $ request );
129- $ limit = $ result ->limit ;
130- $ offset = $ result ->offset ;
131- $ total = $ result ->total ;
132129
133- while ( ($ limit * $ offset ) + $ limit < $ total ) {
130+ if ( isset ( $ result ->limit ) && isset ( $ result ->offset ) && isset ( $ result ->total )){
131+ $ limit = $ result ->limit ;
132+ $ offset = $ result ->offset ;
133+ $ total = $ result ->total ;
134+
135+ while ( ($ limit * $ offset ) + $ limit < $ total ) {
134136 $ result ->limit = ($ limit * $ offset ) + $ limit ;
135137 $ offset ++;
136138 $ append = $ this ->fetch ( $ request .'&offset= ' .($ offset * $ limit ) );
137139 $ result ->monitors ->monitor = array_merge ( $ result ->monitors ->monitor , $ append ->monitors ->monitor );
140+ }
141+ $ result ->limit = ( $ limit * $ offset ) + $ limit ;
138142 }
139- $ result ->limit = ( $ limit * $ offset ) + $ limit ;
140143
141144 return $ result ;
142145 }
@@ -196,9 +199,60 @@ public function new_monitor( $friendly_name, $url, $type, $alert_contacts = null
196199
197200 /**
198201 * [edit_monitor description]
202+ *
203+ * @param [type] $monitor_id [description].
204+ * @param [type] $monitor_status [description].
205+ * @param [type] $friendly_name [description].
206+ * @param [type] $url [description].
207+ * @param [type] $type [description].
208+ * @param [type] $alert_contacts [description].
209+ * @param [type] $sub_type [description].
210+ * @param [type] $port [description].
211+ * @param [type] $keyword_type [description].
212+ * @param [type] $keyword_value [description].
213+ * @param [type] $username [description].
214+ * @param [type] $password [description].
215+ * @return [type] [description]
199216 */
200- protected function edit_monitor () {
217+ public function edit_monitor ( $ monitor_id , $ monitor_status = null , $ friendly_name = null , $ url = null , $ type = null , $ alert_contacts = null , $ sub_type = null , $ port = null , $ keyword_type = null , $ keyword_value = null , $ username = null , $ password = null ) {
218+
219+ $ request = $ this ->base_uri . '/editMonitor?monitorID= ' . $ monitor_id ;
220+
221+ if (isset ($ monitor_status )){
222+ $ request .= '&monitorStatus= ' . $ monitor_status ;
223+ }
224+ if (isset ($ friendly_name )){
225+ $ request .= '&monitorFriendlyName= ' . urlencode ($ friendly_name );
226+ }
227+ if (isset ($ url )){
228+ $ request .= '&monitorURL= ' . $ url ;
229+ }
230+ if (isset ($ type )){
231+ $ request .= '&monitorType= ' . $ type ;
232+ }
233+ if (isset ($ sub_type )){
234+ $ request .= '&monitorSubType= ' . $ sub_type ;
235+ }
236+ if (isset ($ port )){
237+ $ request .= '&monitorPort= ' . $ port ;
238+ }
239+ if (isset ($ keyword_type )){
240+ $ request .= '&monitorKeywordType= ' . $ keyword_type ;
241+ }
242+ if (isset ($ keyword_value )){
243+ $ request .= '&monitorKeywordValue= ' . urlencode ($ keyword_value );
244+ }
245+ if (isset ($ username )){
246+ $ request .= '&monitorHTTPUsername= ' . urlencode ($ username );
247+ }
248+ if (isset ($ password )){
249+ $ request .= '&monitorHTTPPassword= ' . urlencode ($ password );
250+ }
251+ if (!empty ($ alert_contacts )){
252+ $ request .= '&monitorAlertContacts= ' . $ this ->get_implode ($ alert_contacts );
253+ }
201254
255+ return $ this ->fetch ( $ request );
202256 }
203257
204258 /**
@@ -207,7 +261,7 @@ protected function edit_monitor() {
207261 * @param [Int] $monitor_id ID of monitor.
208262 * @return [type] [description]
209263 */
210- protected function delete_monitor ( $ monitor_id ) {
264+ public function delete_monitor ( $ monitor_id ) {
211265 if ( empty ( $ monitor_id ) ) {
212266 return new WP_Error ( 'required-fields ' , __ ( 'Required fields are empty ' , 'text-domain ' ) );
213267 }
0 commit comments