Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete link API functionality #632

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions app/Http/Controllers/Api/ApiLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,19 @@ public function lookupLink(Request $request) {
throw new ApiException('NOT_FOUND', 'Link not found.', 404, $response_type);
}
}

public function deleteLink(Request $request) {

$response_type = $request->input('response_type');
$url_ending = $request->input('url_ending');
$link = LinkHelper::linkExists($url_ending);

if (!$link) {
throw new ApiException('DELETION ERROR','The Short Link to delete was not found', 404, $response_type);
}

$link->delete();
return "OK";
}

}
3 changes: 3 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@
/* API data endpoints */
$app->get('data/link', ['as' => 'api_link_analytics', 'uses' => 'ApiAnalyticsController@lookupLinkStats']);
$app->post('data/link', ['as' => 'api_link_analytics', 'uses' => 'ApiAnalyticsController@lookupLinkStats']);

/*API delete endpoints */
$app->get('admin/delete_link', ['as' => 'api_delete_link', 'uses' => 'ApiLinkController@deleteLink']);
});
14 changes: 14 additions & 0 deletions docs/developer-guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ Response:
}
```

### /api/v2/admin/delete_link
Arguments:

- `url_ending`: the link ending for the URL to delete. (e.g `5ga`)

An API key granted to a regular user can only be used to delete their own links.
Admins can delete any link.

Response: An OK if the link was deleted, unauthorised if not authorised to delete or 404 if the link does not exist.

Example: GET `http://example.com/api/v2/admin/delete_link?key=API_KEY_HERE&url_ending=5gk`

Response: `OK`

## HTTP Error Codes
The API will return an error code if your request was malformed or another error occured while processing your request.

Expand Down