diff --git a/api/interactions/interactions.py b/api/interactions/interactions.py new file mode 100644 index 0000000..e70474c --- /dev/null +++ b/api/interactions/interactions.py @@ -0,0 +1,14 @@ +from core.rest_client import RestClient +from api.interactions.orgs import Orgs +from api.interactions.repos import Repos + + +class Interactions(RestClient): + """ + https://developer.github.com/v3/interactions/#interactions + """ + + def __init__(self, api_root_url, **kwargs): + super(Interactions, self).__init__(api_root_url, **kwargs) + self.orgs = Orgs(self.api_root_url, **kwargs) + self.repos = Repos(self.api_root_url, **kwargs) diff --git a/api/interactions/orgs.py b/api/interactions/orgs.py new file mode 100644 index 0000000..912f709 --- /dev/null +++ b/api/interactions/orgs.py @@ -0,0 +1,27 @@ +from core.rest_client import RestClient + + +class Orgs(RestClient): + def __init__(self): + self.headers = {'Accept': 'application/vnd.github.sombra-preview'} + + def get_interactions_limits_for_org(self, org, **kwargs): + """ + https://developer.github.com/v3/interactions/orgs/#get-interaction-restrictions-for-an-organization + :param org: organization name + """ + return self.get('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs) + + def update_interactions_limits_for_org(self, org, **kwargs): + """ + https://developer.github.com/v3/interactions/orgs#add-or-update-interaction-restrictions-for-an-organization + :param org: organization name + """ + return self.put('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs) + + def remove_interaction_restrictions_for_org(self, org, **kwargs): + """ + https://developer.github.com/v3/interactions/orgs#remove-interaction-restrictions-for-an-organization + :param org: organization name + """ + return self.delete('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs) diff --git a/api/interactions/repos.py b/api/interactions/repos.py new file mode 100644 index 0000000..c4fc7c0 --- /dev/null +++ b/api/interactions/repos.py @@ -0,0 +1,29 @@ +from core.rest_client import RestClient + + +class Repos(RestClient): + def __init__(self): + self.headers = {'Accept': 'application/vnd.github.sombra-preview'} + + def get_interaction_restrictions_for_repo(self, owner, **kwargs): + """ + https://developer.github.com/v3/interactions/repos#get-interaction-restrictions-for-a-repository + :param owner: organization owner + """ + return self.get('/repos/{}/:repo/interaction-limits'.format(owner), headers=self.headers, **kwargs) + + def update_interaction_restrictions_for_repo(self, owner, repo, **kwargs): + """ + https://developer.github.com/v3/interactions/repos/#add-or-update-interaction-restrictions-for-a-repository + :param owner: organization owner + :param repo: repository + """ + return self.put('/repos/{}/{}/interaction-limits'.format(owner, repo), headers=self.headers, **kwargs) + + def remove_interaction_restrictions_for_repo(self, owner, repo, **kwargs): + """ + https://developer.github.com/v3/interactions/repos/#remove-interaction-restrictions-for-a-repository + :param owner: organization owner + :param repo: repository + """ + return self.delete('/repos/{}/{}/interaction-limits'.format(owner, repo), header=self.headers, **kwargs) diff --git a/github.py b/github.py index b5dc7a8..edb7c1c 100644 --- a/github.py +++ b/github.py @@ -1,6 +1,8 @@ from api.repositories.repos import Repos from api.issues.issues import Issues from api.checks.checks import Checks +from api.interactions.interactions import Interactions + class Github(): def __init__(self, **kwargs): @@ -8,3 +10,4 @@ def __init__(self, **kwargs): self.repos = Repos(self.api_root_url, **kwargs) self.issues = Issues(self.api_root_url, **kwargs) self.checks = Checks(self.api_root_url, **kwargs) + self.interactions = Interactions(self.api_root_url, **kwargs)