module Noteman::Dropbox
Constants
- APP_KEY
- APP_SECRET
Public Instance Methods
load_state()
click to toggle source
# File lib/noteman/state.rb, line 9 def load_state if File.exist? state_file state = JSON.parse(File.read(state_file), :max_nesting => false) state['tree'] = Node.from_json_content(state['tree']) else state = { 'tree' => {} } save_state state end state end
map_hash_values(h) { |v| ... }
click to toggle source
Run a mapping function over every value in a Hash, returning a new Hash.
# File lib/noteman/state.rb, line 67 def map_hash_values(h) new = {} h.each { |k,v| new[k] = yield v } new end
save_state(state)
click to toggle source
# File lib/noteman/state.rb, line 23 def save_state(state) state['tree'] = Node.to_json_content(state['tree']) File.open(state_file,"w") do |f| f.write(JSON.pretty_generate(state, :max_nesting => false)) end end
state_file()
click to toggle source
# File lib/noteman/state.rb, line 5 def state_file File.join File.expand_path(config['home']), config['state_file'] end
sync()
click to toggle source
# File lib/noteman/dropbox.rb, line 11 def sync state = load_state # auth if not state['access_token'] web_auth = DropboxOAuth2FlowNoRedirect.new(APP_KEY, APP_SECRET) authorize_url = web_auth.start() puts "1. Go to: #{authorize_url}" puts "2. Click \"Allow\" (you might have to log in first)." puts "3. Copy the authorization code." print "Enter the authorization code here: " STDOUT.flush auth_code = STDIN.gets.strip access_token, user_id = web_auth.finish(auth_code) puts "Link successful." state['access_token'] = access_token end cursor = state['cursor'] access_token = state['access_token'] c = DropboxClient.new(access_token) result = c.delta cursor, config['dropbox_path'] pp result #save_state state end