Class: LiveJournal::Request::CheckFriends

Inherits:
Req
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Req

#dryrun!, #dumpresponse, #verbose!

Constructor Details

#initialize(user, lastupdate = nil) ⇒ CheckFriends

Returns a new instance of CheckFriends.



120
121
122
123
124
# File 'lib/livejournal/friends.rb', line 120

def initialize(user, lastupdate=nil)
  super(user, 'checkfriends')
  @lastupdate = lastupdate
  @interval = 90   # reasonable default?
end

Instance Attribute Details

#intervalObject (readonly)

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



116
117
118
# File 'lib/livejournal/friends.rb', line 116

def interval
  @interval
end

#lastupdateObject (readonly)

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



119
120
121
# File 'lib/livejournal/friends.rb', line 119

def lastupdate
  @lastupdate
end

Instance Method Details

#runObject

Returns true if there are new posts available.



126
127
128
129
130
131
132
# 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