class LiveJournal::Request::GetEvents
Public Class Methods
We support three different types of GetEvents:
-
GetEvents.new(user, :itemid => itemid)
(fetch a single item) -
GetEvents.new(user, :recent => n)
(fetch most recent n itemds) -
GetEvents.new(user, :lastsync => lastsync)
(for syncing)
We support one final option called :strict
, which requires a bit of explanation.
Whenever LiveJournal
adds new metadata to entries (such as the location field, which was introduced in 2006) it also exposes this metadata via the LJ protocol. However, ljrb can't know about future metadata and doesn't know how to handle it properly. Some metadata (like the current location) must be sent to the server to publish an entry correctly; others, like the last revision time, must not be.
Normally, when we see a new property we abort with a ProtocolException
. If the object is constructed with :strict => false
, we'll skip over any new properties.
# File lib/livejournal/entry.rb, line 312 def initialize(user, opts) super(user, 'getevents') @request['lineendings'] = 'unix' @strict = false @strict = opts[:strict] if opts.has_key? :strict if opts.has_key? :itemid @request['selecttype'] = 'one' @request['itemid'] = opts[:itemid] elsif opts.has_key? :recent @request['selecttype'] = 'lastn' @request['howmany'] = opts[:recent] elsif opts.has_key? :lastsync @request['selecttype'] = 'syncitems' @request['lastsync'] = opts[:lastsync] if opts[:lastsync] else raise ArgumentError, 'invalid options for GetEvents' end end
Public Instance Methods
Returns either a single #Entry or a hash of itemid => #Entry, depending on the mode this was constructed with.
# File lib/livejournal/entry.rb, line 335 def run super entries = {} each_in_array('events') do |req| entry = Entry.new.from_request(req) entries[entry.itemid] = entry end each_in_array('prop') do |prop| itemid = prop['itemid'].to_i entries[itemid].load_prop(prop['name'], prop['value'], @strict) end if @request.has_key? 'itemid' return entries[@request['itemid']] else return entries end end