Closed teward closed 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.
TL;DR: I assume you know what you're doing.
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.