From e1f0bcd7e8938c7f9e4cc5731ca5c7eb7e78aa48 Mon Sep 17 00:00:00 2001 From: ShaiV Date: Wed, 29 Dec 2021 11:20:58 +0200 Subject: [PATCH] changed webhose to webz --- webz.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 webz.php diff --git a/webz.php b/webz.php new file mode 100644 index 0000000..0ee41c9 --- /dev/null +++ b/webz.php @@ -0,0 +1,83 @@ + 0, + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_RETURNTRANSFER => true + ); + + /** + * @param string $api_key + */ + public static function config($api_key) + { + self::$API_KEY = $api_key; + } + + /** + * @param string $query_url + * @return mixed + */ + private static function fetch_request($query_url) + { + if(self::$ECHO_REQUEST_URL) + echo "

" . $query_url . "

"; + + $curl = curl_init($query_url); + curl_setopt_array($curl, self::$CURLOPTS); + $json = curl_exec($curl); + curl_close($curl); + + $result = json_decode($json); + + + self::$NEXT = isset($result->next) ? self::$API_URL . $result->next : null; + + return $result; + } + + /** + * @param bool $enable_debug + */ + public static function enable_debug($enable_debug) + { + self::$ECHO_REQUEST_URL = $enable_debug; + } + + /** + * @param string $type + * @param ArrayObject $param_dict + * @return mixed|null + */ + public static function query($type, $param_dict) + { + if(self::$API_KEY == null) return null; + $queryURL = self::$API_URL . sprintf(self::$API_URL_PARAMS, $type, self::$API_KEY); + + foreach($param_dict as $key=> $value) + $queryURL .= sprintf("&%s=%s", $key, urlencode($value)); + + return self::fetch_request($queryURL); + } + + /** + * @return mixed|null + */ + public static function get_next() + { + if(self::$API_KEY == null) return null; + if(self::$NEXT == null) return null; + return self::fetch_request(self::$NEXT); + } +} + +?> \ No newline at end of file