Best way to parse JSON in Rails for Twitter API
I'm working on a rails app that searches the Twitter API stream for keywords and then records those tweets.
I've used Hpricot before to parse XML but I w开发者_开发技巧as wondering if someone could recommend a gem (or even a best practice) to parse JSON from the Twitter search API?
If you use the newly rewritten Twitter gem, you can make a query like this:
Twitter.user_timeline("sferik").first
The response would be a Hashie::Mash object corresponding to the first status. To access the information, you just call the attribute like it was a method:
Twitter.user_timeline("sferik").first.text
The response from this is just text. You don't have to directly deal with JSON.
I believe there are many twitter gems that should work. Github has the twitter gem as the most popular.
I have used it 1 1/2 yrs ago, but it should do what you want and have support to back it up.
I use the json gem to parse Twitter responses. To access the api I use grackle and sometimes curb to do api requests in parallel (Curl::Multi).
精彩评论