├── 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 "" . $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 | ?> --------------------------------------------------------------------------------