class MotionVj::Client
Attributes
db_client[R]
videos_dir[R]
Public Class Methods
get_token(app_key, app_secret)
click to toggle source
# File lib/motion_vj/client.rb, line 28 def self.get_token(app_key, app_secret) flow = DropboxOAuth2FlowNoRedirect.new(app_key, app_secret) authorize_url = flow.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: ' code = MotionVj::Helpers::Input.gets_until_not_blank(:code) flow.finish(code).first end
new(token, videos_dir)
click to toggle source
# File lib/motion_vj/client.rb, line 7 def initialize(token, videos_dir) @db_client = DropboxClient.new(token) @videos_dir = videos_dir end
Public Instance Methods
file_exist?(filename)
click to toggle source
# File lib/motion_vj/client.rb, line 12 def file_exist?(filename) begin metadata = self.db_client.metadata(File.join(self.videos_dir, filename)) metadata && !metadata['is_dir'] && metadata['bytes'] && metadata['bytes'] > 0 rescue DropboxError => e false end end
upload(filepath)
click to toggle source
# File lib/motion_vj/client.rb, line 21 def upload(filepath) open(filepath) do |file| metadata = self.db_client.put_file(File.join(self.videos_dir, File.basename(filepath)), file, true) metadata && !metadata['is_dir'] && metadata['bytes'] && metadata['bytes'] > 0 end end