diff --git a/README.md b/README.md index 8800722..e46ae51 100644 --- a/README.md +++ b/README.md @@ -56,11 +56,11 @@ The `FloatClient` is bound to the Laravel service container and can be injected: ```php use Spatie\FloatSdk\FloatClient; -public function __construct(protected FloatClient $client) {} +public function __construct(protected FloatClient $float) {} public function index() { - $users = $this->client->users()->all(); + $users = $this->float->users()->all(); } ``` @@ -71,6 +71,7 @@ The `FloatClient` exposes the following resource groups: - projects() - tasks() - clients() +- allocations() Each group has methods to fetch individual records or lists with optional filters. @@ -79,20 +80,20 @@ Each group has methods to fetch individual records or lists with optional filter #### Get user by ID ```php -$user = $client->users()->get(1); +$user = $float->users()->get(1); ``` #### Get all users ```php // Without filters -$users = $client->users()->all(); +$users = $float->users()->all(); // With filters -use Spatie\FloatSdk\QueryParameters\GetUsersParameters; +use Spatie\FloatSdk\QueryParameters\GetUsersParams; -$users = $client->users()->all( - new GetUsersParameters( +$users = $float->users()->all( + new GetUsersParams( active: true, departmentId: 5, ) @@ -104,20 +105,20 @@ $users = $client->users()->all( #### Get project by ID ```php -$project = $client->projects()->get(10); +$project = $float->projects()->get(10); ``` #### Get all projects ```php // Without filters -$projects = $client->projects()->all(); +$projects = $float->projects()->all(); // With filters -use Spatie\FloatSdk\QueryParameters\GetProjectsParameters; +use Spatie\FloatSdk\QueryParameters\GetProjectsParams; -$projects = $client->projects()->all( - new GetProjectsParameters( +$projects = $float->projects()->all( + new GetProjectsParams( clientId: 10, tagName: 'Design', fields: ['id', 'name'], @@ -131,20 +132,20 @@ $projects = $client->projects()->all( #### Get task by ID ```php -$task = $client->tasks()->get(1); +$task = $float->tasks()->get(1); ``` #### Get all tasks ```php // Without filters -$tasks = $client->tasks()->all(); +$tasks = $float->tasks()->all(); // With filters -use Spatie\FloatSdk\QueryParameters\GetTasksParameters; +use Spatie\FloatSdk\QueryParameters\GetTasksParams; -$tasks = $client->tasks()->all( - new GetTasksParameters( +$tasks = $float->tasks()->all( + new GetTasksParams( projectId: 42, billable: true, fields: ['id', 'name'], @@ -152,6 +153,56 @@ $tasks = $client->tasks()->all( ); ``` +### Clients + +#### Get client by ID + +```php +$client = $client->clients()->get(1); +``` + +#### Get all clients + +```php +// Without filters +$clients = $float->clients()->all(); + +// With filters +use Spatie\FloatSdk\QueryParameters\GetClientsParams; + +$clients = $float->clients()->all( + new GetClientsParams( + fields: ['id', 'name'], + expand: ['projects'], + ) +); +``` + +### Allocations + +#### Get allocations by ID + +```php +$client = $float->allocations()->get(1); +``` + +#### Get all allocations + +```php +// Without filters +$allocations = $float->allocations()->all(); + +// With filters +use Spatie\FloatSdk\QueryParameters\GetAllocationsParams; + +$allocations = $float->allocations()->all( + new GetAllocationsParams( + fields: ['id', 'start_date'], + expand: ['project'], + ) +); +``` + ### Pagination & Sorting You can pass a parameter object to the `all()` methods. All parameters are optional. @@ -161,7 +212,9 @@ You can pass a parameter object to the `all()` methods. All parameters are optio - `sort` (string): Sort field (e.g., "name", "modified_since") ```php -new GetUsersParameters( +use Spatie\FloatSdk\QueryParameters\GetUsersParams; + +new GetUsersParams( page: 2, perPage: 25, sort: 'name' @@ -173,7 +226,9 @@ new GetUsersParameters( Limit which fields are returned by passing the `fields` array: ```php -new GetProjectsParameters( +use Spatie\FloatSdk\QueryParameters\GetProjectsParams; + +new GetProjectsParams( fields: ['id', 'name', 'client_id'] ); ``` @@ -182,7 +237,9 @@ new GetProjectsParameters( Some endpoints support expanding related data using the `expand` array: ```php -new GetProjectsParameters( +use Spatie\FloatSdk\QueryParameters\GetProjectsParams; + +new GetProjectsParams( expand: ['client'] ); diff --git a/src/FloatClient.php b/src/FloatClient.php index 34214e7..38414ff 100755 --- a/src/FloatClient.php +++ b/src/FloatClient.php @@ -4,6 +4,7 @@ use Saloon\Http\Auth\TokenAuthenticator; use Saloon\Http\Connector; +use Spatie\FloatSdk\Groups\AllocationsGroup; use Spatie\FloatSdk\Groups\ClientsGroup; use Spatie\FloatSdk\Groups\ProjectsGroup; use Spatie\FloatSdk\Groups\TasksGroup; @@ -54,4 +55,9 @@ public function clients(): ClientsGroup { return new ClientsGroup($this); } + + public function allocations(): AllocationsGroup + { + return new AllocationsGroup($this); + } } diff --git a/src/Groups/AllocationsGroup.php b/src/Groups/AllocationsGroup.php new file mode 100644 index 0000000..2ddbcc2 --- /dev/null +++ b/src/Groups/AllocationsGroup.php @@ -0,0 +1,22 @@ +connector->send(new GetAllocation($allocationId)); + } + + public function all(?GetAllocationsParams $parameters = null): Response + { + return $this->connector->send(new GetAllocations($parameters)); + } +} diff --git a/src/Groups/ClientsGroup.php b/src/Groups/ClientsGroup.php index 7867e49..f94e526 100644 --- a/src/Groups/ClientsGroup.php +++ b/src/Groups/ClientsGroup.php @@ -4,7 +4,7 @@ use Saloon\Http\BaseResource; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetClientsParameters; +use Spatie\FloatSdk\QueryParameters\GetClientsParams; use Spatie\FloatSdk\Requests\GetClient; use Spatie\FloatSdk\Requests\GetClients; @@ -15,7 +15,7 @@ public function get(int $clientId): Response return $this->connector->send(new GetClient($clientId)); } - public function all(?GetClientsParameters $parameters = null): Response + public function all(?GetClientsParams $parameters = null): Response { return $this->connector->send(new GetClients($parameters)); } diff --git a/src/Groups/ProjectsGroup.php b/src/Groups/ProjectsGroup.php index 2371fd2..8855e95 100644 --- a/src/Groups/ProjectsGroup.php +++ b/src/Groups/ProjectsGroup.php @@ -4,7 +4,7 @@ use Saloon\Http\BaseResource; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetProjectsParameters; +use Spatie\FloatSdk\QueryParameters\GetProjectsParams; use Spatie\FloatSdk\Requests\GetProject; use Spatie\FloatSdk\Requests\GetProjects; @@ -15,7 +15,7 @@ public function get(int $projectId): Response return $this->connector->send(new GetProject($projectId)); } - public function all(?GetProjectsParameters $parameters = null): Response + public function all(?GetProjectsParams $parameters = null): Response { return $this->connector->send(new GetProjects($parameters)); } diff --git a/src/Groups/TasksGroup.php b/src/Groups/TasksGroup.php index 53b89ae..e09f486 100644 --- a/src/Groups/TasksGroup.php +++ b/src/Groups/TasksGroup.php @@ -4,7 +4,7 @@ use Saloon\Http\BaseResource; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetTasksParameters; +use Spatie\FloatSdk\QueryParameters\GetTasksParams; use Spatie\FloatSdk\Requests\GetTask; use Spatie\FloatSdk\Requests\GetTasks; @@ -15,7 +15,7 @@ public function get(int $taskId): Response return $this->connector->send(new GetTask($taskId)); } - public function all(?GetTasksParameters $parameters = null): Response + public function all(?GetTasksParams $parameters = null): Response { return $this->connector->send(new GetTasks($parameters)); } diff --git a/src/Groups/UsersGroup.php b/src/Groups/UsersGroup.php index 62f2b41..4380f50 100644 --- a/src/Groups/UsersGroup.php +++ b/src/Groups/UsersGroup.php @@ -4,7 +4,7 @@ use Saloon\Http\BaseResource; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetUsersParameters; +use Spatie\FloatSdk\QueryParameters\GetUsersParams; use Spatie\FloatSdk\Requests\GetUser; use Spatie\FloatSdk\Requests\GetUsers; @@ -15,7 +15,7 @@ public function get(int $userId): Response return $this->connector->send(new GetUser($userId)); } - public function all(?GetUsersParameters $parameters = null): Response + public function all(?GetUsersParams $parameters = null): Response { return $this->connector->send(new GetUsers($parameters)); } diff --git a/src/QueryParameters/GetAllocationsParameters.php b/src/QueryParameters/GetAllocationsParams.php similarity index 98% rename from src/QueryParameters/GetAllocationsParameters.php rename to src/QueryParameters/GetAllocationsParams.php index cc060fb..b9c464f 100644 --- a/src/QueryParameters/GetAllocationsParameters.php +++ b/src/QueryParameters/GetAllocationsParams.php @@ -4,7 +4,7 @@ use Spatie\FloatSdk\Concerns\HasPaginationAndSort; -class GetAllocationsParameters +class GetAllocationsParams { use HasPaginationAndSort; diff --git a/src/QueryParameters/GetClientsParameters.php b/src/QueryParameters/GetClientsParams.php similarity index 97% rename from src/QueryParameters/GetClientsParameters.php rename to src/QueryParameters/GetClientsParams.php index 9566a47..a4b3914 100644 --- a/src/QueryParameters/GetClientsParameters.php +++ b/src/QueryParameters/GetClientsParams.php @@ -4,7 +4,7 @@ use Spatie\FloatSdk\Concerns\HasPaginationAndSort; -class GetClientsParameters +class GetClientsParams { use HasPaginationAndSort; diff --git a/src/QueryParameters/GetProjectsParameters.php b/src/QueryParameters/GetProjectsParams.php similarity index 98% rename from src/QueryParameters/GetProjectsParameters.php rename to src/QueryParameters/GetProjectsParams.php index c952abd..84c9e1c 100644 --- a/src/QueryParameters/GetProjectsParameters.php +++ b/src/QueryParameters/GetProjectsParams.php @@ -4,7 +4,7 @@ use Spatie\FloatSdk\Concerns\HasPaginationAndSort; -class GetProjectsParameters +class GetProjectsParams { use HasPaginationAndSort; diff --git a/src/QueryParameters/GetTasksParameters.php b/src/QueryParameters/GetTasksParams.php similarity index 97% rename from src/QueryParameters/GetTasksParameters.php rename to src/QueryParameters/GetTasksParams.php index b88ca43..ed63970 100644 --- a/src/QueryParameters/GetTasksParameters.php +++ b/src/QueryParameters/GetTasksParams.php @@ -4,7 +4,7 @@ use Spatie\FloatSdk\Concerns\HasPaginationAndSort; -class GetTasksParameters +class GetTasksParams { use HasPaginationAndSort; diff --git a/src/QueryParameters/GetUsersParameters.php b/src/QueryParameters/GetUsersParams.php similarity index 98% rename from src/QueryParameters/GetUsersParameters.php rename to src/QueryParameters/GetUsersParams.php index 6a82e22..2282c86 100644 --- a/src/QueryParameters/GetUsersParameters.php +++ b/src/QueryParameters/GetUsersParams.php @@ -4,7 +4,7 @@ use Spatie\FloatSdk\Concerns\HasPaginationAndSort; -class GetUsersParameters +class GetUsersParams { use HasPaginationAndSort; diff --git a/src/Requests/GetAllocations.php b/src/Requests/GetAllocations.php index fdc3d25..e8db10f 100644 --- a/src/Requests/GetAllocations.php +++ b/src/Requests/GetAllocations.php @@ -5,7 +5,7 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetAllocationsParameters; +use Spatie\FloatSdk\QueryParameters\GetAllocationsParams; use Spatie\FloatSdk\Resources\TaskResource; class GetAllocations extends Request @@ -13,7 +13,7 @@ class GetAllocations extends Request protected Method $method = Method::GET; public function __construct( - protected ?GetAllocationsParameters $parameters = null + protected ?GetAllocationsParams $parameters = null ) {} protected function defaultQuery(): array diff --git a/src/Requests/GetClients.php b/src/Requests/GetClients.php index 36012d0..3a63761 100644 --- a/src/Requests/GetClients.php +++ b/src/Requests/GetClients.php @@ -5,7 +5,7 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetClientsParameters; +use Spatie\FloatSdk\QueryParameters\GetClientsParams; use Spatie\FloatSdk\Resources\ClientResource; class GetClients extends Request @@ -13,7 +13,7 @@ class GetClients extends Request protected Method $method = Method::GET; public function __construct( - protected ?GetClientsParameters $parameters = null + protected ?GetClientsParams $parameters = null ) {} protected function defaultQuery(): array diff --git a/src/Requests/GetProjects.php b/src/Requests/GetProjects.php index 51caf97..cfc4119 100644 --- a/src/Requests/GetProjects.php +++ b/src/Requests/GetProjects.php @@ -5,7 +5,7 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetProjectsParameters; +use Spatie\FloatSdk\QueryParameters\GetProjectsParams; use Spatie\FloatSdk\Resources\ProjectResource; class GetProjects extends Request @@ -13,7 +13,7 @@ class GetProjects extends Request protected Method $method = Method::GET; public function __construct( - protected ?GetProjectsParameters $parameters = null + protected ?GetProjectsParams $parameters = null ) {} protected function defaultQuery(): array diff --git a/src/Requests/GetTasks.php b/src/Requests/GetTasks.php index 3ffd905..0d77821 100644 --- a/src/Requests/GetTasks.php +++ b/src/Requests/GetTasks.php @@ -5,7 +5,7 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetTasksParameters; +use Spatie\FloatSdk\QueryParameters\GetTasksParams; use Spatie\FloatSdk\Resources\TaskResource; class GetTasks extends Request @@ -13,7 +13,7 @@ class GetTasks extends Request protected Method $method = Method::GET; public function __construct( - protected ?GetTasksParameters $parameters = null + protected ?GetTasksParams $parameters = null ) {} protected function defaultQuery(): array diff --git a/src/Requests/GetUsers.php b/src/Requests/GetUsers.php index ba32682..7a60724 100644 --- a/src/Requests/GetUsers.php +++ b/src/Requests/GetUsers.php @@ -5,7 +5,7 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Spatie\FloatSdk\QueryParameters\GetUsersParameters; +use Spatie\FloatSdk\QueryParameters\GetUsersParams; use Spatie\FloatSdk\Resources\UserResource; class GetUsers extends Request @@ -13,7 +13,7 @@ class GetUsers extends Request protected Method $method = Method::GET; public function __construct( - protected ?GetUsersParameters $parameters = null + protected ?GetUsersParams $parameters = null ) {} public function resolveEndpoint(): string