Skip to content

Commit 6d07b21

Browse files
authored
Merge pull request #9 from frain-dev/deprecate-apps
Deprecate apps.
2 parents b2d2734 + f5ccc45 commit 6d07b21

File tree

13 files changed

+39
-136
lines changed

13 files changed

+39
-136
lines changed

README.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ Next, import the `convoy` module and setup with your auth credentials.
1616

1717
```python
1818
from convoy import Convoy
19-
convoy = Convoy({"api_key":"your_api_key"})
19+
convoy = Convoy({"api_key":"your_api_key", "project_id": "your_project_id"})
2020
```
2121
The SDK also supports authenticating via Basic Auth by defining your username and password.
2222

23-
```python
24-
convoy = Convoy({"username":"default", "password":"default"})
25-
```
26-
27-
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.
23+
In the event you're using a self-hosted convoy instance, you can define the `uri` as part of what is passed into the convoy's constructor.
2824

2925
```python
30-
convoy = Convoy({ "api_key": 'your_api_key', "uri": 'self-hosted-instance' })
26+
convoy = Convoy({ "api_key": 'your_api_key', "uri": 'self-hosted-instance', "project_id": "your_project_id"})
3127
```
3228

3329
## Usage
@@ -38,20 +34,9 @@ convoy = Convoy({ "api_key": 'your_api_key', "uri": 'self-hosted-instance' })
3834
(response, status) = convoy.group.all({ "perPage": 10, "page": 1 })
3935
```
4036

41-
### Creating an Application
42-
43-
An application represents a user's application trying to receive webhooks. Once you create an application, you'll receive a `uid` that you should save and supply in subsequent API calls to perform other requests such as creating an event.
44-
45-
```python
46-
appData = { "name": "my_app", "support_email": "[email protected]" }
47-
(response, status) = convoy.application.create({}, appData)
48-
app_id = response["data"]["uid"]
49-
50-
```
51-
52-
### Add Application Endpoint
37+
### Create an Endpoint
5338

54-
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.
39+
An endpoint represents a target URL to receive events.
5540

5641
```python
5742
endpointData = {
@@ -61,7 +46,8 @@ endpointData = {
6146
"events": ["*"],
6247
}
6348

64-
(response, status) = convoy.endpoint.create(app_id, {}, endpointData)
49+
(response, status) = convoy.endpoint.create({}, endpointData)
50+
endpoint_id = response["data"]["uid"]
6551
```
6652

6753
### Sending an Event
@@ -70,7 +56,7 @@ To send an event, you'll need the `uid` we created in the earlier section.
7056

7157
```python
7258
eventData = {
73-
"app_id": app_id,
59+
"endpoint_id": endpoint_id,
7460
"event_type": "payment.success",
7561
"data": {
7662
"event": "payment.success",

convoy/api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from convoy.api.application import Application
21
from convoy.api.delivery_attempts import DeliveryAttempt
32
from convoy.api.endpoint import Endpoint
43
from convoy.api.event import Event

convoy/api/application.py

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

convoy/api/endpoint.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class Endpoint():
1010
def __init__(self, config):
1111
self.client = Client(config)
1212

13-
def all(self, app_id, query):
13+
def all(self, query):
1414
"""
15-
Get all endpoints for an application.
15+
Get all endpoints for a project.
1616
"""
17-
response = self.client.http_get("/applications/%s/endpoints" % app_id, query)
17+
response = self.client.http_get("/endpoints", query)
1818
return response
1919

20-
def create(self, app_id, query, data):
20+
def create(self, query, data):
2121
"""
2222
Create a new endpoint.
2323
Parameters
@@ -29,19 +29,19 @@ def create(self, app_id, query, data):
2929
"events": [],
3030
}
3131
"""
32-
response = self.client.http_post("/applications/%s/endpoints" % app_id, query, data)
32+
response = self.client.http_post("/endpoints", query, data)
3333
return response
3434

35-
def find(self, app_id, endpoint_id, query):
35+
def find(self, endpoint_id, query):
3636
"""
37-
Find a particular application.
37+
Find a particular endpoint.
3838
"""
39-
response = self.client.http_get("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query)
39+
response = self.client.http_get("endpoints/%s" % endpoint_id, query)
4040
return response
4141

42-
def update(self, app_id, endpoint_id, query, data):
42+
def update(self, endpoint_id, query, data):
4343
"""
44-
Update an application.
44+
Update an endpoint.
4545
Parameters
4646
----------
4747
data = {
@@ -51,13 +51,13 @@ def update(self, app_id, endpoint_id, query, data):
5151
"events": [],
5252
}
5353
"""
54-
response = self.client.http_put("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query, data)
54+
response = self.client.http_put("/endpoints/%s" % endpoint_id, query, data)
5555
return response
5656

57-
def delete(self, app_id, endpoint_id, query, data):
57+
def delete(self, endpoint_id, query, data):
5858
"""
59-
Delete an application.
59+
Delete an endpoint.
6060
"""
61-
response = self.client.http_delete("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query, data)
61+
response = self.client.http_delete("/endpoints/%s" % endpoint_id, query, data)
6262
return response
6363

convoy/api/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create(self, query, data):
2020
Parameters
2121
----------
2222
data = {
23-
app_id: "",
23+
endpoint_id: "",
2424
event_type: "",
2525
data: {
2626
"event": "",

convoy/api/source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, config):
1313

1414
def all(self, query):
1515
"""
16-
Get all sources for an application.
16+
Get all sources for a project.
1717
"""
1818

1919
response = self.client.http_get("/sources", query)

convoy/api/subscription.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def create(self, query, data):
3131
"count": 0,
3232
"threshold": ""
3333
},
34-
"app_id": "",
3534
"endpoint_id": "",
3635
"filter_config": {
3736
"event_types": []
@@ -68,7 +67,6 @@ def update(self, subscription_id, query, data):
6867
"count": 0,
6968
"threshold": ""
7069
},
71-
"app_id": "",
7270
"endpoint_id": "",
7371
"filter_config": {
7472
"event_types": []

convoy/client/client.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
@dataclass
1010
class Config:
1111
api_key: Optional[str] = ""
12-
username: Optional[str] = ""
13-
password: Optional[str] = ""
1412
uri: Optional[str] = ""
13+
project_id: Optional[str] = ""
1514

1615
class Client():
1716
"""
@@ -21,13 +20,9 @@ def __init__(self, config: dict):
2120
config = Config(**config)
2221
if config.api_key:
2322
self.api_key = config.api_key
24-
if config.username:
25-
self.username = config.usernamme
26-
if config.password:
27-
self.password = config.password
2823

2924
if config.uri == "":
30-
self.base_uri = "https://dashboard.getconvoy.io/api/v1"
25+
self.base_uri = f"https://dashboard.getconvoy.io/api/v1/projects/{config.project_id}"
3126
else:
3227
self.base_uri = config.uri
3328

@@ -65,10 +60,12 @@ def get_base_url(self):
6560
return self.base_uri
6661

6762
def get_authorization(self):
68-
if self.api_key != "":
69-
return "Bearer %s" % self.api_key
70-
71-
return "Basic %s" % b64encode(("%s:%s" % (self.username, self.password)).encode("utf-8")).decode("utf-8")
63+
try:
64+
if self.api_key != "":
65+
return "Bearer %s" % self.api_key
66+
raise ValueError("Invalid API Key")
67+
except ValueError as e:
68+
return e
7269

7370
def build_path(self, path):
7471
return "%s%s" % (self.base_uri, path)

convoy/convoy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from re import sub
2-
from convoy.api import application, delivery_attempts, endpoint, event, event_delivery, group, source, subscription
2+
from convoy.api import delivery_attempts, endpoint, event, event_delivery, group, source, subscription
3+
from convoy.utils import webhook
34

45
class Convoy():
56
"""Initializes the main Convoy Object.
@@ -20,11 +21,11 @@ class Convoy():
2021
}
2122
"""
2223
def __init__(self, config):
23-
self.application = application.Application(config)
2424
self.delivery_attempt = delivery_attempts.DeliveryAttempt(config)
2525
self.endpoint = endpoint.Endpoint(config)
2626
self.event_delivery = event_delivery.EventDelivery(config)
2727
self.event = event.Event(config)
2828
self.group = group.Group(config)
2929
self.source = source.Source(config)
30-
self.subscription = subscription.Subscription(config)
30+
self.subscription = subscription.Subscription(config)
31+
self.webhook = webhook.Webhook()

convoy/data.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@
1313
"uri": ""
1414
}
1515

16-
NewApplication = {
17-
"name": "",
18-
"support_email": "",
19-
"secret": ""
20-
}
21-
22-
2316
NewEvent = {
24-
"app_id": "",
17+
"endpoint_id": "",
2518
"event_type": "",
2619
"data": {
2720
"event": "",

0 commit comments

Comments
 (0)