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

Matching Go Capabilities #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
308 changes: 294 additions & 14 deletions src/Gorse.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,46 +76,326 @@ function __construct(string $endpoint, string $apiKey)
$this->apiKey = $apiKey;
}

/**
* @throws GuzzleException
*/
function insertFeedback(array $feedbacks): RowAffected
{
return RowAffected::fromJSON($this->request('POST', '/api/feedback', $feedbacks));
}

/**
* @throws GuzzleException
*/
function putFeedback(array $feedbacks): RowAffected
{
return RowAffected::fromJSON($this->request('PUT', '/api/feedback', $feedbacks));
}

/**
* @throws GuzzleException
*/
function getFeedback(string $cursor, int $n): array
{
return $this->request('GET', '/api/feedback?cursor=' . $cursor . '&n=' . $n, null);
}

/**
* @throws GuzzleException
*/
function getFeedbacksWithType(string $feedbackType, string $cursor, int $n): array
{
return $this->request('GET', '/api/feedback/' . $feedbackType . '?cursor=' . $cursor . '&n=' . $n, null);
}

/**
* @throws GuzzleException
*/
function getFeedbackWithUserItem(string $userId, string $itemId): array
{
return $this->request('GET', '/api/feedback/' . $userId . '/' . $itemId, null);
}

/**
* @throws GuzzleException
*/
function getFeedbackWithTypeUserItem(string $feedbackType, string $userId, string $itemId): Feedback
{
return Feedback::fromJSON($this->request('GET', '/api/feedback/' . $feedbackType . '/' . $userId . '/' . $itemId, null));
}

/**
* @throws GuzzleException
*/
function delFeedback(string $feedbackType, string $userId, string $itemId): Feedback
{
return Feedback::fromJSON($this->request('DELETE', '/api/feedback/' . $feedbackType . '/' . $userId . '/' . $itemId, null));
}

/**
* @throws GuzzleException
*/
function delFeedbackWithUserItem(string $userId, string $itemId): array
{
return $this->request('DELETE', '/api/feedback/' . $userId . '/' . $itemId, null);
}

/**
* @throws GuzzleException
*/
function getItemFeedbacks(string $itemId)
{
return $this->request('GET', "/api/item/$itemId/feedback", null);
}

/**
* @throws GuzzleException
*/
function getItemFeedbacksWithType(string $itemId, string $feedbackType)
{
return $this->request('GET', "/api/item/$itemId/feedback/$feedbackType", null);
}

/**
* @throws GuzzleException
*/
function getUserFeedbacks(string $userId)
{
return $this->request('GET', "/api/user/$userId/feedback", null);
}

/**
* @throws GuzzleException
*/
function getUserFeedbacksWithType(string $userId, string $feedbackType)
{
return $this->request('GET', "/api/user/$userId/feedback/$feedbackType", null);
}

/**
* @throws GuzzleException
*/
function getItemLatest(string $userId, int $n, int $offset)
{
return $this->request('GET', "/api/latest?user-id=$userId&n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemLatestWithCategory(string $userId, string $category, int $n, int $offset)
{
return $this->request('GET', "/api/latest?user-id=$userId&category=$category&n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemPopular(string $userId, int $n, int $offset)
{
return $this->request('GET', "/api/popular?user-id=$userId&n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemPopularWithCategory(string $userId, string $category, int $n, int $offset)
{
return $this->request('GET', "/api/popular/$category?user-id=$userId&n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemRecommend(string $userId, array $categories, string $writeBackType, string $writeBackDelay, int $n, int $offset)
{
$queryCategories = http_build_query(['category' => $categories], '', '&');
return $this->request('GET', "/api/recommend/$userId?write-back-type=$writeBackType&write-back-delay=$writeBackDelay&n=$n&offset=$offset&$queryCategories", null);
}

/**
* @throws GuzzleException
*/
function getItemRecommendWithCategory(string $userId, string $category, string $writeBackType, string $writeBackDelay, int $n, int $offset)
{
return $this->request('GET', "/api/recommend/$userId/$category?write-back-type=$writeBackType&write-back-delay=$writeBackDelay&n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getSessionItemRecommend(array $feedbacks, int $n, int $offset)
{
return $this->request('POST', "/api/session/recommend?n=$n&offset=$offset", $feedbacks);
}

/**
* @throws GuzzleException
*/
function getSessionItemRecommendWithCategory(array $feedbacks, string $category, int $n, int $offset)
{
return $this->request('POST', "/api/session/recommend/$category?n=$n&offset=$offset", $feedbacks);
}

/**
* @throws GuzzleException
*/
function getUserNeighbors(string $userId, int $n, int $offset)
{
return $this->request('GET', "/api/user/$userId/neighbors?n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemNeighbors(string $itemId, int $n, int $offset)
{
return $this->request('GET', "/api/item/$itemId/neighbors?n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function getItemNeighborsWithCategory(string $itemId, string $category, int $n, int $offset)
{
return $this->request('GET', "/api/item/$itemId/neighbors/$category?n=$n&offset=$offset", null);
}

/**
* @throws GuzzleException
*/
function insertUser(User $user): RowAffected
{
return RowAffected::fromJSON($this->request('POST', '/api/user/', $user));
return RowAffected::fromJSON($this->request('POST', '/api/user', $user->jsonSerialize()));
}

/**
* @throws GuzzleException
*/
function getUser(string $user_id): User
function insertUsers(array $users): RowAffected
{
return User::fromJSON($this->request('GET', '/api/user/' . $user_id, null));
$usersData = array_map(function($user) {
return $user->jsonSerialize();
}, $users);
return RowAffected::fromJSON($this->request('POST', '/api/users', $usersData));
}

/**
* @throws GuzzleException
*/
function deleteUser(string $user_id): RowAffected
function updateUser(string $userId, array $userPatch): RowAffected
{
return RowAffected::fromJSON($this->request('DELETE', '/api/user/' . $user_id, null));
return RowAffected::fromJSON($this->request('PATCH', "/api/user/$userId", $userPatch));
}

/**
* @throws GuzzleException
*/
function insertFeedback(array $feedback): RowAffected
function getUser(string $userId): User
{
return RowAffected::fromJSON($this->request('POST', '/api/feedback/', $feedback));
return User::fromJSON($this->request('GET', "/api/user/$userId", null));
}


/**
* @throws GuzzleException
*/
function getUsers(string $cursor = '', int $n = 0)
{
$queryParams = http_build_query(['cursor' => $cursor, 'n' => $n]);
return $this->request('GET', "/api/users?$queryParams", null);
}

/**
* @throws GuzzleException
*/
function deleteUser(string $userId): RowAffected
{
return RowAffected::fromJSON($this->request('DELETE', "/api/user/$userId", null));
}

/**
* @throws GuzzleException
*/
function insertItem(array $item): RowAffected
{
return RowAffected::fromJSON($this->request('POST', '/api/item', $item));
}

/**
* @throws GuzzleException
*/
function insertItems(array $items): RowAffected
{
return RowAffected::fromJSON($this->request('POST', '/api/items', $items));
}

/**
* @throws GuzzleException
*/
function updateItem(string $itemId, array $itemPatch): RowAffected
{
return RowAffected::fromJSON($this->request('PATCH', "/api/item/$itemId", $itemPatch));
}

/**
* @throws GuzzleException
*/
function getItem(string $itemId)
{
return $this->request('GET', "/api/item/$itemId", null);
}

/**
* @throws GuzzleException
*/
function getItems(string $cursor = '', int $n = 0)
{
$queryParams = http_build_query(['cursor' => $cursor, 'n' => $n]);
return $this->request('GET', "/api/items?$queryParams", null);
}

/**
* @throws GuzzleException
*/
function getRecommend(string $user_id): array
function deleteItem(string $itemId): RowAffected
{
return $this->request('GET', '/api/recommend/' . $user_id, null);
return RowAffected::fromJSON($this->request('DELETE', "/api/item/$itemId", null));
}

/**
* @throws GuzzleException
*/
function putItemCategory(string $itemId, string $category): RowAffected
{
return RowAffected::fromJSON($this->request('PUT', "/api/item/$itemId/category/$category", null));
}

/**
* @throws GuzzleException
*/
function delItemCategory(string $itemId, string $category): RowAffected
{
return RowAffected::fromJSON($this->request('DELETE', "/api/item/$itemId/category/$category", null));
}


/**
* @throws GuzzleException
*/
function healthLive()
{
return $this->request('GET', "/api/health/live", null);
}

/**
* @throws GuzzleException
*/
function healthReady()
{
return $this->request('GET', "/api/health/ready", null);
}


/**
* @throws GuzzleException
*/
Expand All @@ -129,4 +409,4 @@ private function request(string $method, string $uri, $body)
$response = $client->request($method, $uri, $options);
return json_decode($response->getBody());
}
}
}
Loading