class LiveJournal::Sync::Entries
To run a sync, create a Sync::Entries
object, then call Entries#run_syncitems
to fetch the sync metadata, then call Entries#run_sync
to get the actual entries.
Attributes
lastsync[R]
To resume from a previous sync, pass in its lastsync value.
Public Class Methods
new(user, lastsync=nil)
click to toggle source
# File lib/livejournal/sync.rb, line 96 def initialize(user, lastsync=nil) @user = user @logitems = {} @lastsync = lastsync end
Public Instance Methods
run_sync() { |entries_hash, lastsync, remaining_count| ... }
click to toggle source
# File lib/livejournal/sync.rb, line 117 def run_sync # :yields: entries_hash, lastsync, remaining_count return if @logitems.empty? lastsync = @lastsync while @logitems.size > 0 req = Request::GetEvents.new(@user, :lastsync => lastsync) entries = req.run # pop off all items that we now have entries for entries.each do |itemid, entry| time = @logitems.delete itemid lastsync = time if lastsync.nil? or time > lastsync end yield entries, lastsync, @logitems.size end end
run_syncitems() { |cur, total| ... }
click to toggle source
# File lib/livejournal/sync.rb, line 101 def run_syncitems # :yields: cur, total cur = 0 total = nil items = {} lastsync = @lastsync while total.nil? or cur < total req = Request::SyncItems.new(@user, items, lastsync) lastsync = req.run cur += req.fetched total = req.total unless total yield cur, total if block_given? end @logitems = Request::SyncItems::subset_items(items, 'L') return (not @logitems.empty?) end