Convert Json to Twitter object manually

56 views
Skip to first unread message

Smith Andre

unread,
Jan 21, 2014, 2:37:22 PM1/21/14
to twitter-...@googlegroups.com
Hello, I was just wondering if there was a way to take a saved twitter response and somehow convert it into a Twitter object like the gem would had you done a normal request.

Thanks

sferik

unread,
Jan 21, 2014, 2:49:18 PM1/21/14
to twitter-...@googlegroups.com
If you have a JSON string you can parse it into a Ruby Hash and send it to ::newFor example:

require 'json'
require 'twitter'
 
json = '{"id":7505382,"screen_name":"sferik","name":"Erik Michaels-Ober"}'
user = Twitter::User.new(JSON.parse(json, :symbolize_names => true))

If you have a faraday response, you can send it to ::from_response.
Reply all
Reply to author
Forward
0 new messages