Class: LiveJournal::Request::SyncItems

Inherits:
Req
  • Object
show all
Defined in:
lib/livejournal/sync.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Req

#dryrun!, #dumpresponse, #verbose!

Constructor Details

#initialize(user, syncitems = nil, lastsync = nil) ⇒ SyncItems

Returns a new instance of SyncItems.



39
40
41
42
43
# File 'lib/livejournal/sync.rb', line 39

def initialize(user, syncitems=nil, lastsync=nil)
  super(user, 'syncitems')
  @syncitems = syncitems || {}
  @request['lastsync'] = lastsync if lastsync
end

Instance Attribute Details

#fetchedObject (readonly)

Returns the value of attribute fetched.



38
39
40
# File 'lib/livejournal/sync.rb', line 38

def fetched
  @fetched
end

#syncitemsObject (readonly)

Returns the value of attribute syncitems.



38
39
40
# File 'lib/livejournal/sync.rb', line 38

def syncitems
  @syncitems
end

#totalObject (readonly)

Returns the value of attribute total.



38
39
40
# File 'lib/livejournal/sync.rb', line 38

def total
  @total
end

Class Method Details

.subset_items(syncitems, want_type = 'L') ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/livejournal/sync.rb', line 60

def self.subset_items(syncitems, want_type='L')
  items = {}
  syncitems.each do |item, time|
    next unless item =~ /^(.)-(\d+)$/
    type, id = $1, $2.to_i
    items[id] = time if type == want_type
  end
  items
end

Instance Method Details

#runObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/livejournal/sync.rb', line 45

def run
  super
  lasttime = nil
  @fetched = 0
  @total = @result['sync_total'].to_i
  each_in_array('sync') do |item|
    item, time = item['item'], item['time']
    next if @syncitems.has_key? item
    @fetched += 1
    lasttime = time if lasttime.nil? or time > lasttime
    @syncitems[item] = time
  end
  lasttime
end