| 1 |
# -------------------------------------------------------------------------------------------- |
| 2 |
# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 |
# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 |
# -------------------------------------------------------------------------------------------- |
| 5 |
|
| 6 |
from msrest.service_client import ServiceClient |
| 7 |
from msrest import Configuration |
| 8 |
|
| 9 |
class BaseGithubManager(object): |
| 10 |
|
| 11 |
def __init__(self, base_url='https://api.github.com', pat=None): |
| 12 |
"""Inits UserManager as to be able to send the right requests""" |
| 13 |
self._pat = pat |
| 14 |
self._config = Configuration(base_url=base_url) |
| 15 |
self._client = ServiceClient(None, self._config) |
| 16 |
|
| 17 |
def construct_github_request_header(self, pat=None): |
| 18 |
headers = { |
| 19 |
"Accept": "application/vnd.github.v3+json" |
| 20 |
} |
| 21 |
|
| 22 |
if pat: |
| 23 |
headers["Authorization"] = "token {pat}".format(pat=pat) |
| 24 |
elif self._pat: |
| 25 |
headers["Authorization"] = "token {pat}".format(pat=self._pat) |
| 26 |
|
| 27 |
return headers |
| 28 |
|
| 29 |
def close_connection(self): |
| 30 |
self._client.close() |