Skip to content

Commit 3039b8b

Browse files
committed
Fixed bug with response code and exception and moved query params from constructor to the individual requests.
1 parent cdd4d10 commit 3039b8b

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

almaapi/__init__.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,38 @@ class AlmaAPIException(Exception):
88

99
class AlmaAPI:
1010

11-
def __init__(self, api, api_key, query_params=None):
11+
def __init__(self, api, api_key):
1212
self.api_url = 'https://api-eu.hosted.exlibrisgroup.com/almaws/v1/' + api + '/'
1313
self.api_key = '?apikey=' + api_key
14-
self.query_params = ''
1514

15+
def get(self, mms_id, query_params=None):
16+
__query_params__ = ''
1617
if query_params is not None:
1718
for key, value in query_params.items():
18-
self.query_params += '&' + key + '=' + value
19+
__query_params__ += '&' + key + '=' + value
1920

20-
def get(self, mms_id):
21-
url = self.api_url + mms_id + self.api_key + self.query_params
21+
url = self.api_url + mms_id + self.api_key + __query_params__
2222

2323
(response, content) = http.Http().request(url)
2424

25-
if response.status != '200':
26-
# print(response)
25+
if response.status != 200:
2726
root = ElementTree.ElementTree(ElementTree.fromstring(content)).getroot()
2827
error_message = root[1][0][1].text
2928
raise AlmaAPIException(str(response.status) + ': ' + error_message)
3029

3130
return content.decode('utf8')
3231

33-
def put(self, mms_id, body):
34-
url = self.api_url + mms_id + self.api_key + self.query_params
32+
def put(self, mms_id, body, query_params=None):
33+
__query_params__ = ''
34+
if query_params is not None:
35+
for key, value in query_params.items():
36+
__query_params__ += '&' + key + '=' + value
37+
38+
url = self.api_url + mms_id + self.api_key + __query_params__
3539
headers = {'Content-type': 'application/xml'}
3640

3741
(response, content) = http.Http().request(url, 'PUT', headers=headers, body=body)
38-
if response.status != '200':
42+
if response.status != 200:
3943
root = ElementTree.ElementTree(ElementTree.fromstring(content)).getroot()
4044
error_message = root[1][0][1].text
4145
raise AlmaAPIException(str(response.status) + ': ' + error_message)

almamarc/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __parse__(i, f):
2929
# Map record fields to a list
3030
self.fields = list(self.xml.findall('.//record/*'))
3131

32+
33+
3234
# Get the attributes of the XMl Object
3335
def __get_attributes__(xml):
3436
record = xml.find('.//record')

0 commit comments

Comments
 (0)