def get_resource_method(name, template):
    """
    Creates a function that is suitable as a method for ResourceCollection.
    """
    def rsr_meth(self, **kwargs):
        http_method = template['http_method']
        extra_path = template.get('extra_path')
        if extra_path:
            fills = {'res_id': kwargs.pop('res_id', '')}
            path = self.path + (extra_path % fills)
        else:
            path = self.path
        response = self.client.request(http_method, path, **kwargs)

        loc = response.headers.get('location', None)

        if loc:
            # If the returned code is a 201, then there should be a location
            # header in the response that we can use to re-get the newly created
            # resource.
            loc = response.headers.get('location')
            response = self.client.get(loc, **kwargs)

        # At this point, we better have a valid JSON response object
        try:
            obj = response.json()
        except:
            # The response had no JSON ... not a resource object
            return

        if COLLECTION_TYPE in response.content_type:
            ret = HookList(
                    [Resource(r, path, response, self.client) for r in obj],
                    response=response
                    )
        else:
            ret = Resource(obj, path, response, self.client)
        return ret

    rsr_meth.__name__ = name
    return rsr_meth
Creates a function that is suitable as a method for ResourceCollection.