Sep 21
HTTParty 0.8.0 with MultiJson throws ‘NameError: constant JSON::Parser not defined’
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 commentsSep 19
Beautiful Earth
“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 commentsAug 27
Spicy Ketchup chez Raj!
Hurricane Irene is here. Since we can’t hit the beach this weekend, spicy ketchup is finally on the menu!
I’m starting with this recipe from the food network:
Ingredients
* 3 pounds very ripe tomatoes, coarsely chopped
* 1 1/2 teaspoons vegetable oil
* 1 small onion, finely chopped
* 1 large clove garlic, minced
* 1/4 cup light brown sugar
* 1/2 teaspoon ground mustard
* 1/2 teaspoon ground ginger
* 1/4 teaspoon crushed red pepper
* 1/4 teaspoon cayenne pepper
* 1/4 teaspoon ground allspice
* 1/8 teaspoon ground cloves
* Pinch ground cinnamon
* 1/4 cup cider vinegar
* Salt
Start by buying the ripest, most delicious tomatoes you can find.
| From Hurricane Irene |
We got these from a farmer’s market on 14th and U street in Northwest DC. The tomatoes are delicious: we ate one of the heirloom tomatoes destined for the pot in about 30 seconds flat.
Next, chop them coarsely and blend them to a puree.
Pass the puree through a wire mesh strainer and into a bowl or pot.
Use a wooden spoon to mash the paste through the strainer until all that remains is the solids.
Finely dice a small onion.
And fry it up.
Now the cooking begins. It will cook down for over an hour.
So delicious. It is mildly spicy: I will use 3x the crushed red pepper next time. I had no cider vinegar and used ordinary vinegar instead and it added became a little too tart. But man it was good. My cousins came over last night and we put the ketchup on everything from edamame to dumplings.
it was awesome.
No commentsAug 25
Next Energy Efficiency Project
Trying to pick my next home energy efficiency project. Melissa and I were supposed to go to the beach in Delaware this weekend but Hurricane Irene has thwarted our plans. I have a rainy weekend to try one of these:
1. Ceiling Fan in the guest bedroom. No more steaming while reading, and more comfortable for friends sleeping over
2. Solar Shades to keep the sun out and the place cooler (and let me sleep longer)
3. Home beer brewing. It takes soooo much energy to transport the beer from the brewery to me.
4. More motion detector light switches. Some of the lights turn off when you leave the room. Upgrade the rest of them.
Have to pick one, any suggestions?
3 commentsJul 25
Something I’ve been wanting to do…
There is something I’ve been wanting to do for a long time, but have
not been able to find a legal way to execute it.
Side Note: It doesn’t have to be legal, but it must be difficult to
detect and difficult for me to get in trouble.
How many times have you heard an awesome song and gotten yourself a
copy. The song might be rare, hard to find, or pretty obscure, but you
just want to share it with your friends. Some people, like my friend
Viraj, create a blog (http://http://videorue.blogspot.com/) where they
can post a YouTube link to the song. People take time to mix a song
with some graphics and post it onto youtube. I appreciate his efforts,
but the format isn’t easy to consume. You have to be sitting at your
computer, not on your phone, and manually click to start each song.
I want to podcast my music. A legitimate podcast where I can share my
MP3′s with my friends. I bought them legally, most through Amazon MP3,
after hearing them on Pandora (also paid subscription). I don’t mind
paying for my music, but I want a good way to share it.
Things I’ve considered are:
1. Putting up a private wordpress blog with PodPress where I can
upload all of this music, share the links with my friends, and
subscribe my Android phone to download automagically from.
2. Finding a third party podcasting service where I can upload my own stuff
The first one puts me at the mercy of my ISP. I’ve been caught for
doing this before with a prior ISP and they threatened to shut my site
down and send some kind of notice to the RIAA if I refused to comply.
I complied.
The second option could be shut down at any time and may not gain any
permanence. I used to upload stuff to CafePress.com, and they took
draconian measures to keep copyrighted content off of their site: If
they suspected that you didn’t own the content you posted, they’d
delete it immediately. They weren’t even 50% correct identifying
copyrighted content, and after the third or fourth time they deleted
all of my shit, i got fed up and gave up.
Just ranting and raving. I really want to be able to share my music!
3 comments