Skip to content
Open
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ calendly = CalendlyAPI(api_key)
- `get_event_details` - Get information about the event
- `list_event_invitees` - Get all invitees for a event

### Oauth2
Getting started with [Calendly Oauth2 API](https://developer.calendly.com/api-docs/YXBpOjU5MTQwNw-o-auth-2-0) .
```
from calendly import CalendlyOauth2

client_id = "<client_id>"
client_secret = "<client_secret>"
redirect_uri = "<redirect_uri>"

oauth2 = CalendlyOauth2(
client_id,
client_secret,
redirect_uri
)
```

### Methods
- `authorization_url` - Returns the formatted authorization URL
- `get_access_token` - Send a request to obtain the given access token
- `revoke_access_token` - Send a request to revoke the given access token
- `refresh_access_token` - Send a request to refresh the given access token
- `introspect_access_token` - Send a request to bring details about the given access token

## Issues
Feel free to submit issues and enhancement requests.
Expand Down
4 changes: 3 additions & 1 deletion calendly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .utils.oauth2 import CalendlyOauth2
from .calendly import CalendlyAPI
from .exceptions import CalendlyException, CalendlyOauth2Exception

__all__ = [CalendlyAPI]
__all__ = [CalendlyAPI, CalendlyOauth2, CalendlyException, CalendlyOauth2Exception]
43 changes: 23 additions & 20 deletions calendly/calendly.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from calendly.utils.constants import WEBHOOK, EVENTS, ME, EVENT_TYPE
from calendly.utils.requests import CalendlyReq, CalendlyException
import json
from typing import List, MutableMapping
import json

from calendly.utils.api import CalendlyReq
from calendly.utils.constants import WEBHOOK, EVENTS, ME, EVENT_TYPE
from calendly.exceptions import CalendlyException


class CalendlyAPI(object):

Expand All @@ -21,14 +24,15 @@ def __init__(self, token: str):
"""
self.request = CalendlyReq(token)

def create_webhook(self, url: str, scope: str, organization: str, signing_key: str=None, user: str=None, event_types: List[str]=["canceled", "created"]) -> MutableMapping:
def create_webhook(self, url: str, scope: str, organization: str, signing_key: str=None, user: str=None, event_types: List[str]=("canceled", "created")) -> MutableMapping:
"""
Create a Webhook Subscription

Args:
url (str): Webhook URL
scope (str): Either "organization" or "user"
organization (str): Unique reference to the organization that the webhook will be tied to
signing_key (str): A signing key
user (str, optional): If scope is set to "user", then user reference is required.
event_types (list, optional): List of user events to subscribe to. Defaults to ["canceled", "created"].

Expand All @@ -44,8 +48,8 @@ def create_webhook(self, url: str, scope: str, organization: str, signing_key: s
'scope': scope,
'signing_key': signing_key}

if (scope == 'user'):
if (user == None):
if scope == 'user':
if user is None:
raise CalendlyException
data['user'] = user

Expand Down Expand Up @@ -131,7 +135,7 @@ def about(self) -> MutableMapping:
response = self.request.get(ME)
return response.json()

def list_event_types(self, count: int=20, organization: str=None, page_token: str=None, sort: str=None, user_uri: str=None) -> List[MutableMapping]:
def list_event_types(self, count: int=20, organization: str=None, page_token: str=None, sort: str=None, user_uri: str=None) -> MutableMapping:
"""
Returns all Event Types associated with a specified user.

Expand All @@ -146,13 +150,13 @@ def list_event_types(self, count: int=20, organization: str=None, page_token: st
dict: json decoded response with list of event types
"""
data = {"count": count}
if (organization):
if organization:
data['organization'] = organization
if (page_token):
if page_token:
data['page_token'] = page_token
if (sort):
if sort:
data['sort'] = sort
if (user_uri):
if user_uri:
data['user'] = user_uri
response = self.request.get(EVENT_TYPE, data)
return response.json()
Expand All @@ -170,7 +174,7 @@ def get_event_type(self, uuid: str) -> MutableMapping:
response = self.request.get(f'{EVENT_TYPE}/' + uuid, data)
return response.json()

def list_events(self, count: int=20, organization: str=None, sort: str=None, user_uri: str=None, status: str=None) -> List[MutableMapping]:
def list_events(self, count: int=20, organization: str=None, sort: str=None, user_uri: str=None, status: str=None) -> MutableMapping:
"""
Returns a List of Events

Expand All @@ -185,13 +189,13 @@ def list_events(self, count: int=20, organization: str=None, sort: str=None, use
dict: json decoded response of list of events.
"""
data = {'count': count}
if (organization):
if organization:
data['organization'] = organization
if (sort):
if sort:
data['sort'] = sort
if (user_uri):
if user_uri:
data['user'] = user_uri
if (status):
if status:
data['status'] = status
response = self.request.get(EVENTS, data)
return response.json()
Expand Down Expand Up @@ -239,7 +243,7 @@ def list_event_invitees(self, uuid: str) -> List[MutableMapping]:
response = self.request.get(url)
return response.json()

def get_all_event_types(self, user_uri: str) -> List[str]:
def get_all_event_types(self, user_uri: str) -> List[MutableMapping]:
"""
Get all event types by recursively crawling on all result pages.

Expand All @@ -254,14 +258,14 @@ def get_all_event_types(self, user_uri: str) -> List[str]:

data = first['collection']

while (next_page):
while next_page:
page = self.request.get(next_page).json()
data += page['collection']
next_page = page['pagination']['next_page']

return data

def get_all_scheduled_events(self, user_uri: str) -> List[str]:
def get_all_scheduled_events(self, user_uri: str) -> List[MutableMapping]:
"""
Get all scheduled events by recursively crawling on all result pages.

Expand Down Expand Up @@ -306,5 +310,4 @@ def convert_event_to_original_url(self, event_uri: str, user_uri: str) -> str:
if not next_page:
break
page = self.request.get(next_page).json()
return

10 changes: 10 additions & 0 deletions calendly/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CalendlyException(Exception):
"""Errors corresponding to a misuse of Calendly API"""

def __init__(self, message=None, details=None):
self.message = message or ""
self.details = details or []
super(CalendlyException, self).__init__(f"{self.message} - {self.details}")

class CalendlyOauth2Exception(CalendlyException):
"""Errors corresponding to a misuse of CalendlyOauth2 API"""
Loading