Skip to content

Commit

Permalink
Merge pull request #9 from frain-dev/deprecate-apps
Browse files Browse the repository at this point in the history
Deprecate apps.
  • Loading branch information
subomi committed May 16, 2023
2 parents b2d2734 + f5ccc45 commit 6d07b21
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 136 deletions.
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ Next, import the `convoy` module and setup with your auth credentials.

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

```python
convoy = Convoy({"username":"default", "password":"default"})
```

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

```python
convoy = Convoy({ "api_key": 'your_api_key', "uri": 'self-hosted-instance' })
convoy = Convoy({ "api_key": 'your_api_key', "uri": 'self-hosted-instance', "project_id": "your_project_id"})
```

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

### Creating an Application

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.

```python
appData = { "name": "my_app", "support_email": "support@myapp.com" }
(response, status) = convoy.application.create({}, appData)
app_id = response["data"]["uid"]

```

### Add Application Endpoint
### Create an Endpoint

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

```python
endpointData = {
Expand All @@ -61,7 +46,8 @@ endpointData = {
"events": ["*"],
}

(response, status) = convoy.endpoint.create(app_id, {}, endpointData)
(response, status) = convoy.endpoint.create({}, endpointData)
endpoint_id = response["data"]["uid"]
```

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

```python
eventData = {
"app_id": app_id,
"endpoint_id": endpoint_id,
"event_type": "payment.success",
"data": {
"event": "payment.success",
Expand Down
1 change: 0 additions & 1 deletion convoy/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from convoy.api.application import Application
from convoy.api.delivery_attempts import DeliveryAttempt
from convoy.api.endpoint import Endpoint
from convoy.api.event import Event
Expand Down
59 changes: 0 additions & 59 deletions convoy/api/application.py

This file was deleted.

28 changes: 14 additions & 14 deletions convoy/api/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class Endpoint():
def __init__(self, config):
self.client = Client(config)

def all(self, app_id, query):
def all(self, query):
"""
Get all endpoints for an application.
Get all endpoints for a project.
"""
response = self.client.http_get("/applications/%s/endpoints" % app_id, query)
response = self.client.http_get("/endpoints", query)
return response

def create(self, app_id, query, data):
def create(self, query, data):
"""
Create a new endpoint.
Parameters
Expand All @@ -29,19 +29,19 @@ def create(self, app_id, query, data):
"events": [],
}
"""
response = self.client.http_post("/applications/%s/endpoints" % app_id, query, data)
response = self.client.http_post("/endpoints", query, data)
return response

def find(self, app_id, endpoint_id, query):
def find(self, endpoint_id, query):
"""
Find a particular application.
Find a particular endpoint.
"""
response = self.client.http_get("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query)
response = self.client.http_get("endpoints/%s" % endpoint_id, query)
return response

def update(self, app_id, endpoint_id, query, data):
def update(self, endpoint_id, query, data):
"""
Update an application.
Update an endpoint.
Parameters
----------
data = {
Expand All @@ -51,13 +51,13 @@ def update(self, app_id, endpoint_id, query, data):
"events": [],
}
"""
response = self.client.http_put("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query, data)
response = self.client.http_put("/endpoints/%s" % endpoint_id, query, data)
return response

def delete(self, app_id, endpoint_id, query, data):
def delete(self, endpoint_id, query, data):
"""
Delete an application.
Delete an endpoint.
"""
response = self.client.http_delete("/applications/%s/endpoints/%s" % (app_id, endpoint_id), query, data)
response = self.client.http_delete("/endpoints/%s" % endpoint_id, query, data)
return response

2 changes: 1 addition & 1 deletion convoy/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create(self, query, data):
Parameters
----------
data = {
app_id: "",
endpoint_id: "",
event_type: "",
data: {
"event": "",
Expand Down
2 changes: 1 addition & 1 deletion convoy/api/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, config):

def all(self, query):
"""
Get all sources for an application.
Get all sources for a project.
"""

response = self.client.http_get("/sources", query)
Expand Down
2 changes: 0 additions & 2 deletions convoy/api/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def create(self, query, data):
"count": 0,
"threshold": ""
},
"app_id": "",
"endpoint_id": "",
"filter_config": {
"event_types": []
Expand Down Expand Up @@ -68,7 +67,6 @@ def update(self, subscription_id, query, data):
"count": 0,
"threshold": ""
},
"app_id": "",
"endpoint_id": "",
"filter_config": {
"event_types": []
Expand Down
19 changes: 8 additions & 11 deletions convoy/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
@dataclass
class Config:
api_key: Optional[str] = ""
username: Optional[str] = ""
password: Optional[str] = ""
uri: Optional[str] = ""
project_id: Optional[str] = ""

class Client():
"""
Expand All @@ -21,13 +20,9 @@ def __init__(self, config: dict):
config = Config(**config)
if config.api_key:
self.api_key = config.api_key
if config.username:
self.username = config.usernamme
if config.password:
self.password = config.password

if config.uri == "":
self.base_uri = "https://dashboard.getconvoy.io/api/v1"
self.base_uri = f"https://dashboard.getconvoy.io/api/v1/projects/{config.project_id}"
else:
self.base_uri = config.uri

Expand Down Expand Up @@ -65,10 +60,12 @@ def get_base_url(self):
return self.base_uri

def get_authorization(self):
if self.api_key != "":
return "Bearer %s" % self.api_key

return "Basic %s" % b64encode(("%s:%s" % (self.username, self.password)).encode("utf-8")).decode("utf-8")
try:
if self.api_key != "":
return "Bearer %s" % self.api_key
raise ValueError("Invalid API Key")
except ValueError as e:
return e

def build_path(self, path):
return "%s%s" % (self.base_uri, path)
7 changes: 4 additions & 3 deletions convoy/convoy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from re import sub
from convoy.api import application, delivery_attempts, endpoint, event, event_delivery, group, source, subscription
from convoy.api import delivery_attempts, endpoint, event, event_delivery, group, source, subscription
from convoy.utils import webhook

class Convoy():
"""Initializes the main Convoy Object.
Expand All @@ -20,11 +21,11 @@ class Convoy():
}
"""
def __init__(self, config):
self.application = application.Application(config)
self.delivery_attempt = delivery_attempts.DeliveryAttempt(config)
self.endpoint = endpoint.Endpoint(config)
self.event_delivery = event_delivery.EventDelivery(config)
self.event = event.Event(config)
self.group = group.Group(config)
self.source = source.Source(config)
self.subscription = subscription.Subscription(config)
self.subscription = subscription.Subscription(config)
self.webhook = webhook.Webhook()
9 changes: 1 addition & 8 deletions convoy/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@
"uri": ""
}

NewApplication = {
"name": "",
"support_email": "",
"secret": ""
}


NewEvent = {
"app_id": "",
"endpoint_id": "",
"event_type": "",
"data": {
"event": "",
Expand Down
2 changes: 1 addition & 1 deletion convoy/utils/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def response(self):


class Webhook:
def __init__(self, secret: str, encoding: str = "hex", tolerance: int = 300, hash: str = "sha256") -> None:
def __init__(self, secret: str = "", encoding: str = "hex", tolerance: int = 300, hash: str = "sha256") -> None:
self.secret = secret
self.encoding = encoding
self.tolerance = tolerance
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# This call to setup() does all the work
setup(
name="convoy-python",
version="0.1.0",
version="0.2.0",
description="Python SDK for Convoy",
url="https://github.com/frain-dev/convoy-python",
long_description=README,
Expand Down
12 changes: 0 additions & 12 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@

cnv = Convoy(Config)

#Application
def test_application():
NewApplication["name"] = "pythonsdktestapp"
NewApplication["support_email"] = "testsdk@frain.dev"
_, status = cnv.application.create({"groupID":"449f4d86-e70b-40eb-a733-dadd89d8d3b6"}, NewApplication)
assert(status == 201)
# response = cnv.applications.all("groupID=449f4d86-e70b-40eb-a733-dadd89d8d3b6")
# response = cnv.applications.find("fb05c3c7-2d9c-4e07-95b4-e859c1415385", "groupID=449f4d86-e70b-40eb-a733-dadd89d8d3b6")
# UpdateApplication = NewApplication
# UpdateApplication["name"] = "sdktest_app"
# response = cnv.applications.update("9a3cc2b9-ce09-4dbd-9ea9-594def3dd347", "groupID=449f4d86-e70b-40eb-a733-dadd89d8d3b6", UpdateApplication)

#Endpoint
def test_endpoint():
NewEndpoint["url"] = "http://ed0b-102-219-153-85.ngrok.io"
Expand Down

0 comments on commit 6d07b21

Please sign in to comment.