Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to work with HTTParty request results as an object

I wonder if it possible to work with HTTParty request results as an object.

Currently I use string keys to access to values of result: result["imageurl"] or result["address"]["street"]

If i were in JavaScript I could simply use: result.imageurl or result.address.street

like image 773
Alexey Zakharov Avatar asked Dec 12 '22 19:12

Alexey Zakharov


1 Answers

Use the Mash class of the hashie gem.

tweet = Hashie::Mash.new(
  HTTParty.get("http://api.twitter.com/1/statuses/public_timeline.json").first
)
tweet.user.screen_name
like image 83
Chubas Avatar answered May 10 '23 16:05

Chubas