Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/serpapi-php.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHP build
name: serpapi-php
on:
push:
branches: [ master ]
Expand Down Expand Up @@ -63,4 +63,4 @@ jobs:
- name: Run test suite
run: composer run-script test
env:
API_KEY: ${{ secrets.API_KEY }}
SERPAPI_KEY: ${{ secrets.SERPAPI_KEY }}
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require 'vendor/autoload.php';

use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'q' => 'coffee',
]);
Expand Down Expand Up @@ -88,7 +88,7 @@ The default engine is `google`. You can change it via the second constructor par
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'bing');
$client = new Client(getenv('SERPAPI_KEY'), 'bing');
$results = $client->search(['q' => 'coffee']);
```

Expand All @@ -99,7 +99,7 @@ The default request timeout is 120 seconds. Customize it via the third construct
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'google', 30);
$client = new Client(getenv('SERPAPI_KEY'), 'google', 30);
```

## Search API
Expand All @@ -108,7 +108,7 @@ $client = new Client(getenv('API_KEY'), 'google', 30);
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google',
'tbm' => 'isch',
Expand All @@ -125,7 +125,7 @@ see: [https://serpapi.com/search-api](https://serpapi.com/search-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_scholar',
'q' => 'coffee',
Expand All @@ -141,7 +141,7 @@ see: [https://serpapi.com/google-scholar-api](https://serpapi.com/google-scholar
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_autocomplete',
'q' => 'coffee',
Expand All @@ -157,7 +157,7 @@ see: [https://serpapi.com/google-autocomplete-api](https://serpapi.com/google-au
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_shopping',
'q' => 'coffee',
Expand All @@ -173,7 +173,7 @@ see: [https://serpapi.com/google-shopping-api](https://serpapi.com/google-shoppi
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_maps',
'q' => 'pizza',
Expand All @@ -191,7 +191,7 @@ see: [https://serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_jobs',
'q' => 'coffee',
Expand All @@ -207,7 +207,7 @@ see: [https://serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_events',
'q' => 'Events in Austin',
Expand All @@ -224,7 +224,7 @@ see: [https://serpapi.com/google-events-api](https://serpapi.com/google-events-a
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_lens',
'url' => 'https://i.imgur.com/5bGzZi7.jpg',
Expand All @@ -242,7 +242,7 @@ see: [https://serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_play',
'q' => 'kite',
Expand All @@ -259,7 +259,7 @@ see: [https://serpapi.com/google-play-api](https://serpapi.com/google-play-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'google_local_services',
'q' => 'electrician',
Expand All @@ -276,7 +276,7 @@ see: [https://serpapi.com/google-local-services-api](https://serpapi.com/google-
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'bing',
'q' => 'coffee',
Expand All @@ -292,7 +292,7 @@ see: [https://serpapi.com/bing-search-api](https://serpapi.com/bing-search-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'baidu',
'q' => 'coffee',
Expand All @@ -308,7 +308,7 @@ see: [https://serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'yahoo',
'p' => 'coffee',
Expand All @@ -324,7 +324,7 @@ see: [https://serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'youtube',
'search_query' => 'coffee',
Expand All @@ -340,7 +340,7 @@ see: [https://serpapi.com/youtube-search-api](https://serpapi.com/youtube-search
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'walmart',
'query' => 'coffee',
Expand All @@ -356,7 +356,7 @@ see: [https://serpapi.com/walmart-search-api](https://serpapi.com/walmart-search
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'ebay',
'_nkw' => 'water',
Expand All @@ -372,7 +372,7 @@ see: [https://serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'naver',
'query' => 'coffee',
Expand All @@ -388,7 +388,7 @@ see: [https://serpapi.com/naver-search-api](https://serpapi.com/naver-search-api
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'home_depot',
'q' => 'table',
Expand All @@ -404,7 +404,7 @@ see: [https://serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'apple_app_store',
'term' => 'coffee',
Expand All @@ -420,7 +420,7 @@ see: [https://serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'engine' => 'duckduckgo',
'q' => 'coffee',
Expand All @@ -439,7 +439,7 @@ see: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$locations = $client->location(['q' => 'Austin', 'limit' => 3]);

echo "Number of locations: " . count($locations) . "\n";
Expand All @@ -455,7 +455,7 @@ First, run a search and save the search ID:
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'q' => 'Coffee',
'location' => 'Austin, Texas',
Expand All @@ -475,7 +475,7 @@ print_r($archived);
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$account = $client->account();
print_r($account);
```
Expand All @@ -485,7 +485,7 @@ print_r($account);
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$html = $client->html(['q' => 'Coffee']);

echo strlen($html) . " bytes of HTML\n";
Expand Down Expand Up @@ -524,7 +524,7 @@ The `tests/` directory includes specifications which serve the dual purposes of
Set your secret API key in your shell before running tests:

```bash
export API_KEY="your_secret_key"
export SERPAPI_KEY="your_secret_key"
```

Install dependencies and run the test suite:
Expand Down
18 changes: 9 additions & 9 deletions README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def snippet(path)
property = source[/assertResponseHasProperty\(\$response,\s*'([^']+)'/, 1] || 'organic_results'

code = "use SerpApi\\Client;\n\n"
code += "$client = new Client(getenv('API_KEY'));\n"
code += "$client = new Client(getenv('SERPAPI_KEY'));\n"
code += "$results = $client->search(#{params});\n\n"
code += "print_r($results->#{property});\n"

Expand Down Expand Up @@ -74,7 +74,7 @@ require 'vendor/autoload.php';

use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'q' => 'coffee',
]);
Expand Down Expand Up @@ -112,7 +112,7 @@ The default engine is `google`. You can change it via the second constructor par
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'bing');
$client = new Client(getenv('SERPAPI_KEY'), 'bing');
$results = $client->search(['q' => 'coffee']);
```

Expand All @@ -123,7 +123,7 @@ The default request timeout is 120 seconds. Customize it via the third construct
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'google', 30);
$client = new Client(getenv('SERPAPI_KEY'), 'google', 30);
```

## Search API
Expand Down Expand Up @@ -215,7 +215,7 @@ see: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$locations = $client->location(['q' => 'Austin', 'limit' => 3]);

echo "Number of locations: " . count($locations) . "\n";
Expand All @@ -231,7 +231,7 @@ First, run a search and save the search ID:
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$results = $client->search([
'q' => 'Coffee',
'location' => 'Austin, Texas',
Expand All @@ -251,7 +251,7 @@ print_r($archived);
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$account = $client->account();
print_r($account);
```
Expand All @@ -261,7 +261,7 @@ print_r($account);
```php
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$client = new Client(getenv('SERPAPI_KEY'));
$html = $client->html(['q' => 'Coffee']);

echo strlen($html) . " bytes of HTML\n";
Expand Down Expand Up @@ -300,7 +300,7 @@ The `tests/` directory includes specifications which serve the dual purposes of
Set your secret API key in your shell before running tests:

```bash
export API_KEY="your_secret_key"
export SERPAPI_KEY="your_secret_key"
```

Install dependencies and run the test suite:
Expand Down
6 changes: 3 additions & 3 deletions tests/SerpApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function setUp(): void
$resolved = $this->resolveApiKey();

if ($resolved === null && $this->requiresApiKey()) {
$this->markTestSkipped('API_KEY is not set');
$this->markTestSkipped('SERPAPI_KEY is not set');
return;
}

Expand All @@ -30,13 +30,13 @@ protected function requiresApiKey(): bool

protected function resolveApiKey(): ?string
{
$env = $_ENV['API_KEY'] ?? null;
$env = $_ENV['SERPAPI_KEY'] ?? null;

if (!empty($env)) {
return $env;
}

$value = getenv('API_KEY');
$value = getenv('SERPAPI_KEY');
if (!empty($value)) {
return $value;
}
Expand Down
Loading