-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiron_example_multiple_callers.py
37 lines (27 loc) · 1.16 KB
/
apiron_example_multiple_callers.py
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 threading
from apiron import Service, JsonEndpoint
class GitHub(Service):
repos = JsonEndpoint(path='/repos/{org}')
issues = JsonEndpoint(path='/repos/{org}/{repo}/issues')
pulls = JsonEndpoint(path='/repos/{org}/{repo}/pulls')
class GitHubOrg:
def __init__(self, org, client, domain, auth):
self.org = org
self.client = client
self.domain = domain
self.auth = auth
def repos(self):
with threading.Lock:
self.client.domain = self.domain
return self.client.repos(org=self.org, auth=self.auth)
def issues(self, repo):
with threading.Lock:
self.client.domain = self.domain
return self.client.issues(org=self.org, repo=repo, auth=self.auth)
def pulls(self, repo):
with threading.Lock:
self.client.domain = self.domain
return self.client.pulls(org=self.org, repo=repo, auth=self.auth)
foo_repo = GitHubOrg('foo', GitHub, 'https://foo.com/api/v3', 'foo_auth_key')
bar_repo = GitHubOrg('bar', GitHub, 'https://bar.com/api/v3', 'bar_auth_key')
print("Example does nothing because these are fake accounts and domains.")