Class: LiveJournal::Sync::Comments

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

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Comments

Returns a new instance of Comments.



135
136
137
138
139
# File 'lib/livejournal/sync.rb', line 135

def initialize(user)
  @user = user
  @session = nil
  @maxid = nil
end

Instance Method Details

#run_body(start = 0) ⇒ Object

:yields: cur, total, comments_hash



173
174
175
176
177
178
179
180
181
182
# File 'lib/livejournal/sync.rb', line 173

def run_body(start=0)  # :yields: cur, total, comments_hash
  while start < @maxid
    data = run_GET('body', start)
    parsed = LiveJournal::Sync::CommentsXML::Parser.new(data)
    break if parsed.comments.empty?
    cur = parsed.comments.keys.max
    yield cur, @maxid, parsed
    start = cur + 1
  end
end

#run_metadata(start = 0) ⇒ Object

:yields: cur, total, comments_hash



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/livejournal/sync.rb', line 161

def (start=0)  # :yields: cur, total, comments_hash
  while @maxid.nil? or start < @maxid
    data = run_GET('meta', start)
    parsed = LiveJournal::Sync::CommentsXML::Parser.new(data)
    @maxid ||= parsed.maxid
    break if parsed.comments.empty?
    cur = parsed.comments.keys.max
    yield cur, @maxid, parsed
    start = cur + 1
  end
end