Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Add subscriptions to recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
yuters committed Mar 16, 2021
1 parent 2b0f47a commit 8e7a7e5
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ $projects = Basecamp::projects()->index($nextPage);
- [Recordings](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/recordings.md)
- [Schedule entries](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/schedule_entries.md)
- [Schedules](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/schedules.md)
- [Subscriptions](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/subscriptions.md)
- [Templates](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/templates.md)
- [To-do list groups](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/todolist_groups.md)
- [To-do lists](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/todolists.md)
Expand Down
33 changes: 33 additions & 0 deletions docs/subscriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Subscriptions

## Get the subscription info

Show the subscribers / subscription info for any "recordings" object: Messages, Comments, Documents,
Uploads, etc...

```php
$subscription = $recording->subscriptions()->show();
```

## Subscribe the current user

```php
$subscription = $recording->subscriptions()->subscribe();
```

## Unsubscribe the current user

```php
$response = $recording->subscriptions()->unsubscribe();
```

## Update the subscription info

Pass the array of people id to subscribe or unsubscribe.

```php
$subscription = $recording->subscriptions()->update([
"subscriptions": [4,5,6],
"unsubscriptions": [1,2,3],
]);
```
10 changes: 10 additions & 0 deletions src/Models/Recording.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public function events()
return Basecamp::events($this->bucket->id, $this->id);
}

/**
* Get the subscription info.
*
* @return \Belvedere\Basecamp\Models\Subscription
*/
public function subscriptions()
{
return Basecamp::subscriptions($this->bucket->id, $this->id);
}

/**
* Trash the recording.
*
Expand Down
39 changes: 39 additions & 0 deletions src/Models/Subscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Belvedere\Basecamp\Models;

use Basecamp;

class Subscription extends AbstractModel
{
/**
* Subscribe the current user.
*
* @return \Belvedere\Basecamp\Models\Subscription
*/
public function subscribe()
{
return Basecamp::subscriptions($this->url)->subscribe();
}

/**
* Unsubscribe the current user.
*
* @return string
*/
public function unsubscribe()
{
return Basecamp::subscriptions($this->url)->unsubscribe();
}

/**
* Update the subscription.
*
* @param array $data
* @return \Illuminate\Http\Collection
*/
public function update(array $data)
{
return Basecamp::subscriptions($this->url)->update($data);
}
}
86 changes: 86 additions & 0 deletions src/Sections/Subscriptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Belvedere\Basecamp\Sections;

use Belvedere\Basecamp\Models\Subscription;
use GuzzleHttp\Client;

class Subscriptions extends AbstractSection
{
/**
* Store the api url for this section.
*
* @var string
*/
protected $url;

/**
* Check for url in of bucket.
*
* @param \GuzzleHttp\Client $client
* @param array $parameters
* @return void
*/
public function __construct(Client $client, array $parameters = [])
{
parent::__construct($client, $parameters);

if (filter_var($this->bucket, FILTER_VALIDATE_URL)) {
$this->url = $this->bucket;
} else {
$this->url = sprintf('buckets/%d/recordings/%d/subscription.json', $this->bucket, $this->parent);
}
}

/**
* Show subscription info for a recording.
*
* @return \Belvedere\Basecamp\Models\Subscription
*/
public function show()
{
$subscription = $this->client->get($this->url);

return new Subscription($this->response($subscription));
}

/**
* Subscribe the current user.
*
* @return \Belvedere\Basecamp\Models\Subscription
*/
public function subscribe()
{
$subscription = $this->client->post($this->url);

return new Subscription($this->response($subscription));
}

/**
* Unsubscribe the current user.
*
* @return string
*/
public function unsubscribe()
{
return $this->client->delete($this->url);
}

/**
* Update the subscription.
*
* @param array $data
* @return \Belvedere\Basecamp\Models\Subscription
*/
public function update(array $data)
{
$subscription = $this->client->put(
$this->url,
[
'json' => $data,
]
);

return new Subscription($this->response($subscription));
}
}

0 comments on commit 8e7a7e5

Please sign in to comment.