In this blog I will create a Rhodes application which will sync your tweets through rhosync.
I am currently using Rhodes 2.1.0 and Rhosync 2.0.6.
If you want to some complex operation you can read twitter API docs:
http://dev.twitter.com/doc/get/statuses/user_timeline
Step 1.) Create a Rhodes Application
1.) Go to command prompt and create Rhodes application
>rhogen app twitter-api
>cd twitter-api
>rhogen model twitter text
2.) Now update index.erb( Adding a link to index page of Twitter controller
link_to “Twitter”, :controller => :Twitter
3.) Enable sync in Twitter model.
Update twitter.rb and add the following line
enable sync
4.) Update rhoconfig.txt(Setting the path for rhosync server)
syncserver = ‘http://localhost:9292/application’
5.) Start the simulator
rake run:bb
Step 2.) Create Rhosync Application
1.) Go to command promt
>rhosync app twitter –server
> cd twitter-server
>rhosync source twitter
2.) Update the source adapter twitter.rb
require ‘json’
require ‘open-uri’
Add this code in query method:
def query(params=nil)
parsed=""
open('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=nalwayaabhishek') do |f|
parsed=JSON.parse(f.read)
end
@result = {}
parsed.each do |item|
item_hash = {}
item_hash['text'] = item['text']
@result[item['id'].to_s] = item_hash
end
@result
end
3.) Start redis server
rake redis:start
4.) Start rhosync server
rake rhosync:start
By default it will start on port 9292.
Once the simulater is started Login with any username and password. And sync the data.
Now you can see your tweets even if you are offline.