Skip to content

Commit

Permalink
Addition of new license issuing/modifying semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
Majored committed Jan 6, 2022
1 parent 9ebf3e5 commit 28d5fe4
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions src/helpers/resources/LicensesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,78 @@ function fetchByMember(int $resource_id, int $member_id): APIResponse {
}

/**
* Issue a new resource license.
* Issue a new permanent resource license.
*
* @param int The identifier of the resource.
* @param int The identifier of the member.
* @param bool Whether or not the license should be active.
*
* @return APIResponse The parsed API response.
*/
function issuePermanent(int $resource_id, int $member_id, bool $active): APIResponse {
$body = [
"purchaser_id" => $member_id,
"permanent" => true,
"active" => $active
];

return $this->wrapper->post(sprintf("resources/%d/licenses", $resource_id), $body);
}

/**
* Issue a new temporary resource license.
*
* @param int The identifier of the resource.
* @param int The identifier of the member.
* @param int The start date of the license as a UNIX timestamp.
* @param int The end date of the license as a UNIX timestamp.
* @param bool Whether or not the license should be active.
*
* @return APIResponse The parsed API response.
*/
function issue(int $resource_id, int $member_id, int $start_date, int $end_date, bool $active): APIResponse {
function issueTemporary(int $resource_id, int $member_id, int $start_date, int $end_date): APIResponse {
$body = [
"purchaser_id" => $member_id,
"permanent" => false,
"start_date" => $start_date,
"end_date" => $end_date,
"active" => $active
"end_date" => $end_date
];

return $this->wrapper->post(sprintf("resources/%d/licenses", $resource_id), $body);
}

/**
* Modify an existing resource license.
* Modify a permanent license (and convert to permanent if currently temporary).
*
* @param int The identifier of the resource.
* @param int The identifier of the license.
* @param bool Whether or not the license should be active, or null if unchanged.
*
* @return APIResponse The parsed API response.
*/
function modifyPermanent(int $resource_id, int $license_id, bool $active): APIResponse {
$body = [
"permanent" => false,
"active" => $active
];

return $this->wrapper->patch(sprintf("resources/%d/licenses/%d", $resource_id, $license_id), $body);
}

/**
* Modify a temporary license (and convert to temporary if currently permanent).
*
* @param int The identifier of the resource.
* @param int The identifier of the license.
* @param int The start date of the license as a UNIX timestamp, or null if unchanged.
* @param int The end date of the license as a UNIX timestamp, or null if unchanged.
* @param bool Whether or not the license should be active, or null if unchanged.
*
* @return APIResponse The parsed API response.
*/
function modify(int $resource_id, int $license_id, int $start_date, int $end_date, bool $active): APIResponse {
function modifyTemporary(int $resource_id, int $license_id, int $start_date, int $end_date): APIResponse {
$body = [
"permanent" => false,
"start_date" => $start_date,
"end_date" => $end_date,
"active" => $active
];

return $this->wrapper->patch(sprintf("resources/%d/licenses/%d", $resource_id, $license_id), $body);
Expand Down

0 comments on commit 28d5fe4

Please sign in to comment.