Skip to content

Commit

Permalink
added the possibility to add format to the url itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Smouter committed Feb 23, 2012
1 parent 77c50d7 commit e5faa69
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions slumber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def _request(self, method, data=None, params=None):
s = self.get_serializer()
url = self._store["base_url"]

if self._store["append_slash"] and not url.endswith("/"):
if self._store["append_slash"] and not url.endswith("/") \
and not self._store["append_format"]:
url = url + "/"

if self._store["append_format"] and not url.endswith(self._store["format"]):
url = url + ".%s" % self._store["format"]

resp = self._store["session"].request(method, url, data=data, params=params, headers={"content-type": s.get_content_type()})

Expand Down Expand Up @@ -159,11 +163,13 @@ def delete(self, **kwargs):

class API(ResourceAttributesMixin, object):

def __init__(self, base_url=None, auth=None, format=None, append_slash=True):
def __init__(self, base_url=None, auth=None, format=None, append_slash=True,
append_format=False):
self._store = {
"base_url": base_url,
"format": format if format is not None else "json",
"append_slash": append_slash,
"append_format": append_format,
"session": requests.session(auth=auth),
}

Expand Down

0 comments on commit e5faa69

Please sign in to comment.