Class: LiveJournal::Request::CheckFriends
- Defined in:
- lib/livejournal/friends.rb
Overview
An example of polling for friends list updates.
req = LiveJournal::Request::CheckFriends.new(user)
req.run # always will return false on the first run.
loop do
puts "Waiting for new entries..."
sleep req.interval # uses the server-recommended sleep time.
break if req.run == true
end
puts "#{user.username}'s friends list has been updated!"
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
The server-recommended number of seconds to wait between running this.
-
#lastupdate ⇒ Object
readonly
If you want to keep your CheckFriends state without saving the object, save the #lastupdate field and pass it to a new object.
Instance Method Summary collapse
-
#initialize(user, lastupdate = nil) ⇒ CheckFriends
constructor
A new instance of CheckFriends.
-
#run ⇒ Object
Returns true if there are new posts available.
Methods inherited from Req
#dryrun!, #dumpresponse, #verbose!
Constructor Details
#initialize(user, lastupdate = nil) ⇒ CheckFriends
Returns a new instance of CheckFriends.
119 120 121 122 123 |
# File 'lib/livejournal/friends.rb', line 119 def initialize(user, lastupdate=nil) super(user, 'checkfriends') @lastupdate = lastupdate @interval = 90 # reasonable default? end |
Instance Attribute Details
#interval ⇒ Object (readonly)
The server-recommended number of seconds to wait between running this.
115 116 117 |
# File 'lib/livejournal/friends.rb', line 115 def interval @interval end |
#lastupdate ⇒ Object (readonly)
If you want to keep your CheckFriends state without saving the object, save the #lastupdate field and pass it to a new object.
118 119 120 |
# File 'lib/livejournal/friends.rb', line 118 def lastupdate @lastupdate end |
Instance Method Details
#run ⇒ Object
Returns true if there are new posts available.
125 126 127 128 129 130 131 |
# File 'lib/livejournal/friends.rb', line 125 def run @request['lastupdate'] = @lastupdate if @lastupdate super @lastupdate = @result['lastupdate'] @interval = @result['interval'].to_i @result['new'] == '1' end |