Skip to content

Commit

Permalink
Major code refactor and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
x-fran committed Dec 21, 2021
1 parent 7c897dd commit 1bf6243
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 899 deletions.
38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you use composer.phar local
```bash
# Get your own copy of composer.phar
$ curl -s https://getcomposer.org/installer | php -- --filename=composer
$ composer require "x-fran/g-trends": "^2.0"
$ composer require "x-fran/g-trends": "^3.0"
```


Expand Down Expand Up @@ -79,24 +79,25 @@ Usage

# This options are by default if none provided
$options = [
'hl' => 'en-US',
'tz' => -60, # last hour
'geo' => 'IE',
];
'hl' => 'en-US',
'tz' => 0,
'geo' => 'US',
'time' => 'all',
'category' => 0,
];
$gt = new GTrends($options);

### Interest Over Time

print_r($gt->interestOverTime('Dublin'));
$gt->getInterestOverTime('Dublin');

### Related Queries

# You can add up to 5 keywords
print_r( $gt->getRelatedSearchQueries(['Dublin', 'Madrid', 'Paris']));
$gt->getRelatedSearchQueries(['Donald Trump', 'Barack Obama']);

### Realtime Search Trends
# Categories for Realtime Search Trends are a single char str:
print_r($gt->getRealTimeSearchTrends('all'));
$gt->getRealTimeSearchTrends('all');
#
# Categories
# all : default
Expand All @@ -108,7 +109,7 @@ Usage
# h : top stories

### Daily Search Trends
# print_r($gt->getDailySearchTrends());
$gt->getDailySearchTrends();

### Trending Searches

Expand Down Expand Up @@ -166,34 +167,27 @@ Usage
# UNITED_KINGDOM=p9
# VIETNAM=p28

### Interest by Subregion
# You can add up to 5 keywords
# Parameter $resolution (optional) for United States 'Subregion', 'Metro', 'City'
# Parameter $resolution (optional) for the rest of the countries 'Subregion', 'City' only
print_r($gt->relatedQueries(['Dublin'], 'City'));

### Suggestions Autocomplete

print_r($gt->suggestionsAutocomplete('toys'));
$gt->suggestionsAutocomplete('Milwaukee');


## Common API parameters

$keyWordList (Array)
$keyWords (Array)

> Array of keywords (up to 5) to get data for
$category (Integer)
$options['category'] (Integer)

> Search by category
> Please view this [wiki page containing all available categories](https://github.com/pat310/google-trends-api/wiki/Google-Trends-Categories)
$tz (Integer)
$options['tz'] (Integer)

> Timezone Offset
> For example US CST is ```360```
$time (String)
$options['time'] (String)

> Timezone Offset
Expand Down
111 changes: 61 additions & 50 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
{
"name": "x-fran/g-trends",
"type": "library",
"description": "Google Trends API for PHP",
"authors": [
{
"name": "Francisc Tar",
"email": "francisc.tar@gmail.com",
"role": "Developer"
"name": "x-fran/g-trends",
"type": "library",
"description": "Google Trends API for PHP",
"authors": [
{
"name": "TarLabs.",
"email": "francisc@tarlabs.es",
"role": "Founder"
}
],
"homepage": "https://tarlabs.es/",
"keywords" : [
"google",
"google-trends",
"google-api",
"trends",
"explore",
"trending",
"related-queries",
"trending-search",
"php-library",
"php"
],
"support": {
"email": "francisc.tar@gmail.com"
},
"license": [
"MIT"
],
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"process-timeout": 5000,
"sort-packages": true
},
"require": {
"php": "^7.4|^8.0",
"ext-curl": "*",
"ext-json": "*",
"laminas/laminas-http": "^2.15",
"laminas/laminas-json": "^3.3",
"laminas/laminas-stdlib": "^3.6"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"phpmd/phpmd": "^2.11",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.6",
"vimeo/psalm": "^4.15"
},
"autoload": {
"psr-4": {
"Google\\": "src/Google"
}
},
"autoload-dev": {
"psr-4": {
"GoogleTest\\": "test/GoogleTest"
}
}
],
"keywords" : [
"google",
"google-trends",
"google-api",
"trends",
"explore",
"trending",
"related-queries",
"trending-search",
"php-library",
"php"
],
"support": {
"email": "francisc.tar@gmail.com"
},
"license": [
"MIT"
],
"require": {
"php" : "^7.0|^8.0",
"laminas/laminas-json": "^3.0",
"laminas/laminas-http": "^2.6",
"laminas/laminas-stdlib": "^3.1",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^6.3|^9.0",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"Google\\": "src/Google"
}
},
"autoload-dev": {
"psr-4": {
"GoogleTest\\": "test/GoogleTest"
}
}
}
}
94 changes: 41 additions & 53 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,65 @@
require 'vendor/autoload.php';

use Google\GTrends;

$options = [
'hl' => 'en-US',
'tz' => -60,
'geo' => 'IE',
'tz' => 0,
'geo' => 'US',
'time' => 'all',
'category' => 0,
];
/** @var Google\GTrends $gt */
$gt = new GTrends($options);

?>

<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8">
<head>
<meta charset="utf-8">

<title>GTrends</title>
<meta name="description" content="">
<meta name="author" content="">
<title>GTrends</title>
<meta name="description" content="">
<meta name="author" content="">

<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
</head>

<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>

<body>
<?php
<body>
<?php

print_r('<pre>');
print_r('<pre>');

print_r("\n\n <h1>GTrends getDailySearchTrends</h1>\n ");
print_r($gt->getDailySearchTrends());
print_r("\n\n");
print_r("\n\n <h1>GTrends getRealTimeSearchTrends</h1>\n ");
print_r($gt->getRealTimeSearchTrends());
print_r("\n\n");

print_r("\n\n <h1>GTrends getRealTimeSearchTrends</h1>\n ");
print_r($gt->getRealTimeSearchTrends());
print_r("\n\n");
print_r("\n\n <h1>GTrends getDailySearchTrends</h1>\n ");
print_r($gt->getDailySearchTrends());
print_r("\n\n");

print_r("\n\n <h1>GTrends getRelatedSearchQueries</h1>\n ");
print_r($gt->getRelatedSearchQueries(['Donald Trump']));
print_r("\n\n");
print_r("\n\n <h1>GTrends getSuggestionsAutocomplete</h1>\n ");
print_r($gt->getSuggestionsAutocomplete('Donald Trump'));
print_r("\n\n");

print_r("\n\n <h1>GTrends interestOverTime</h1>\n ");
print_r($gt->interestOverTime('Donald Trump'));
print_r("\n\n");
print_r("\n\n <h1>GTrends getGeo</h1>\n ");
print_r($gt->getGeo());
print_r("\n\n");

print_r("\n\n <h1>GTrends getRelatedTopics</h1>\n ");
print_r($gt->getRelatedTopics('Donald Trump'));
print_r("\n\n");
print_r("\n\n <h1>GTrends getCategories</h1>\n ");
print_r($gt->getCategories());
print_r("\n\n");

print_r("\n\n <h1>GTrends interestBySubregion</h1>\n ");
print_r($gt->interestBySubregion(['Dublin']));
print_r("\n\n");
print_r("\n\n <h1>GTrends getAllOneKeyWord</h1>\n ");
print_r($gt->getAllOneKeyWord('Donald Trump'));
print_r("\n\n");

print_r("\n\n <h1>GTrends interestByCity</h1>\n ");
print_r($gt->interestByCity(['Dublin']));
print_r("\n\n");
print_r("\n\n <h1>GTrends getAllMultipleKeyWords</h1>\n ");
print_r($gt->getAllMultipleKeyWords(['Donald Trump', 'Barack Obama']));
print_r("\n\n");

print_r("\n\n <h1>GTrends interestByMetro</h1>\n ");
print_r($gt->interestByMetro(['Dublin']));
print_r("\n\n");

print_r("\n\n <h1>GTrends suggestionsAutocomplete</h1>\n ");
print_r($gt->suggestionsAutocomplete('Donald Trump'));
print_r("\n\n");

print_r("\n\n <h1>GTrends suggestionsAutocomplete</h1>\n ");
print_r($gt->getCategories());
print_r("\n\n");

?>
<script src=""></script>
</body>
?>
<script src=""></script>
</body>
</html>
Loading

0 comments on commit 1bf6243

Please sign in to comment.