class Memot::Dropbox
Public Class Methods
auth(app_key, app_secret)
click to toggle source
# File lib/memot/dropbox.rb, line 6 def auth(app_key, app_secret) flow = DropboxOAuth2FlowNoRedirect.new(app_key, app_secret) puts "Access to this URL: #{flow.start}" print "PIN code: " code = gets.strip flow.finish(code) end
new(access_token, redis)
click to toggle source
# File lib/memot/dropbox.rb, line 15 def initialize(access_token, redis) @client = DropboxClient.new(access_token) @redis = redis end
Public Instance Methods
file_body_of(path)
click to toggle source
# File lib/memot/dropbox.rb, line 43 def file_body_of(path) client.get_file(path) end
parse_dir_tree!(path)
click to toggle source
# File lib/memot/dropbox.rb, line 20 def parse_dir_tree!(path) latest_revision = get_revision(path) updated_revision = latest_revision need_update = [] client.metadata(path)["contents"].sort_by { |cont| cont["revision"] }.each do |cont| cont_path = cont["path"] cont_revision = cont["revision"] unless cont["is_dir"] if (cont_revision > latest_revision) && markdown?(cont_path) need_update << { dropbox_path: cont_path, revision: cont_revision } updated_revision = cont_revision end end end set_revision(path, updated_revision) if updated_revision > latest_revision need_update end
Private Instance Methods
client()
click to toggle source
# File lib/memot/dropbox.rb, line 49 def client @client end
dir_key_of(dir)
click to toggle source
# File lib/memot/dropbox.rb, line 61 def dir_key_of(dir) "memot:#{dir}" end
get_revision(dir)
click to toggle source
# File lib/memot/dropbox.rb, line 65 def get_revision(dir) key = dir_key_of(dir) if redis.exists(key) redis.get(key).to_i else set_revision(key, 0) 0 end end
markdown?(path)
click to toggle source
# File lib/memot/dropbox.rb, line 57 def markdown?(path) %w{.md .markdown}.include?(File.extname(path).downcase) end
redis()
click to toggle source
# File lib/memot/dropbox.rb, line 53 def redis @redis end
set_revision(dir, revision)
click to toggle source
# File lib/memot/dropbox.rb, line 76 def set_revision(dir, revision) key = dir_key_of(dir) redis.set(key, revision) end