Class: Datapimp::Sync::DropboxFolder

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/datapimp/sync/dropbox_folder.rb

Instance Method Summary collapse

Instance Method Details

#cursorObject

The Dropbox Delta API uses a cursor to keep track of the last state the local filesystem has synced with. We store this in the syncable folder itself



23
24
25
# File 'lib/datapimp/sync/dropbox_folder.rb', line 23

def cursor
  cursor_path.exist? && cursor_path.read
end

#cursor_pathObject



27
28
29
# File 'lib/datapimp/sync/dropbox_folder.rb', line 27

def cursor_path
  local_path.join('.dropbox-cursor')
end

#deltaObject

Provides access to the Dropbox API Delta which will tell us how to modify the state of ‘local_path` to match what exists on Dropbox.



11
12
13
# File 'lib/datapimp/sync/dropbox_folder.rb', line 11

def delta
  @delta ||= dropbox.delta(cursor, remote_path)
end

#dropboxObject

Provides easy access to the Dropbox client



4
5
6
# File 'lib/datapimp/sync/dropbox_folder.rb', line 4

def dropbox
  @dropbox ||= Datapimp::Sync.dropbox
end

#ensure_remote_folder_existsObject



67
68
# File 'lib/datapimp/sync/dropbox_folder.rb', line 67

def ensure_remote_folder_exists
end

#local_pathObject

A Pointer to the local path we will be syncing with the Dropbox remote



16
17
18
# File 'lib/datapimp/sync/dropbox_folder.rb', line 16

def local_path
  Pathname(local)
end

#remote_pathObject



31
32
33
34
35
# File 'lib/datapimp/sync/dropbox_folder.rb', line 31

def remote_path
  dropbox.ls(remote)
rescue(Dropbox::API::Error::NotFound)
  nil
end

#remote_path_missing?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/datapimp/sync/dropbox_folder.rb', line 44

def remote_path_missing?
  remote_path.nil?
end

#remote_path_parentObject



37
38
39
40
41
42
# File 'lib/datapimp/sync/dropbox_folder.rb', line 37

def remote_path_parent
  parent, _ = File.split(remote)
  dropbox.ls(parent)
rescue(Dropbox::API::Error::NotFound)
  nil
end

#run(action, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/datapimp/sync/dropbox_folder.rb', line 48

def run(action, options={})
  action = action.to_sym

  if action == :push
    if remote_path_missing?
      dropbox.mkdir(remote)
    end

    Dir[local_path.join("**/*")].each do |f|
      # Upload the file
      binding.pry
    end

  elsif action == :pull
    # TODO
    # Implement the Delta call
  end
end