Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

First pass at options builder#212

Closed
LGraber wants to merge 1 commit intodevelopmenttableau/server-client-python:developmentfrom
builderstableau/server-client-python:buildersCopy head branch name to clipboard
Closed

First pass at options builder#212
LGraber wants to merge 1 commit intodevelopmenttableau/server-client-python:developmentfrom
builderstableau/server-client-python:buildersCopy head branch name to clipboard

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?


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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.