Skip to content

Commit

Permalink
Merge pull request #1 from ruby232/alpha
Browse files Browse the repository at this point in the history
Add User and WorkItem
  • Loading branch information
doishub authored Dec 11, 2023
2 parents 8d88eb2 + 0112d4d commit 3dda459
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 4 deletions.
61 changes: 61 additions & 0 deletions src/Api/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Oveleon\YouTrack\Api;

class User extends AbstractApi
{
/**
* Overwrites the default fields for users.
*/
protected function defaultFields(): self
{
$this->addFields([
'id',
'login',
'fullName',
'email',
'ringId',
'guest',
'online',
'banned',
'tags',
'savedQueries',
'avatarUrl',
'profiles',
]);

return $this;
}

/**
* Returns all users.
*/
public function all(): array
{
return $this->get("users");
}

/**
* Returns one user by id.
*/
public function one(string $userId): array
{
return $this->get("users/$userId");
}

/**
* Creates a new user.
*/
public function create(array $parameter): array
{
return $this->post("users", $parameter);
}

/**
* Update an existing user.
*/
public function update(string $userId, array $parameter): array
{
return $this->post("users/$userId", $parameter);
}
}
67 changes: 67 additions & 0 deletions src/Api/WorkItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Oveleon\YouTrack\Api;

class WorkItem extends AbstractApi
{
/**
* Overwrites the default fields for work items.
*/
protected function defaultFields(): self
{
$this->addFields([
'id',
'author' => [
'id'
],
'becomesRemoved',
'created',
'creator',
'date',
'description',
'duration' => [
'presentation',
'minutes'
],
'isNew',
'type',
'updated',
'issue' =>[
'id',
'customFields' => [
'name',
'$type',
'value' => [
'name'
],
],
]
]);

return $this;
}

/**
* Returns all work items.
*/
public function all(): array
{
return $this->get("workItems");
}

/**
* Returns one work item by id.
*/
public function one(string $workItemId): array
{
return $this->get("workItems/$workItemId");
}


public function query(string $name, string $value): self
{
$this->addQuery($name, $value);

return $this;
}
}
17 changes: 13 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Oveleon\YouTrack\Api\Issue;
use Oveleon\YouTrack\Api\Project;
use Oveleon\YouTrack\Api\User;
use Oveleon\YouTrack\Api\WorkItem;
use Oveleon\YouTrack\HttpClient\HttpClientInterface;

class Client
Expand All @@ -21,18 +23,25 @@ public function getHttpClient(): HttpClientInterface
}

/**
* Entry point for issues
* Entry points.
*/
public function issues(): Issue
{
return new Issue($this);
}

/**
* Entry point for projects
*/
public function projects(): Project
{
return new Project($this);
}

public function users(): User
{
return new User($this);
}

public function workItems(): WorkItem
{
return new WorkItem($this);
}
}

0 comments on commit 3dda459

Please sign in to comment.