-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunify_api.py
More file actions
64 lines (49 loc) · 1.94 KB
/
Copy pathunify_api.py
File metadata and controls
64 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from datetime import datetime, timedelta, timezone
from bundleup import BundleUp
api_key = os.getenv("BUNDLEUP_API_KEY")
connection_id = os.getenv("BUNDLEUP_CONNECTION_ID")
if not api_key:
raise SystemExit("BUNDLEUP_API_KEY is required")
if not connection_id:
raise SystemExit("BUNDLEUP_CONNECTION_ID is required for unify example")
client = BundleUp(api_key)
unify = client.unify(connection_id)
print("Unify API example")
try:
users = unify.chat.users({"limit": 10})
print(f"Chat users: {len(users.get('data', []))}")
except Exception as error:
print(f"Failed to fetch chat users: {error}")
try:
channels = unify.chat.channels({"limit": 10})
print(f"Chat channels: {len(channels.get('data', []))}")
channel = next(iter(channels.get("data", [])), None)
if channel:
messages = unify.chat.messages(channel["id"], {"limit": 10})
print(f"Messages in {channel['name']}: {len(messages.get('data', []))}")
except Exception as error:
print(f"Failed to fetch chat channels: {error}")
try:
repos = unify.git.repos({"limit": 10})
print(f"Git repos: {len(repos.get('data', []))}")
except Exception as error:
print(f"Failed to fetch git repos: {error}")
try:
tickets = unify.ticketing.tickets({"limit": 10})
print(f"Ticketing tickets: {len(tickets.get('data', []))}")
first = next(iter(tickets.get("data", [])), None)
if first:
ticket = unify.ticketing.ticket(first["id"])
print(f"Ticket {ticket['data']['id']}: {ticket['data']['title']}")
except Exception as error:
print(f"Failed to fetch tickets: {error}")
try:
events = unify.calendar.events({
"starts_after": datetime.now(timezone.utc).isoformat(),
"starts_before": (datetime.now(timezone.utc) + timedelta(days=7)).isoformat(),
"limit": 10,
})
print(f"Calendar events: {len(events.get('data', []))}")
except Exception as error:
print(f"Failed to fetch calendar events: {error}")