Skip to content

Commit

Permalink
Merge pull request #96 from samgiles/url-endpoint
Browse files Browse the repository at this point in the history
Add url() endpoint to return the url that represents a resource
  • Loading branch information
samgiles committed Nov 15, 2014
2 parents 176e35f + 5cf6c13 commit d2a7a6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions slumber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ def __call__(self, id=None, format=None, url_override=None):

def _request(self, method, data=None, files=None, params=None):
s = self._store["serializer"]
url = self._store["base_url"]

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

headers = {"accept": s.get_content_type()}

Expand Down Expand Up @@ -126,6 +123,14 @@ def _try_to_serialize_response(self, resp):
else:
return resp.content

def url(self):
url = self._store["base_url"]

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

return url

def get(self, **kwargs):
resp = self._request("GET", params=kwargs)
if 200 <= resp.status_code <= 299:
Expand Down
3 changes: 3 additions & 0 deletions tests/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,6 @@ def test_api(self):
resp = client.test.get()

self.assertEqual(resp['result'], ['a', 'b', 'c'])

def test_url(self):
self.assertEqual(self.base_resource.url(), "http://example/api/v1/test")

0 comments on commit d2a7a6d

Please sign in to comment.