Restructure API client
Review Request #4021 — Created April 4, 2013 and submitted
Restructure API client. Instead of wrapping everything and hiding resources inside of various Transport objects, Resource objects are now returned to the user. The Transport no longer serves as an all-wrapping, interface to and between everything, super object, but as a simple interface to the Review Board server. Resource method calls which return HttpRequests are now decorated, which serves as the new wrapping mechanism. The decorator captures calls to these methods, and passes the internal method, and arguments, off to the Transport to be executed. The new simpler Transport now only provides a few core methods; primarily it needs to be able to massage the provided arguments, call the method, and deal with the returned HttpRequest in a suitable manner. This should make writing a new Async Transport simple. Now that proper Resource objects are returned, API users can rely on checking class types using isinstance to differentiate between item and list resources etc. Additionally, dictionary or list fields returned from a resource use standard class types, regardless of the transport used. Also, the unit tests have been updated to test the new code, and are much more sane (reaching into internals much less).
Ran the new unit tests (passed), ran a number of unchanged rbt commands (including posting this request with 'rbt post'), and used my development Review Bot instance to test the new code (Review Bot is a user of the api).
Description | From | Last Updated |
---|---|---|
Missing a trailing period. |
chipx86 | |
Can we maybe swap this to be: if kwargs.pop('internal', True): ... else: ... It's easier to read. |
chipx86 | |
Can you fit "self" on the setattr line and the other parameters aligned to that? |
chipx86 | |
Can you indent this one more level? |
chipx86 | |
Same as above. |
chipx86 | |
Same as above. |
chipx86 | |
Blank line above. |
chipx86 | |
I don't see anything overwriting attribute setting. Can you not just do self._resource = ... ? Failing that, can you … |
chipx86 | |
Where does _fields_dict come from? Should this be _fields? If so, can you just do self._fields, like you do below? |
chipx86 | |
No need for outer parens. |
chipx86 | |
Do you need the ".__iter__" ? |
chipx86 | |
Same comments as above. |
chipx86 | |
Should end with a period. |
chipx86 | |
Should end with a period. |
chipx86 | |
HEY! I found the missing "i" ! |
chipx86 | |
Maybe flip these? Seems more natural to read "If this is an HttpRequest, execute it." |
chipx86 | |
embedded |
david | |
Can you group the private variables together? |
chipx86 | |
No need for parens. |
chipx86 | |
This duplicates all the logic of __getattr__. Maybe we can consolidate them? Maybe just something as simple as: try: return … |
chipx86 | |
Should be able to put the first param on the create_resource line and align them all. |
chipx86 | |
Can you just do this? return xrange(self.num_items) |
david | |
Shouldn't need parens or +. Or is ReviewBot yelling at you? |
chipx86 |
-
-
-
-
-
-
-
-
-
I don't see anything overwriting attribute setting. Can you not just do self._resource = ... ? Failing that, can you do: self.__dict__.update({ '_resource': ..., '_fields': ..., }) I'd prefer that format.
-
Where does _fields_dict come from? Should this be _fields? If so, can you just do self._fields, like you do below?
-
-
-
-
-
-
-
- Change Summary:
-
Fixed based on Christian's review. Also added some new unit tests.
- Description:
-
Restructure API client.
Instead of wrapping everything and hiding resources inside of various
Transport objects, Resource objects are now returned to the user. The Transport no longer servers as an all-wrapping, interface to and between everything, super object, but as a simple interface to the Review Board server. Resource method calls which return HttpRequests are now decorated,
which serves as the new wrapping mechanism. The decorator captures calls to these methods, and passes the internal method, and arguments, off to the Transport to be executed. The new simpler Transport now only provides a few core methods; primarily it needs to be able to massage the provided arguments, call the method, and deal with the returned HttpRequest in a suitable manner. This should make writing a new Async Transport simple. Now that proper Resource objects are returned, API users can rely on
checking class types using isinstance to differentiate between item and list resources etc. Additionally, dictionary or list fields returned from a resource use
standard class types, regardless of the transport used. Also, the unit tests have been updated to test the new code, and are
much more sane (reaching into internals much less). - - Based on /r/4004
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/api/resource.py rbtools/api/transport/__init__.py rbtools/api/decorators.py rbtools/api/factory.py rbtools/api/transport/sync.py rbtools/api/tests.py Ignored Files:
- Change Summary:
-
Updated based on David's and Christian's reviews.
- Description:
-
Restructure API client.
Instead of wrapping everything and hiding resources inside of various
Transport objects, Resource objects are now returned to the user. The ~ Transport no longer servers as an all-wrapping, interface to and ~ Transport no longer serves as an all-wrapping, interface to and between everything, super object, but as a simple interface to the Review Board server. Resource method calls which return HttpRequests are now decorated,
which serves as the new wrapping mechanism. The decorator captures calls to these methods, and passes the internal method, and arguments, off to the Transport to be executed. The new simpler Transport now only provides a few core methods; primarily it needs to be able to massage the provided arguments, call the method, and deal with the returned HttpRequest in a suitable manner. This should make writing a new Async Transport simple. Now that proper Resource objects are returned, API users can rely on
checking class types using isinstance to differentiate between item and list resources etc. Additionally, dictionary or list fields returned from a resource use
standard class types, regardless of the transport used. Also, the unit tests have been updated to test the new code, and are
much more sane (reaching into internals much less).