Class: Quiver::Adapter::Dropbox

Inherits:
Object
  • Object
show all
Defined in:
lib/quiver/adapter/dropbox.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, access_key) ⇒ Dropbox

Returns a new instance of Dropbox.



8
9
10
11
# File 'lib/quiver/adapter/dropbox.rb', line 8

def initialize(root, access_key)
  @root = root
  @access_key = access_key
end

Instance Method Details

#clientObject



12
13
14
# File 'lib/quiver/adapter/dropbox.rb', line 12

def client
  @client ||= ::DropboxApi::Client.new(@access_key)
end

#each(path) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/quiver/adapter/dropbox.rb', line 21

def each(path)
   = client.(normalize_path(path))
  ['contents'].each do |content|
    next unless content['is_dir']
    yield Pathname.new(content['path'])
  end
end

#image_url(path) ⇒ Object

Don’t include this url direct on your site. Use via cdn.



17
18
19
20
# File 'lib/quiver/adapter/dropbox.rb', line 17

def image_url(path)
  @@image_url_cache ||= {}
  @@image_url_cache[path] ||= client.get_temporary_link(normalize_path(path)).link
end

#load(path) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/quiver/adapter/dropbox.rb', line 28

def load(path)
  content = nil
  meta = client.download(normalize_path(path)) do |con|
    content = con
  end
  [content, meta]
end

#save(path, content) ⇒ Object



35
36
37
# File 'lib/quiver/adapter/dropbox.rb', line 35

def save(path, content)
  client.upload normalize_path(path), content
end