forked from allisson/python-simple-rest-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_github.py
More file actions
37 lines (28 loc) · 1.56 KB
/
async_github.py
File metadata and controls
37 lines (28 loc) · 1.56 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
import asyncio
from simple_rest_client.api import API
from simple_rest_client.resource import AsyncResource
class EventResource(AsyncResource):
actions = {
'public_events': {'method': 'GET', 'url': 'events'},
'repository_events': {'method': 'GET', 'url': '/repos/{}/{}/events'},
'repository_issues_events': {'method': 'GET', 'url': '/repos/{}/{}/issues/events'},
'public_network_events': {'method': 'GET', 'url': '/networks/{}/{}/events'},
'public_organization_events': {'method': 'GET', 'url': '/orgs/{}/events'},
'user_received_events': {'method': 'GET', 'url': '/users/{}/received_events'},
'public_user_received_events': {'method': 'GET', 'url': '/users/{}/received_events/public'},
'user_events': {'method': 'GET', 'url': '/users/{}/events'},
'public_user_events': {'method': 'GET', 'url': '/users/{}/events/public'},
'organization_events': {'method': 'GET', 'url': '/users/{}/events/orgs/{}'},
}
# https://github.com/settings/tokens
default_params = {'access_token': 'valid-token'}
github_api = API(
api_root_url='https://api.github.com', params=default_params,
json_encode_body=True
)
github_api.add_resource(resource_name='events', resource_class=EventResource)
async def main():
print('github_api.events.public_events={!r}'.format(await github_api.events.public_events()))
print('github_api.events.repository_events={!r}'.format(await github_api.events.repository_events('allisson', 'python-simple-rest-client')))
loop = asyncio.get_event_loop()
loop.run_until_complete(main())