its-rigs / Trolly

A Python wrapper around the Trello API. Provides a group of Python classes to represent Trello Objects. All classes come with basic Trello API method calls and are easily extensible to suit your needs. See the README for more details.
MIT License
100 stars 29 forks source link

Change Card.add_label to pick the correct resource #32

Closed jean closed 8 years ago

jean commented 8 years ago

POST to /labels/ if creating a label by name. POST to /idLabels/ if assigning a label (pass Label instance).

jean commented 8 years ago

@plish I agree they should be two methods .. I've got a fancy singledispatch-based implementation here: https://github.com/plish/Trolly/pull/36/files It's conflicted now, but I can update if you like the approach.

its-rigs commented 8 years ago

@jean never seen that before, but it is definitely a lot cleaner. Think that is the better approach.

jean commented 8 years ago

@plish I'm at a C# shop now, so I was getting envious of them using multiple-dispatch all over the place. And turns out at least single-dispatch in Python is easy :-)

I'm depending on singledispatch from PyPI for 2.7 compatibility. For 3.4+ it's part of functools. I wouldn't mind if Trolly went 3.4.

The only thing that bothers me about the approach in #36 is that the different implementations return different things: the original (/labels) API returns JSON for the new label, and the new (/idLabels) returns (logically) a list of label ids.

I don't think that this is a problem, since in the new case you already have the label object with all its properties.