├── License.txt ├── README.md ├── composer.json └── webz.php /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Webz.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | webz.io client for PHP 3 | ============================ 4 | 5 | A simple way to access the [Webz.io](https://webz.io) API from your PHP code: 6 | 7 | ```php 8 | // API Key from: https://webz.io/dashboard 9 | Webz::config("API_KEY"); 10 | 11 | //Perform a "filterWebContent" query using "United States" as our keywords. 12 | $params = array("q"=>"United States", "size"=>"3"); 13 | $result = Webz::query("filterWebContent", $params); 14 | 15 | //Fetch the next results using the same terms. 16 | $result = Webz::get_next(); 17 | ``` 18 | API Key 19 | ------- 20 | 21 | To make use of the webz.io API, you'll need an API key. 22 | 23 | To get one, sign up at: 24 | https://webz.io/auth/signup 25 | 26 | And your key will be available here: 27 | https://webz.io/dashboard 28 | 29 | 30 | Usage 31 | ----------- 32 | 33 | To get started, you'll need to import the class and configure it with your API key: 34 | 35 | ```php 36 | require_once('webz.php'); 37 | 38 | // API Key from: https://webz.io/dashboard 39 | Webz::config("API_KEY"); 40 | ``` 41 | 42 |
43 | 44 | **API Endpoints** 45 | 46 | The first parameter the query() function accepts is the API endpoint string. Available endpoints: 47 | * filterWebContent - access to the news/blogs/forums/reviews API 48 | * productFilter - access to data about eCommerce products/services 49 | * darkFilter - access to the dark web (coming soon) 50 | 51 | Now you can make a request and inspect the results: 52 | 53 | ```php 54 | //Helper method to print result: 55 | function print_filterwebdata_titles($api_response) 56 | { 57 | if($api_response == null) 58 | { 59 | echo "

Response is null, no action taken.

"; 60 | return; 61 | } 62 | if(isset($api_response->posts)) 63 | foreach($api_response->posts as $post) 64 | { 65 | echo "

" . $post->title . "

"; 66 | } 67 | } 68 | 69 | //Perform a "filterWebContent" query using "United States" as our keywords. 70 | $params = array("q"=>"United States", "size"=>"3"); 71 | $result = Webz::query("filterWebContent", $params); 72 | print_filterwebdata_titles($result); 73 | ``` 74 | 75 | You can traverse the structure as you would any PHP array: 76 | 77 | ```php 78 | //Print more detailed information about the article: 79 | 80 | $params = array("q"=>"United States", "size"=>"1"); 81 | $result = Webz::query("filterWebContent", $params); 82 | 83 | foreach($result->posts as $post) 84 | { 85 | echo "

Site: " . $post->thread->site . "

"; 86 | echo "

Categories:

"; 87 | echo ""; 92 | } 93 | ``` 94 | 95 |
96 | 97 | Depending on the endpoint used, the resulting JSON array could provide "posts", "products", ... 98 | You can view the JSON in the browser to get a clearer picture of the return data. 99 | In order to view the data in the browser, we can enable a debug flag to expose the URL fed to cURL: 100 | 101 | ```php 102 | //If true, echoes the parameterised Webz API URL before executing request. 103 | Webz::enable_debug(true); 104 | ``` 105 | 106 | 107 | Full documentation 108 | ------------------ 109 | 110 | * ``Webz::config(api_key)`` 111 | 112 | * api_key - your API key 113 | 114 | * ``Webz::query(end_point_str, params)`` 115 | 116 | * end_point_str 117 | * filterWebContent - access to the news/blogs/forums/reviews API 118 | * productFilter - access to data about eCommerce products/services 119 | * darkFilter - access to the dark web (coming soon) 120 | * params: A key value dictionary. [Read about the available parameters](https://docs.webz.io/). 121 | 122 | * ``Webz::get_next()`` - Fetches the next page of results using the same parameters. 123 | 124 | * ``Webz::enable_debug(debug_enabled)`` 125 | 126 | * debug_enabled - boolean, If true, echoes the parameterised Webz API URL before executing requests. 127 | 128 | 129 | Polling 130 | ------------------ 131 | 132 | It is possible to continue a search to fetch more results using the same parameters: 133 | 134 | ```php 135 | //Perform a "productFilter" query using "United Kingdom" as our keywords. 136 | $params = array("q"=>"United Kingdom", "size"=>"1"); 137 | $result = Webz::query("productFilter", $params); 138 | print_productsearch_titles($result); 139 | 140 | //Fetch the next results using the same terms. 141 | $result = Webz::get_next(); 142 | print_productsearch_titles($result); 143 | 144 | $result = Webz::get_next(); 145 | print_productsearch_titles($result); 146 | 147 | //... 148 | //When $result is null, there are no more results available. 149 | ``` 150 | 151 | License 152 | ------------------ 153 | The code of this repository is published under the MIT license 154 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webz/webzio-php", 3 | "description": "Webz.io PHP SDK", 4 | "homepage": "https://github.com/Webhose/webhoseio-PHP", 5 | "version": "1.1", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Webz.io", 11 | "email": "webz-support@webz.io", 12 | "homepage": "https://webz.io/" 13 | } 14 | ], 15 | "require": { 16 | "php": "^5.4|^7.0", 17 | "ext-curl": "*", 18 | "ext-libxml": "*" 19 | }, 20 | "autoload": { 21 | "files": ["webz.php"] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /webz.php: -------------------------------------------------------------------------------- 1 | 0, 14 | CURLOPT_SSL_VERIFYHOST => 0, 15 | CURLOPT_RETURNTRANSFER => true 16 | ); 17 | 18 | /** 19 | * @param string $api_key 20 | */ 21 | public static function config($api_key) 22 | { 23 | self::$API_KEY = $api_key; 24 | } 25 | 26 | /** 27 | * @param string $query_url 28 | * @return mixed 29 | */ 30 | private static function fetch_request($query_url) 31 | { 32 | if(self::$ECHO_REQUEST_URL) 33 | echo "

" . $query_url . "

"; 34 | 35 | $curl = curl_init($query_url); 36 | curl_setopt_array($curl, self::$CURLOPTS); 37 | $json = curl_exec($curl); 38 | curl_close($curl); 39 | 40 | $result = json_decode($json); 41 | 42 | 43 | self::$NEXT = isset($result->next) ? self::$API_URL . $result->next : null; 44 | 45 | return $result; 46 | } 47 | 48 | /** 49 | * @param bool $enable_debug 50 | */ 51 | public static function enable_debug($enable_debug) 52 | { 53 | self::$ECHO_REQUEST_URL = $enable_debug; 54 | } 55 | 56 | /** 57 | * @param string $type 58 | * @param ArrayObject $param_dict 59 | * @return mixed|null 60 | */ 61 | public static function query($type, $param_dict) 62 | { 63 | if(self::$API_KEY == null) return null; 64 | $queryURL = self::$API_URL . sprintf(self::$API_URL_PARAMS, $type, self::$API_KEY); 65 | 66 | foreach($param_dict as $key=> $value) 67 | $queryURL .= sprintf("&%s=%s", $key, urlencode($value)); 68 | 69 | return self::fetch_request($queryURL); 70 | } 71 | 72 | /** 73 | * @return mixed|null 74 | */ 75 | public static function get_next() 76 | { 77 | if(self::$API_KEY == null) return null; 78 | if(self::$NEXT == null) return null; 79 | return self::fetch_request(self::$NEXT); 80 | } 81 | } 82 | 83 | ?> --------------------------------------------------------------------------------