kadirpekel/hammock — pull request #13 by twigs (2013-05-28 07:52:13+00:00)
Title: Allow the use of resource uris

Some rest based APIs use resource URIs to point to specific, usually related resources. These URIs are usually absolute paths for the domain hosting the API and are returned by previous API calls.
At the moment there is no way to use those URIs directly with hammock. You either have to modify the uri by removing leading slashes or to use requests directly.

This proposed patch adds a new keyword ``strip_slash`` which will remove leading and trailing slashes from the name when spawning new ``Hammock`` instances. This allows to use the URIs directly.

**current behavior**::

import hammock
api = hammock.Hammock('http://localhost:8000')
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri) # note the double slash after domain:port
http://localhost:8000//api/v1/users/4711/

**with ``strip_slash``**::

import hammock
api = hammock.Hammock('http://localhost:8000', strip_slash=True)
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri)
http://localhost:8000/api/v1/users/4711

**can be used with ``append_slash``**::

import hammock
api = hammock.Hammock('http://localhost:8000', strip_slash=True, append_slash=True)
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri)
http://localhost:8000/api/v1/users/4711/