Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 58 | All time: 10,535 This week: 524 |
Version | License | PHP version | Categories | |||
polr-api 2.0.0 | GNU General Publi... | 5 | HTTP, PHP 5, Web services |
Description | Author | |
This package provides an API for the Polr URL shortener service. |
A Restful API for the Polr URL Shortener
This package gives access to all Polr features through a Restful API, excepted the following.
Add the Github repository and package to the composer.json
file of your Polr installation, and run composer update
.
{
"repositories": [
{
"type": "git",
"url": "https://github.com/lagdo/polr-api"
}
],
"require": {
"lagdo/polr-api": "dev-master"
}
}
Register the service provider in the bootstrap/app.php
.
$app->register(\Lagdo\Polr\Api\PolrApiServiceProvider::class);
The API endpoints are documented here. The documentation is generated with API Doc.
Sometimes the requests to the API return with errors due to CSRF verification failure. That's because Polr has disabled CSRF verification only for its own API endpoints.
This API endpoints then need to be also added in the app/Http/Middleware\VerifyCsrfToken.php
file.
public function handle($request, \Closure $next) {
if ($request->is('api/v/action/') ||
$request->is('api/v/data/') ||
$request->is('api/v/links/') ||
$request->is('api/v/users/') ||
$request->is('api/v/stats/')) {
// Exclude public API from CSRF protection
// but do not exclude private API endpoints
return $next($request);
}
return parent::handle($request, $next);
}
<a name="top"></a>
Restful API for the Polr URL Shortener
<p>Delete the link with the given ending.</p>
DELETE /links/:ending
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to delete links.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a link with the given ending.</p>|
<p>Fetch a paginated list of links. The input parameters are those of the Datatables library.</p>
GET /links
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | draw | Integer | optional<p>The draw option.</p>| | columns | Object | optional<p>The table columns.</p>| | order | Object | optional<p>The data ordering.</p>| | start | Integer | optional<p>The data offset.</p>| | length | Integer | optional<p>The data count.</p>| | search | Object | optional<p>The search options.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The link list.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to list links.</p>|
<p>Fetch a paginated list of links. The input parameters are those of the Datatables library.</p>
GET /users/me/links
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | draw | Integer | optional<p>The draw option.</p>| | columns | Object | optional<p>The table columns.</p>| | order | Object | optional<p>The data ordering.</p>| | start | Integer | optional<p>The data offset.</p>| | length | Integer | optional<p>The data count.</p>| | search | Object | optional<p>The search options.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Mixed | <p>The link list.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to list links.</p>|
<p>Returns</p>
GET /links/:ending
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | secret | String | optional<p>The link secret.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The link data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a link with the given ending.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>Invalid URL code given for a secret URL.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Create a shortened URL for a given link</p>
POST /links
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | url | String | <p>The link to shorten.</p>| | ending | String | optional<p>A custom ending for the link.</p>| | secret | String | optional<p>Create a secret link or not.</p>| | ip | String | optional<p>The IP address the request came from.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Mixed | <p>The shortened URL.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | CreationError | Object | <p>An error occurs while shortening the link.</p>| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Update the link with the given ending.</p>
PUT /links/:ending
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | url | String | optional<p>The new URL.</p>| | status | String | optional<p>The status change: enable, disable or toggle.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to edit the link.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a link with the given ending.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Fetch stats of a given type for a single link.</p>
GET /links/:ending/stats
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | type | String | <p>The type of stats to fetch.</p>| | ending | String | <p>The short URL id of the link.</p>| | left_bound | String | <p>The start date.</p>| | right_bound | String | <p>The end date.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Mixed | <p>The stats data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to view stats.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AnalyticsError | Object | <p>An error occurs while fetching stats from the database.</p>| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Fetch stats of a given type.</p>
GET /stats
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | type | String | <p>The type of stats to fetch.</p>| | left_bound | String | <p>The start date.</p>| | right_bound | String | <p>The end date.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Mixed | <p>The stats data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to view stats.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AnalyticsError | Object | <p>An error occurs while fetching stats from the database.</p>| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Change the API Settings of the user with the given id.</p>
PUT /users/:id/api
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | quota | String | optional<p>The new API quota.</p>| | status | String | optional<p>The API access change: enable, disable or toggle.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The updated user data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to edit the user.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a user with the given id.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Generate a new API access key for the user with the given id.</p>
POST /users/:id/api
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Mixed | <p>The updated user data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to edit the user.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a user with the given id.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Get the user with the given id</p>
GET /users/:id
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The user data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to get users.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a user with the given id.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
<p>Fetch a paginated list of users. The input parameters are those of the Datatables library.</p>
GET /users
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | draw | Integer | optional<p>The draw option.</p>| | columns | Object | optional<p>The table columns.</p>| | order | Object | optional<p>The data ordering.</p>| | start | Integer | optional<p>The data offset.</p>| | length | Integer | optional<p>The data count.</p>| | search | Object | optional<p>The search options.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The user list.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to list users.</p>|
<p>Update the user with the given id.</p>
PUT /users/:id
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | key | String | <p>The user API key.</p>| | role | String | optional<p>The new role.</p>| | status | String | optional<p>The user status change: enable, disable or toggle.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | message | String | <p>The response message.</p>| | settings | Object | <p>The Polr instance config options.</p>| | result | Object | <p>The updated user data.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | AccessDenied | Object | <p>The user does not have permission to edit the user.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | NotFound | Object | <p>Unable to find a user with the given id.</p>|
| Name | Type | Description | |:---------|:-----------|:--------------------------------------| | MissingParameters | Object | <p>There is a missing or invalid parameter.</p>|
Files (16) |
File | Role | Description | ||
---|---|---|---|---|
docs (1 file) | ||||
src (1 file, 2 directories) | ||||
tests (2 files) | ||||
apidoc.json | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (16) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Helpers (3 files) | ||||
Http (1 file, 2 directories) | ||||
PolrApiServiceProvider.php | Class | Class source |
Files (16) | / | src | / | Helpers |
File | Role | Description |
---|---|---|
ResponseHelper.php | Class | Class source |
StatsHelper.php | Class | Class source |
UserHelper.php | Class | Class source |
Files (16) | / | src | / | Http |
File | Role | Description | ||
---|---|---|---|---|
Controllers (3 files) | ||||
Middleware (1 file) | ||||
routes.php | Example | Example script |
Files (16) | / | src | / | Http | / | Controllers |
File | Role | Description |
---|---|---|
LinkController.php | Class | Class source |
StatsController.php | Class | Class source |
UserController.php | Class | Class source |
Files (16) | / | tests |
File | Role | Description |
---|---|---|
ExampleTest.php | Class | Class source |
TestCase.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Reuses | Unique User Downloads | Download Rankings | ||||||||||||||||
100% | 1 |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Other classes that need this package |
Class | Why it is needed | Dependency |
---|---|---|
Polr Admin Dashboard | Needs to be installed on managed Polr instances | Required |