Charcoal-SE / SmokeDetector-ng

SmokeDetector reboot project.
Apache License 2.0
6 stars 3 forks source link

Refactor the Post object API Response parser #1

Closed teward closed 7 years ago

teward commented 7 years ago

This uses a dict that is the static mapping of response elements to internal variables, and the newly-written getitem/setitem methods, to iterate through known / parseable elements in the response, and then gets data from the response and sets it into the internal variables of the Post object using the new setitem methods.

Should there be a KeyError anywhere, it's likely because the API response does not have that key, so we just simply move on to the next item in the element map. As an example, this way, if 'question_id' is present, it'll use that for self._post_id, and if not, 'answer_id' will be used; failing that, it falls back to a default value of "0" for _post_id which was defined in the object itself.

teward commented 7 years ago

And yes I used a pull request, because I did some testing and design of this in a separate repository. And start with a GitHub commit and move on to PyCharm for further implementation and testing.

ArtOfCode- commented 7 years ago

TL;DR: I assume you know what you're doing.