-
Notifications
You must be signed in to change notification settings - Fork 121
Add query_params to appropriate methods #143
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
Conversation
|
Can one of the admins verify this patch? |
|
Thanks @Cadair. A couple notes:
|
|
Can't comment on the sphinx stuff since I'm not familiar with it at all, but I can tell you @Half-Shot will want it in a separate PR. I can also tell you it will almost certainly be very appreciated. ;) Oh, also, you'll need to sign-off before anything is merged. See Contributing.rst |
non-Jedi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly prefer using an explicit query_params={} rather than **query_params since we already use **kwargs on login.
matrix_client/api.py
Outdated
| """ | ||
|
|
||
| def __init__(self, base_url, token=None, identity=None): | ||
| def __init__(self, base_url, token=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the ability to use an api object per mxid without having to explicitly pass in the user_id kwarg on every request.
| Common values for ``query_params`` are: | ||
| | ts: timestamp for event | ||
| | user_id: user id for transaction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good documentation. Need to add note in parentheses about these values only being useful for application services. Matrix newcomers may use python sdk as reference without reading the spec.
| return self._send("GET", "/initialSync", query_params={"limit": limit}) | ||
| query_params['limit'] = limit | ||
| return self._send("GET", "/initialSync", | ||
| query_params=query_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going with the convention of query_params being slurped by
**query_params, we should also consider slurping the query_params for _send
in the same way and splatting the query_params dict here into the _send
call.
| Common values for ``query_params`` are: | ||
| | ts: timestamp for event | ||
| | user_id: user id for transaction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note as above for all documentation about params being AS-specific.
matrix_client/api.py
Outdated
| request = { | ||
| "timeout": timeout_ms | ||
| } | ||
| request = query_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename this variable query_params for consistency.
matrix_client/api.py
Outdated
|
|
||
| def sync(self, since=None, timeout_ms=30000, filter=None, | ||
| full_state=None, set_presence=None): | ||
| full_state=None, set_presence=None, **query_params): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency of the api, we should probably deprecate since, timeout_ms, filter, full_state, and set_presence kwargs in favor of slurping those things with **query_params. Unfortunately, I don't think there's any way to raise a deprecation warning for kwargs specified positionally and not raise a warning for the same kwargs specified by identifier. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could do that by using a decorator that does funky things with signature objects. I think it might be Python 3 only though.
matrix_client/api.py
Outdated
| **query_params: Extra parameters to be sent in the HTTP request. | ||
| Common values for ``query_params`` are: | ||
| | ts: timestamp for event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My gut says that ts is not a query_param that makes sense for this api call.
matrix_client/api.py
Outdated
| **query_params: Extra parameters to be sent in the HTTP request. | ||
| Common values for ``query_params`` are: | ||
| | ts: timestamp for event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we need to make sure query_param values make sense for the api call before mentioning them in the documentation. user_id does, but ts probably doesn't.
| query_params=query_params | ||
| ) | ||
|
|
||
| def login(self, login_type, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I don't like using **query_params. Now we've introduced
inconsistency to our api methods. Sometimes, extra kwargs are treated as extra
json, and sometimes they're params.
Additionally, there might be times when an AS that's e2e-aware would make use of
login/logout api methods. Not sure; would need to double-check this.
matrix_client/api.py
Outdated
| "timeout": timeout, | ||
| "from": from_token | ||
| } | ||
| query_params.update(params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query_params["timeout"] = timeout
query_params["from"] = from_tokenis slightly cleaner, but whatever.
This makes it easy to have a appservice use one API instance to act as many users.
|
@non-Jedi I have changed from |
|
@Cadair thanks. Will take a look when I get a chance (probably after I finally get to the doc updates). Could you fix the failing flake8 test from Travis, please? |
|
@Cadair turns out Haven't thought about this enough to know what correct solution is, but I just |
|
Yeah I thought about that the other day as well. It's not just query params that does that in the api though. I will go through and replace them all with |
|
Thinking about this again, I think AS support should be pushed entirely into a subclass of I'm trying to push this sdk towards being as modular/composable as possible, and this seems like a step in the correct direction while also making things unique to different |
|
I need to give this some thought. off the top of my head I feel like this is a good argument for |
|
Could be. Need to look again at api methods that currently slurp kwargs first. If we do go that route, we should call the slurped kwargs |
This now adds
**query_paramsto most methods to allow specification of appservice parameters liketsanduser_id.It also does a bunch of documentation updates and moves from
sphinxcontrib.napoleontosphinx.ext.napoleon.This introduces a breaking change of
timestamp=tots=.Signed-off-by: Stuart Mumford stuart@cadair.com