Class: Dropbox::Event

Inherits:
Object show all
Defined in:
lib/dropbox/event.rb

Overview

The Dropbox::Event class stores information about which entries were modified during a pingback event. You initialize this class from the JSON string given to you by Dropbox during a pingback:

event = Dropbox::Event.new(params[:target_events])

Once this is complete, the Dropbox::Event instance contains references for each of the entries, with the basic information included in the pingback:

event.user_ids #=> [ 1, 2, 3 ]
event.entries(1).first #=> #<Dropbox::Revision 1:10:100>

For any of these entries, you can load its content and metadata:

event.entries(1).first.load(dropbox_session)
event.entries(1).first.content #=> "Content of file..."
event.entries(1).first.size #=> 2245

You can also load only the metadata for all of a user’s entries:

event.(first_users_dropbox_session)
event.entries(1).first.size #=> 154365

Instance Method Summary collapse

Constructor Details

#initialize(json_pingback) ⇒ Event

:nodoc:



31
32
33
34
35
36
37
38
39
40
# File 'lib/dropbox/event.rb', line 31

def initialize(json_pingback) # :nodoc:
  @json_pingback = json_pingback
  begin
    @metadata = JSON.parse(json_pingback).stringify_keys_recursively
  rescue JSON::ParserError
    raise Dropbox::ParseError, "Invalid pingback event data"
  end

  process_pingback
end

Instance Method Details

#entries(user_id = nil) ⇒ Object

When given no arguments, returns an array of all entries (as Dropbox::Revision instances). When given a user ID, filters the list to only entries belonging to that Dropbox user.



52
53
54
# File 'lib/dropbox/event.rb', line 52

def entries(user_id=nil)
  user_id ? (@entries_by_user_id[user_id.to_i] || []).dup : @entries.dup
end

#inspectObject

:nodoc:



72
73
74
# File 'lib/dropbox/event.rb', line 72

def inspect # :nodoc:
  "#<#{self.class.to_s} (#{@entries.size} entries)>"
end

#load_metadata(session, options = {}) ⇒ Object

Loads the metadata for all entries belonging to a given Dropbox session. Does not load data for files that do not belong to the user owning the given Dropbox session.

Future calls to this method will result in additional network requests, though the Dropbox::Revision instances do cache their metadata values.

Options:

mode

Temporarily changes the API mode. See the Dropbox::API::MODES array.



68
69
70
# File 'lib/dropbox/event.rb', line 68

def (session, options={})
   session.(@json_pingback, options).stringify_keys_recursively
end

#user_idsObject

Returns an array of Dropbox user ID’s involved in this pingback.



44
45
46
# File 'lib/dropbox/event.rb', line 44

def user_ids
  @entries_by_user_id.keys
end