Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nemorize committed Jul 31, 2023
0 parents commit 7602a8a
Show file tree
Hide file tree
Showing 14 changed files with 3,116 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/.idea/
/node_modules/
14 changes: 14 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2023 Ji Yong, Kim <nemo@qroffle.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# php-indexnow

**php-indexnow** is a PHP library for [IndexNow](https://indexnow.org) API.

## Example usage
```bash
composer require nemorize/indexnow
```
```php
$indexnow = new \Nemorize\Indexnow\Indexnow();
$indexnow->setKey('fc1e3ad82010475381daf9846e627fdd');
$indexnow->submit('https://example.com/url-changed');
$indexnow->submit([
'https://example.com/url-changed',
'https://example.com/url-changed-2'
]);
```

## Specification

### setHost
```php
Indexnow::setHost (string $host): void;
```
You can change the hostname of the API. If you don't set the hostname, the default host is `api.indexnow.org`.

### getHost
```php
Indexnow::getHost (): string;
```
Returns the hostname of the API.

### setKey
```php
Indexnow::setKey (string $key): void;
```
You can change the key of the API.

### getKey
```php
Indexnow::getKey (): string;
```
Returns the key of the API.

### setKeyLocation
```php
Indexnow::setKeyLocation (?string $keyLocation): void;
```
You can change the key location of the API. If you want to unset the key location, you can set `null`.

### getKeyLocation
```php
Indexnow::getKeyLocation (): ?string;
```
Returns the key location of the API.

### submit
```php
Indexnow::submit (string|array $url, array $guzzleOptions = null): void;
```
You can submit a URL to the API. If you use `$url` as an array, it will submit multiple URLs using JSON request.
`$guzzleOptions` is an array of options for [Guzzle](https://docs.guzzlephp.org/en/stable/quickstart.html#making-a-request).

#### Exceptions
`submit` method throws exceptions if some errors occur.
If the API throws well-known non-20x response codes, it will throw the following exceptions that extend `IndexnowException`.
Any other errors will throw `GuzzleException`.

- `BadRequestException`
- `ForbiddenException`
- `TooManyRequestsException`
- `UnprocessableEntityException`

## License
MIT License
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nemorize/indexnow",
"description": "PHP library for submitting website URLs using IndexNow to search engines.",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Nemorize\\Indexnow\\": "src/"
}
},
"authors": [
{
"name": "Ji Yong, Kim",
"email": "nemo@qroffle.com"
}
],
"require": {
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.7"
}
}
Loading

0 comments on commit 7602a8a

Please sign in to comment.