Class: LiveJournal::Request::CheckFriends
- Inherits:
-
Req
- Object
- Req
- 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)
-
- (Object) interval
readonly
The server-recommended number of seconds to wait between running this.
-
- (Object) lastupdate
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)
-
- (CheckFriends) initialize(user, lastupdate = nil)
constructor
A new instance of CheckFriends.
-
- (Object) run
Returns true if there are new posts available.
Methods inherited from Req
#dryrun!, #dumpresponse, #verbose!
Constructor Details
- (CheckFriends) initialize(user, lastupdate = nil)
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
- (Object) interval (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 |
- (Object) lastupdate (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
- (Object) run
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 |