tylercunnion / crunchbase

Ruby Crunchbase API wrapper
MIT License
51 stars 23 forks source link

Entity.all does not work #10

Closed rurabe closed 10 years ago

rurabe commented 10 years ago

This is more Crunchbase's fault, since it returns calls to this endpoint with invalid json. But since it's broken here you could implement a patch.

It seems what it's doing is returning arrays of 1000 records, concatenating the json (thus making it invalid).

[{ record1 }, ... { record 1000 }][{ record 1001 }, ... { record 2000 }][ ...... ]

super ugly patch as follows:

json = Net::HTTP.get(...)
valid_json = "[#{json.gsub(/\]\[/,"],[")}]"
hsh = JSON.load(valid_json)
desired_response = hsh.flatten
tylercunnion commented 10 years ago

Thanks for bringing this to my attention; I'll see if there's perhaps another way of going about fixing it (not overly concerned with ugliness though) and put a patch in.

tylercunnion commented 10 years ago

So my inattention and delay may have solved this for us actually: http://developer.crunchbase.com/forum/read/180214

They seem to have fixed this particular bug. I'm going to therefore close this, but as this isn't the first time they've had bugs of this nature (there's a reason that

resp = resp.gsub(/[[:cntrl:]]/, '')

exists in api.rb) it might be preferable to raise our own exception on malformed JSON going forward. I'll give it some thought.