Skip to content

Commit

Permalink
normalize url in a single central place (GlpiService.request)
Browse files Browse the repository at this point in the history
  • Loading branch information
costela committed May 31, 2017
1 parent fdc79bf commit 381f8ff
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions glpi/glpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ def request(self, method, url, accept_json=False, headers={},
(http://docs.python-requests.org/en/master/api/#requests.Response)
"""

full_url = self.url + url
if self.session is None:
new_session = True
full_url = '%s/%s' % (self.url, url.strip('/'))

input_headers = _remove_null_values(headers) if headers else {}

Expand Down Expand Up @@ -281,15 +279,14 @@ def create(self, data_json=None):
def get_all(self):
""" Return all content of Item in JSON format. """

uri = '/' + self.uri
res = self.request('GET', uri)
res = self.request('GET', self.uri)
return res.json()

def get(self, item_id):
""" Return the JSON item with ID item_id. """

if isinstance(item_id, int):
uri = '/%s/%d' % (self.uri, item_id)
uri = '%s/%d' % (self.uri, item_id)
response = self.request('GET', uri)
return response.json()
else:
Expand All @@ -298,8 +295,7 @@ def get(self, item_id):

def get_path(self, path=''):
""" Return the JSON from path """
uri = '/%s' % (path)
response = self.request('GET', uri)
response = self.request('GET', path)
return response.json()

def search_options(self, item_name):
Expand Down

0 comments on commit 381f8ff

Please sign in to comment.