add resource name in a string
My resource name contains hyphens (-). I can only use underscore (_) character for a name in Python. I do a hack like this:
PATH = 'http://localhost:8000/api/v1/' # (the real url should be: http://localhost:8000/api/v1/conf/) response_post = api.conf("pdus-oid2").post(pdu.dict) response_delete = api.conf("pdus-oid2/" + response_post["_id"]).delete()
whereas "pdus-oid2" is the name of the resource. Thus, I reckon you should add a possibility of adding a resource name in a string.
Not a slumber dev, but I think this would be hard to do. Given slumber’s simple principle of converting Python attributes to URI path segments and using a call for invalid syntax (like integers), your solution sounds like the way to go.
IOW, I think base.thing('hyphen-dash').get() is as good as base.things(42).get()
In the spirit of OO path manipulation libraries, you could make the case for new syntax like base / things / 'hyphen-dash' and base / things / 42, i.e. overriding the division operator, but this looks more cute/wrong to me.
This would be possible to do if the base API object became a resource in it's own right, then you could do api("pdus-oid2").post() and such, however I'm not sure offhand how that world behind that, api("pdus-oid2")(25).delete() looks kinda gnarly to me and non obvious.
I'm not particully able to have the time to implement this, but if you brought API inline with Resource in this capacity I would probably be willing to accept it.
After I have wandered to this page, I have found my solution to this problem. Using getattr can do it. The
response = getattr(zmenteto_api.forms, "post-files").post(photo_json)
works for me just fine.
Now I have found even better (much more readable) solution:
zmenteto_api.forms.__call__("post-files").post(photo_json)
It also solves problem with API endpoints on reserved keywords like delete.