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

Make data explicit. #4

Open
hbredin opened this issue Dec 18, 2014 · 2 comments
Open

Make data explicit. #4

hbredin opened this issue Dec 18, 2014 · 2 comments

Comments

@hbredin
Copy link
Member

hbredin commented Dec 18, 2014

Most methods have a data parameter that is not very self-explanatory.
For instance, how would someone know what to put in data when calling client.create_user(data)?

It would be better to define clearly what is expected from the user.
Otherwise, to use the client, one must have a look at the REST API documentation.

def create_user(self, username=None, password=None, role='user'):
    data = {'username': username, 'password': password, 'role': role}
    self.post('user', data)

This stands for most methods (not only create_user).
@clbarras @juandelamontana what do you think?

@clbarras
Copy link

Le 18/12/2014 13:47, Hervé BREDIN a écrit :

Most methods have a |data| parameter that is not very self-explanatory.
For instance, how would someone know what to put in |data| when calling |client.create_user(data)|?

It would be better to define clearly what is expected from the user.
Otherwise, to use the client, one must have a look at the REST API documentation.

|def create_user(self, username=None, password=None, role='user'):
data = {'username': username, 'password': password, 'role': role}
self.post('user', data)
|

This stands for most methods (not only |create_user|).
@clbarras https://github.com/clbarras @juandelamontana https://github.com/juandelamontana what
do you think?

very good idea - if we wish to allow both approaches and retain compatibility with current client we
could also do

|def create_user(self, data=None, username=None, password=None, role='user'):
||| if data is None:
data = ...

  • Claude
    ||

@hbredin
Copy link
Member Author

hbredin commented Dec 19, 2014

Yes, but what if both data and username are provided ? :)

data = {'username': 'toto', 'password': 'toto', 'role': 'user'}
client.create_user(**data)

is equivalent to

client.create_user(username='toto', password='toto', role='user')

So old code using client.create_user(data=data) just needs to be changed into client.create_user(**data)

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

No branches or pull requests

2 participants