Reputation: 1771
I'd like to make requests to APIs for a range of sites like Twitter, Facebook etc and store the results in my database.
The example request Twitter give is here: https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true
How do I go about making the request from my Rails 3 App and then store the data? I don't necessarily need all of the data, i'm mostly interested in followers in this case.
Many thanks in advance.
EDIT:
I tried adding this to my artists controller's show method:
require 'open-uri'
require 'json'
result = JSON.parse(open("https://api.twitter.com/1/users/show.json?screen_name=thesubways&include_entities=true").read)
parsed_json = ActiveSupport::JSON.decode(result)
@results = parsed_json["followers_count"]
Upvotes: 3
Views: 2203
Reputation: 11929
As for start ....
require 'open-uri'
require 'json'
result = JSON.parse(open("https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true").read)
# now you have result["followers_count"] ... and can use it to store with AR object or raw sql query
you also must use database in your rails project, but first of all you should read official guide http://guides.rubyonrails.org/getting_started.html
Upvotes: 1