Skip to content

Commit

Permalink
Merge pull request #5 from boegel/cleanup
Browse files Browse the repository at this point in the history
fix remarks
  • Loading branch information
Jens Timmerman committed May 19, 2016
2 parents b4fd101 + 05dbd75 commit 10fdab8
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/vsc/utils/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get(self, url, headers=None, **params):
Do a http get request on the given url with given headers and parameters
Parameters is a dictionary that will will be urlencoded
"""
if self.append_slash:
if self.append_slash and not url.endswith('/'):
url += '/'
url += self.urlencode(params)
return self.request(self.GET, url, None, headers)
Expand All @@ -133,10 +133,7 @@ def delete(self, url, headers=None, body=None, **params):
if self.append_slash:
url += '/'
url += self.urlencode(params)
if headers is None:
headers = {}
headers['Content-Type'] = 'application/json'
return self.request(self.DELETE, url, json.dumps(body), headers)
return self.request(self.DELETE, url, json.dumps(body), headers, content_type='application/json')

def post(self, url, body=None, headers=None, **params):
"""
Expand All @@ -146,10 +143,7 @@ def post(self, url, body=None, headers=None, **params):
if self.append_slash:
url += '/'
url += self.urlencode(params)
if headers is None:
headers = {}
headers['Content-Type'] = 'application/json'
return self.request(self.POST, url, json.dumps(body), headers)
return self.request(self.POST, url, json.dumps(body), headers, content_type='application/json')

def put(self, url, body=None, headers=None, **params):
"""
Expand All @@ -159,10 +153,7 @@ def put(self, url, body=None, headers=None, **params):
if self.append_slash:
url += '/'
url += self.urlencode(params)
if headers is None:
headers = {}
headers['Content-Type'] = 'application/json'
return self.request(self.PUT, url, json.dumps(body), headers)
return self.request(self.PUT, url, json.dumps(body), headers, content_type='application/json')

def patch(self, url, body=None, headers=None, **params):
"""
Expand All @@ -172,15 +163,16 @@ def patch(self, url, body=None, headers=None, **params):
if self.append_slash:
url += '/'
url += self.urlencode(params)
if headers is None:
headers = {}
headers['Content-Type'] = 'application/json'
return self.request(self.PATCH, url, json.dumps(body), headers)
return self.request(self.PATCH, url, json.dumps(body), headers, content_type='application/json')

def request(self, method, url, body, headers):
def request(self, method, url, body, headers, content_type=None):
"""Low-level networking. All HTTP-method methods call this"""
if headers is None:
headers = {}

if content_type is not None:
headers['Content-Type'] = content_type

if self.auth_header is not None:
headers['Authorization'] = self.auth_header
headers['User-Agent'] = self.user_agent
Expand Down

0 comments on commit 10fdab8

Please sign in to comment.