Skip to content
Merged
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
97 changes: 77 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
```

Expand 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.

Expand All @@ -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,
)
Expand All @@ -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'],
Expand All @@ -131,27 +132,77 @@ $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'],
)
);
```

### 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.
Expand All @@ -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'
Expand All @@ -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']
);
```
Expand All @@ -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']
);

Expand Down
6 changes: 6 additions & 0 deletions src/FloatClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,4 +55,9 @@ public function clients(): ClientsGroup
{
return new ClientsGroup($this);
}

public function allocations(): AllocationsGroup
{
return new AllocationsGroup($this);
}
}
22 changes: 22 additions & 0 deletions src/Groups/AllocationsGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Spatie\FloatSdk\Groups;

use Saloon\Http\BaseResource;
use Saloon\Http\Response;
use Spatie\FloatSdk\QueryParameters\GetAllocationsParams;
use Spatie\FloatSdk\Requests\GetAllocation;
use Spatie\FloatSdk\Requests\GetAllocations;

class AllocationsGroup extends BaseResource
{
public function get(int $allocationId): Response
{
return $this->connector->send(new GetAllocation($allocationId));
}

public function all(?GetAllocationsParams $parameters = null): Response
{
return $this->connector->send(new GetAllocations($parameters));
}
}
4 changes: 2 additions & 2 deletions src/Groups/ClientsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Groups/ProjectsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Groups/TasksGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Groups/UsersGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Spatie\FloatSdk\Concerns\HasPaginationAndSort;

class GetAllocationsParameters
class GetAllocationsParams
{
use HasPaginationAndSort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Spatie\FloatSdk\Concerns\HasPaginationAndSort;

class GetClientsParameters
class GetClientsParams
{
use HasPaginationAndSort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Spatie\FloatSdk\Concerns\HasPaginationAndSort;

class GetProjectsParameters
class GetProjectsParams
{
use HasPaginationAndSort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Spatie\FloatSdk\Concerns\HasPaginationAndSort;

class GetTasksParameters
class GetTasksParams
{
use HasPaginationAndSort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Spatie\FloatSdk\Concerns\HasPaginationAndSort;

class GetUsersParameters
class GetUsersParams
{
use HasPaginationAndSort;

Expand Down
4 changes: 2 additions & 2 deletions src/Requests/GetAllocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
{
protected Method $method = Method::GET;

public function __construct(
protected ?GetAllocationsParameters $parameters = null
protected ?GetAllocationsParams $parameters = null
) {}

protected function defaultQuery(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Requests/GetClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
{
protected Method $method = Method::GET;

public function __construct(
protected ?GetClientsParameters $parameters = null
protected ?GetClientsParams $parameters = null
) {}

protected function defaultQuery(): array
Expand Down
Loading