Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resource name in a string #44

Open
adam-dziedzic opened this issue Nov 2, 2012 · 4 comments
Open

add resource name in a string #44

adam-dziedzic opened this issue Nov 2, 2012 · 4 comments

Comments

@adam-dziedzic
Copy link

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.

@merwok
Copy link
Contributor

merwok commented Jan 30, 2013

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.

@dstufft
Copy link
Collaborator

dstufft commented Feb 7, 2013

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.

@PetrDlouhy
Copy link

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.

@PetrDlouhy
Copy link

PetrDlouhy commented Feb 21, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants