Skip to content

Commit 03ee30b

Browse files
authored
deprecate apps (#6)
* add support for deprecating applications * update project resource
1 parent 53951be commit 03ee30b

6 files changed

Lines changed: 46 additions & 107 deletions

File tree

README.md

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,29 @@ use Convoy\Convoy;
2727
$convoy = new Convoy(["api_key" => "your_api_key"]);
2828
```
2929

30-
The SDK also supports authenticating via Basic Auth by defining your username and password.
30+
### Create an Endpoint
3131

32-
```php
33-
$convoy = new Convoy(["username" => "default", "password" => "default"]);
34-
```
35-
36-
In the event you're using a self hosted convoy instance, you can define the url as part of what is passed into convoy's constructor.
37-
38-
```php
39-
$convoy = new Convoy([
40-
"api_key" => "your_api_key",
41-
"uri" => "self-hosted-instance"
42-
]);
43-
```
44-
45-
### Creating an Application
46-
47-
An application represents a user's application trying to receive webhooks. Once you create an application, you'll receive a `uid` as part of the response that you should save and supply in subsequent API calls to perform other requests such as creating an event.
48-
49-
```php
50-
$appData = ["name" => "my_app", "support_email" => "support@myapp.com"];
51-
52-
$response = $convoy->applications()->create($appData);
53-
54-
$appId = $response['data']['uid'];
55-
```
56-
57-
### Add Application Endpoint
58-
59-
After creating an application, you'll need to add an endpoint to the application you just created. An endpoint represents a target URL to receive events.
32+
An endpoint represents a target URL to receive events.
6033

6134
```php
6235
$endpointData = [
36+
"name" => "Default Endpoint",
6337
"url" => "https://0d87-102-89-2-172.ngrok.io",
6438
"description" => "Default Endpoint",
6539
"secret" => "endpoint-secret",
6640
"events" => ["*"]
6741
]
6842

69-
$response = $convoy->endpoints()->create($appId, $endpointData);
43+
$response = $convoy->endpoints()->create($endpointData);
7044
```
7145

7246
### Sending an Event
7347

74-
To send an event, you'll need the `uid` from the application we created earlier.
48+
To send an event, you'll need the `uid` from the endpoint we created earlier.
7549

7650
```php
7751
$eventData = [
78-
"app_id" => $appId,
52+
"endpoint_id" => $endpointId,
7953
"event_type" => "payment.success",
8054
"data" => [
8155
"event" => "payment.success",

src/Api/Endpoint.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55
class Endpoint extends AbstractApi
66
{
7-
public function all(string $appId, array $parameters = []): array
7+
public function all(array $parameters = []): array
88
{
9-
return $this->httpGet(sprintf('/applications/%s/endpoints', $appId), $parameters);
9+
return $this->httpGet('/endpoints', $parameters);
1010
}
1111

12-
public function create(string $appId, array $data, array $parameters): array
12+
public function create(array $data, array $parameters): array
1313
{
14-
return $this->httpPost(sprintf('/applications/%s/endpoints', $appId), $data, $parameters);
14+
return $this->httpPost('/endpoints', $data, $parameters);
1515
}
1616

17-
public function find(string $appId, string $endpointId, array $parameters = []): array
17+
public function find(string $endpointId, array $parameters = []): array
1818
{
19-
return $this->httpGet(sprintf('/applications/%s/endpoints/%s', $appId, $endpointId), $parameters);
19+
return $this->httpGet(sprintf('/endpoints/%s', $endpointId), $parameters);
2020
}
2121

22-
public function update(string $appId, string $endpointId, array $data, array $parameters = []): array
22+
public function update(string $endpointId, array $data, array $parameters = []): array
2323
{
24-
return $this->httpPut(sprintf('/applications/%s/endpoints/%s', $appId, $endpointId), $data, $parameters);
24+
return $this->httpPut(sprintf('/endpoints/%s', $endpointId), $data, $parameters);
2525
}
2626

27-
public function delete(string $appId, string $endpointId, array $data = [], array $parameters = []): array
27+
public function delete(string $endpointId, array $data = [], array $parameters = []): array
2828
{
29-
return $this->httpDelete(sprintf('/applications/%s/endpoints/%s', $appId, $endpointId), $data, $parameters);
29+
return $this->httpDelete(sprintf('/endpoints/%s', $endpointId), $data, $parameters);
3030
}
3131
}

src/Api/Group.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Api/Project.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Convoy\Api;
4+
5+
class Project extends AbstractApi
6+
{
7+
public function find(array $parameters = []): array
8+
{
9+
return $this->httpGet("/", $parameters);
10+
}
11+
12+
public function update(array $data, array $parameters = []): array
13+
{
14+
return $this->httpPut("/", $data, $parameters);
15+
}
16+
17+
public function delete(array $data = [], array $parameters = []): array
18+
{
19+
return $this->httpDelete("/", $data, $parameters);
20+
}
21+
}

src/Convoy.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Convoy;
44

5-
use Convoy\Api\Application;
65
use Convoy\Api\DeliveryAttempt;
76
use Convoy\Api\Endpoint;
87
use Convoy\Api\Event;
98
use Convoy\Api\EventDelivery;
10-
use Convoy\Api\Group;
9+
use Convoy\Api\Project;
1110
use Convoy\Api\Source;
1211
use Convoy\Api\Subscription;
1312
use Convoy\HttpClient\ClientBuilder;
@@ -47,14 +46,9 @@ public function getHttpClient(): HttpMethodsClientInterface
4746
return $this->clientBuilder->getHttpClient();
4847
}
4948

50-
public function groups(): Group
49+
public function projects(): Project
5150
{
52-
return new Group($this->getHttpClient());
53-
}
54-
55-
public function applications(): Application
56-
{
57-
return new Application($this->getHttpClient());
51+
return new Project($this->getHttpClient());
5852
}
5953

6054
public function events(): Event

src/HttpClient/Config.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ private function configureDefaultOptions(OptionsResolver $resolver): void
3131
'client_builder' => new ClientBuilder(),
3232
'uri_factory' => Psr17FactoryDiscovery::findUriFactory(),
3333
'uri' => self::URI,
34+
'project_id' => '',
3435
'api_key' => '',
35-
'username' => '',
36-
'password' => '',
3736
]);
3837

3938

@@ -44,8 +43,7 @@ private function setAllowedTypes(OptionsResolver $resolver): void
4443
{
4544
$resolver->setAllowedTypes('uri', 'string');
4645
$resolver->setAllowedTypes('api_key', 'string');
47-
$resolver->setAllowedTypes('username', 'string');
48-
$resolver->setAllowedTypes('password', 'string');
46+
$resolver->setAllowedTypes('project_id', 'string');
4947
$resolver->setAllowedTypes('client_builder', ClientBuilder::class);
5048
$resolver->setAllowedTypes('uri_factory', UriFactoryInterface::class);
5149
}
@@ -62,35 +60,18 @@ public function getUriFactory(): UriFactoryInterface
6260

6361
public function getUri(): UriInterface
6462
{
65-
return $this->getUriFactory()->createUri($this->config['uri']);
63+
$uri = sprintf('%s/projects/%s', $this->config['uri'], $this->config['project_id']);
64+
65+
return $this->getUriFactory()->createUri($uri);
6666
}
6767

6868
public function getApiKey(): string
6969
{
7070
return $this->config['api_key'];
7171
}
7272

73-
public function getUsername(): string
74-
{
75-
return $this->config['username'];
76-
}
77-
78-
public function getPassword(): string
79-
{
80-
return $this->config['password'];
81-
}
82-
83-
public function isBearerTokenAuthentication(): bool
84-
{
85-
return array_key_exists('api_key', $this->config) && ! empty($this->config['api_key']);
86-
}
87-
8873
public function getAuthenticationPlugin(): Authentication
8974
{
90-
if ($this->isBearerTokenAuthentication()) {
91-
return new Bearer($this->getApiKey());
92-
}
93-
94-
return new BasicAuth($this->getUsername(), $this->getPassword());
75+
return new Bearer($this->getApiKey());
9576
}
9677
}

0 commit comments

Comments
 (0)