-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.py
More file actions
66 lines (50 loc) · 1.98 KB
/
example1.py
File metadata and controls
66 lines (50 loc) · 1.98 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
65
66
import os
import urlr
from urlr.rest import ApiException
username = os.getenv("URLR_API_USERNAME") # to define on your end
password = os.getenv("URLR_API_PASSWORD") # to define on your end
# Access Tokens
configuration = urlr.Configuration()
with urlr.ApiClient(configuration) as api_client:
access_token_api = urlr.AccessTokensApi(api_client)
create_access_token_request = urlr.CreateAccessTokenRequest(
username=username,
password=password,
)
try:
api_response = access_token_api.create_access_token(
create_access_token_request=create_access_token_request)
except ApiException as e:
print("Exception when calling AccessTokensApi->create_access_token: %s\n" % e)
quit()
configuration.access_token = api_response.token
# Workspaces - get workspace id
with urlr.ApiClient(configuration) as api_client:
workspaces_api = urlr.WorkspacesApi(api_client)
try:
workspaces = workspaces_api.get_teams()
workspace_id = workspaces.teams[0].id
except Exception as e:
print("Exception when calling WorkspacesApi->get_teams: %s\n" % e)
# Create a link
with urlr.ApiClient(configuration) as api_client:
links_api = urlr.LinksApi(api_client)
create_link_request = urlr.CreateLinkRequest(
url="https://github.com/URLR",
team_id=workspace_id
)
try:
link = links_api.create_link(
create_link_request=create_link_request)
except Exception as e:
print("Exception when calling LinksApi->create_link: %s\n" % e)
# Get statistics
with urlr.ApiClient(configuration) as api_client:
statistics_api = urlr.StatisticsApi(api_client)
get_statistics_request = urlr.GetStatisticsRequest(link_id=link.id)
try:
api_response = statistics_api.get_statistics(
get_statistics_request=get_statistics_request)
print(api_response)
except Exception as e:
print("Exception when calling StatisticsApi->get_statistics: %s\n" % e)