1+ import os
12import urlr
23from urlr .rest import ApiException
3- from pprint import pprint
4+
5+ username = os .getenv ("URLR_API_USERNAME" ) # to define on your end
6+ password = os .getenv ("URLR_API_PASSWORD" ) # to define on your end
7+
48
59# Access Tokens
610
7- with urlr .ApiClient () as api_client :
8- access_tokens_api = urlr .AccessTokensApi (api_client )
9-
10- access_tokens_request = urlr .AccessTokensRequest .from_json ('{"username": "","password": ""}' )
11+ configuration = urlr .Configuration ()
12+
13+ with urlr .ApiClient (configuration ) as api_client :
14+ access_token_api = urlr .AccessTokensApi (api_client )
15+
16+ create_access_token_request = urlr .CreateAccessTokenRequest (
17+ username = username ,
18+ password = password ,
19+ )
1120
1221 try :
13- api_response = access_tokens_api .create_access_token (access_tokens_request = access_tokens_request )
22+ api_response = access_token_api .create_access_token (
23+ create_access_token_request = create_access_token_request )
1424 except ApiException as e :
1525 print ("Exception when calling AccessTokensApi->create_access_token: %s\n " % e )
1626 quit ()
1727
18- # Link shortening
28+ configuration .access_token = api_response .token
29+
30+ # Workspaces - get workspace id
31+
32+ with urlr .ApiClient (configuration ) as api_client :
33+ workspaces_api = urlr .WorkspacesApi (api_client )
34+ try :
35+ workspaces = workspaces_api .get_teams ()
36+ workspace_id = workspaces .teams [0 ].id
37+ except Exception as e :
38+ print ("Exception when calling WorkspacesApi->get_teams: %s\n " % e )
1939
20- configuration = urlr .Configuration (
21- access_token = api_response .token
22- )
40+ # Create a link
2341
2442with urlr .ApiClient (configuration ) as api_client :
25- link_api = urlr .LinksApi (api_client )
26- create_link_request = urlr .CreateLinkRequest .from_json ('{"url": "","team_id": ""}' )
43+ links_api = urlr .LinksApi (api_client )
44+ create_link_request = urlr .CreateLinkRequest (
45+ url = "https://github.com/URLR" ,
46+ team_id = workspace_id
47+ )
2748
2849 try :
29- api_response = link_api .create_link (create_link_request = create_link_request )
30- pprint ( api_response )
50+ link = links_api .create_link (
51+ create_link_request = create_link_request )
3152 except Exception as e :
32- pprint ("Exception when calling LinksApi->create_link: %s\n " % e )
53+ print ("Exception when calling LinksApi->create_link: %s\n " % e )
3354
34- # Statistics
55+ # Get statistics
3556
3657with urlr .ApiClient (configuration ) as api_client :
3758 statistics_api = urlr .StatisticsApi (api_client )
38- statistics_request = urlr .StatisticsRequest . from_json ( '{" link_id": ""}' )
59+ get_statistics_request = urlr .GetStatisticsRequest ( link_id = link . id )
3960
4061 try :
41- api_response = statistics_api .get_statistics (statistics_request = statistics_request )
42- pprint (api_response )
62+ api_response = statistics_api .get_statistics (
63+ get_statistics_request = get_statistics_request )
64+ print (api_response )
4365 except Exception as e :
44- print ("Exception when calling StatisticsApi->get_statistics: %s\n " % e )
66+ print ("Exception when calling StatisticsApi->get_statistics: %s\n " % e )
0 commit comments