-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira_connection_base.py
46 lines (32 loc) · 1.32 KB
/
jira_connection_base.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
38
39
40
41
42
43
import json
from base64 import b64encode
from http.client import HTTPSConnection
from abc import ABC, ABCMeta
class JiraConnection(ABC):
__metaclass__=ABCMeta
_body=""
_header=""
_userAndPass=b''
def setUserAndPass(self, userAndPassStr):
self._userAndPass=b64encode(bytes(userAndPassStr,'ascii')).decode("ascii")
return self
def setHeader(self):
self._headers = { 'Authorization' : 'Basic %s' % self._userAndPass, 'Content-Type': 'application/json' }
return self
def setBody(self,body_json):
self._body=body_json
return self
def sendRequest(self):
try:
self.connection=HTTPSConnection("jira.aspiraconnect.com")
self.connection.request('POST', '/rest/api/2/search', headers=self._headers, body=self._body)
return self.connection.getresponse().read()
except (ConnectionResetError, TimeoutError) as e:
raise Exception('Connection Error')
def requestInGet(self, path):
try:
self.connection=HTTPSConnection("jira.aspiraconnect.com")
self.connection.request('GET', path, headers=self._headers)
return self.connection.getresponse().read()
except (ConnectionResetError, TimeoutError) as e:
raise Exception('Connection Error')