8000 First pass at options builder by LGraber · Pull Request #212 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

First pass at options builder #212

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

Closed
wants to merge 1 commit into from
Closed

First pass at options builder #212

wants to merge 1 commit into from

Conversation

LGraber
Copy link
Contributor
@LGraber LGraber commented Aug 7, 2017

Not ready to actually submit this but I find our current syntax for building a filter / sort set ... yucky. I implemented a simple builder pattern. "_" prefixed methods have special meaning. For all other methods, the name is the property you are filtering on and the 2 params are an operator and value. I just accept simple strings that actually look like the operator. I imagine later I can add "_include" when we expose fields. You can see in the sample that it makes it much easier to read. All of our samples only have one filter so it isn't so bad but it would get bad quickly if you did any more

Copy link
Collaborator
@t8y8 t8y8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think I like the way it reads, would need more time to play with it.

The one thing I don't like is the .build() part of the API. It feels very Java.

Is there a way for it to always be ready to send (builds after every update or the endpoint logic calls build on the 'requestmodel' for you?

@@ -25,6 +28,35 @@ class Direction:
Desc = 'desc'
Asc = 'asc'

class Builder:
def __init__(self):
self.__pagenumber = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the __ is necessary (it invokes name mangling to avoid inheritance problems but here I think you can just make it the _... it's more 'polite' form :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double underscore was needed to disambiguate with the call to _pagenumber that I was specifically handling. If I don't do this, it actually fails

@graysonarts
Copy link
Contributor

How about the contract for the Filters/Request Options/etc is that we call str(...) and the objects are required to implement __str__(self), and that's our contract. It's simple, and easy to understand. No need for a build method, and when we are creating the request, we just have to do format('...{}...', options) and python should automatically call __str__.

@t8y8
Copy link
Collaborator
t8y8 commented Aug 8, 2017

@RussTheAerialist I like that contract

@LGraber
Copy link
Contributor Author
LGraber commented Aug 9, 2017

I think I am a bit confused. If I don't call _build() and so still have a Builder object, what do I call to actually get a RequestOptions object? I need to call something, right? Also, if we don't have a "build" method, then why did I call it a Builder?

@t8y8
Copy link
Collaborator
t8y8 commented Aug 9, 2017

I think @RussTheAerialist is proposing you just create a RequestOptions object and it has all the methods you currently have on Builder.

Then, the contract for endpoints is to call str(request_object) -- which is really easy to test and manage

@graysonarts
Copy link
Contributor

Closing for inactivity

@bcantoni bcantoni deleted the builders branch December 3, 2020 21:13
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

Successfully merging this pull request may close these issues.

3 participants
0