method-inc / bamboozled

Bamboozled wraps the BambooHR API without the use of Rails dependencies.
MIT License
44 stars 50 forks source link

🐛Error parsing valid JSON response #65

Open rhec opened 5 years ago

rhec commented 5 years ago

Description

The JSON response from the server is failing to parse, because bamboozled is passing a HTTParty::Response object to JSON.parse. This will raise an exception: ArgumentError: strict_parse() expected a String or IO Object. That exception is caught, and bamboozled attempts to parse the JSON as XML, which also fails and raises an exception. That exception is not caught.

Expected behavior

The JSON from the server is parsed and returned.

How To Reproduce

irb(main):004:0> client = Bamboozled.client(subdomain: "<subdomain redacted>", api_key: "<api key redacted>")
irb(main):005:0> client.employee.all
MultiXml::ParseError: 1:1: FATAL: Start tag expected, '<' not found
    from (irb):5

Environment

Ruby 2.4.5

Dependencies: httparty (0.13.3) json (1.8.6)

Potential solution

Change JSON.parse(response) to JSON.parse(response.body) in base.rb.

splybon commented 5 years ago

@rhec thanks for the issue! Sorry it's taken a while to get back to you. The change you put in looks pretty good.

I'm having a hard to replicating the issue though. I'm guessing it has to do with the response that bamboo is giving you. Would you be able to paste in the response that you are getting back from bamboo?

splybon commented 5 years ago

@rhec we just updated the gem versions to httparty and json with bamboozled version 0.3.0. Can you see if that magically fixes your issue?