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

Docs are inconsistant: likes().data or likes.data ? #111

Open
andybak opened this issue May 16, 2016 · 3 comments
Open

Docs are inconsistant: likes().data or likes.data ? #111

andybak opened this issue May 16, 2016 · 3 comments

Comments

@andybak
Copy link

andybak commented May 16, 2016

I'm using a wrapper where the former works and the latter doesn't. Not sure if it's a bug in the wrapper but your docs use both forms:

likes().data: http://tapioca-wrapper.readthedocs.io/en/stable/quickstart.html#fetching-data

likes.data: http://tapioca-wrapper.readthedocs.io/en/stable/quickstart.html#iterating-over-data

@filipeximenes
Copy link
Contributor

@andybak, both are right.

  • In the first one we are printing the raw data (a python dictionary) from the API response.
  • The second one we are iterating over a list of TapiocaClient objects and internally in the for loop we print the raw data like.id().data, in this case a facebook id that is a string. So data is an attribute in the response.

Everytime we "call" an object, we transform it from TapiocaClient to TapiocaClientExecutor where we are able to perform actions in the objects. TapiocaClient is only able to traverse the object attriburtes.

This example was used on purpose so people would be forced into understanding the difference in this situations.
I'll keep this issue open so we add a note to the documentation explaining this.

@andybak
Copy link
Author

andybak commented May 16, 2016

Hmmmm. I don't recall seeing any other Python library where you can use the callable and non-callable form of an attribute in subtly different ways and it feels a trifle un-pythonic and hard to remember.

Why was this pattern chosen rather than - for example - always transforming to TapiocaClientExecutor ?

@filipeximenes
Copy link
Contributor

Agreed. I had to do some kind of DSL here to allow us to traverse the response using . (dot). Eg. this is a JSON response for http://www.something.com/api/resource.

{
  "data": {
    "attr": {
       "other_attr": "http://www.something.com/api/list-items"
    }
  }
}

res = api.resource().get()
to access the url you can do:
res.data.attr.other_attr
this will return a TapiocaClient wrapped string. If you need the raw string, you can do:
res.data.attr.other_attr().data
if you want to fetch what the url returns, you can do:
other_res = res.data.attr.other_attr().get()

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

2 participants