Class: Datapimp::Sync::GoogleDriveFolder

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

Instance Method Summary collapse

Instance Method Details

#apiObject



3
4
5
# File 'lib/datapimp/sync/google_drive_folder.rb', line 3

def api
  @api ||= Datapimp::Sync.google.api
end

#drawingsObject



15
16
17
# File 'lib/datapimp/sync/google_drive_folder.rb', line 15

def drawings
  remote_path.files.select {|file| file.mime_type == "application/vnd.google-apps.drawing" }
end

#local_pathObject



7
8
9
# File 'lib/datapimp/sync/google_drive_folder.rb', line 7

def local_path
  Pathname(local)
end

#remote_pathObject



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

def remote_path
  api.collection_by_title(remote)
end

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/datapimp/sync/google_drive_folder.rb', line 19

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

  if action == :push

  elsif action == :pull

  elsif action == :svgs
    drawings.each do |drawing|
      filename = drawing.title.parameterize + '.svg'
      local_file = local_path.join(filename)

      if local_file.exist? && !options[:overwrite]
        puts "== #{ filename } already exists. skipping. pass --overwrite to overwrite"
      else
        puts "== Downloading to svg: #{ filename }"
        drawing.export_as_file(local_path.join(filename), 'image/svg+xml')
      end
    end
  end
end