class LiveJournal::Request::CheckFriends

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!"

Attributes

interval[R]

The server-recommended number of seconds to wait between running this.

lastupdate[R]

If you want to keep your CheckFriends state without saving the object, save the lastupdate field and pass it to a new object.

Public Class Methods

new(user, lastupdate=nil) click to toggle source
Calls superclass method
# File lib/livejournal/friends.rb, line 120
def initialize(user, lastupdate=nil)
  super(user, 'checkfriends')
  @lastupdate = lastupdate
  @interval = 90   # reasonable default?
end

Public Instance Methods

run() click to toggle source

Returns true if there are new posts available.

Calls superclass method
# File lib/livejournal/friends.rb, line 126
def run
  @request['lastupdate'] = @lastupdate if @lastupdate
  super
  @lastupdate = @result['lastupdate']
  @interval = @result['interval'].to_i
  @result['new'] == '1'
end