Archive for September, 2011

Do you know this person?

September 27th, 2011 | Category: funnies

Least Interesting man in the World

 
Click the picture to enlarge. from http://www.xkcd.com

1 comment

HTTParty 0.8.0 with MultiJson throws ‘NameError: constant JSON::Parser not defined’

September 21st, 2011 | Category: geek out

I’d written a gem to make requests of an OPOWER internal API. In that gem, I’d used HTTParty 0.7.8 to do the get, put, etc to the API endpoint. I’d used Crack to parse the JSON. HTTParty revvd to 0.8.0 and seemingly removed Crack support. Here is how I got my gem to work again.

1. Update the Gemfile and Gemfile.lock to use the new version of httparty

2. Started seeing errors like this:

NameError: constant JSON::Parser not defined
/Users/rbanerjee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/rbanerjee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/rbanerjee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/rbanerjee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/rbanerjee/.rvm/gems/ruby-1.9.2-p180/gems/multi_json-1.0.3/lib/multi_json.rb:30:in `block in default_engine'

and

NotImplementedError: HTTParty::Parser has not implemented a parsing method for the :json format.
/Users/rbanerjee/.rvm/gems/ruby-1.9.2-p180/gems/httparty-0.8.0/lib/httparty/parser.rb:138:in `rescue in parse_supported_format'
/Users/rbanerjee/.rvm/gems/ruby-1.9.2-p180/gems/httparty-0.8.0/lib/httparty/parser.rb:136:in `parse_supported_format'

Huh? That doesn’t make any sense: HTTParty doesn’t have a built in JSON parser? What about the dependencies it just listed? Turns out that the second error is a result of the first failure.

3. Did some digging into multi_json docs, which are listed as a dependency. The first example in the basic doc is incorrect and I had to do a little tweaking.

SOLUTION

1. Fix your require statements at the top of your class:
require 'httparty'
require 'multi_json'

2. Inside your class or module,
include HTTParty
include MultiJson

3. Place this near your code, in a place where it’ll effect every function:
MultiJson.engine = :json_gem

Good luck. Drop a note and let me know if this worked / didn’t work for you.

No comments

Beautiful Earth

September 19th, 2011 | Category: geek out

“Science educator James Drake took 600 still photos from the International Space Station as it orbited the Earth, and created a fantastic time-lapse animation out of them. It must be seen to be appreciated; storms and cities fly past below in amazing clarity.”

 

from Slashdot. Turn to high-def mode and full screen for this gorgeous video!

No comments