Always operate on the HTTParty's parsed_response, both instance- and class-wise.
Always operate on the HTTParty's parsed_response, both instance- and class-wise.

This is (1) to keep parity with how the instance-based #get_* and #post methods
work (which use #map_data, which uses the parsed_response), and (2) to avoid any
further bizarre/hidden behaviours due to HTTParty::Response trying really hard
to be a transparent proxy for Hash.

In the success (HTTP 200) case, parsed_response appears to always be a String.
In the failure (HTTP 4xx) case, parsed_response appears to always be a Hash.

Background:

Mogli::Client.response_is_error? doesn't appear work.  When calling
Mogli::Client.create_from_code_and_authenticator, response_is_error? always
returns false.  This is because post_data.is_a?(::HTTParty::Response) == false
even though post_data.class == HTTParty::Response.  The consequence in the
failure case was that the subsequent #split (delegated transparently to
parsed_data) would throw a NoMethodError -- because it was a Hash, not a String.
Worked in the success case because, again, response_is_error? always returned
false, and the delegated #split would be sent to a String.

Fixing Moglie::Client.response_is_error?:

  if ::HTTParty::Response === post_data # ...

which would have avoided the proxy/delegation of the class match to Hash.

But I still argue that this patch is the better solution.

mmangino/mogli