Class: LiveJournal::Request::EditEvent

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

Instance Method Summary collapse

Methods inherited from Req

#dryrun!, #dumpresponse, #run, #verbose!

Constructor Details

#initialize(user, entry, opts = {}) ⇒ EditEvent

To edit an entry, pass in a #User and an #Entry to this and run it. To delete an entry, pass in :delete => true as the third parameter. (In this case, the Entry object only needs its itemid filled in.)

The LiveJournal API for deletion is to “edit” an entry to have an empty event. To prevent accidentally deleting entries, if you pass in an entry with an empty event without passing the delete flag, this will raise the AccidentalDeleteError exception.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/livejournal/entry.rb', line 368

def initialize(user, entry, opts={})
  super(user, 'editevent')

  @request['itemid'] = entry.itemid
  if opts.has_key? :delete
    @request['event'] = ''
  else
    entry.add_to_request @request
  end

  if @request['event'].nil? or @request['event'].empty?
    raise AccidentalDeleteError unless opts.has_key? :delete
  end
end