Sha256: 762486127a7006ff4c434a7a72ebe2a2ac830cdeb0debaf4d3097d94cab1dd49

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'dropbox_sdk'

module MotionVj
  class Client
    attr_reader :db_client

    def initialize(token)
      @db_client = DropboxClient.new(token)
    end

    def file_exist?(filename)
      begin
        metadata = db_client.metadata(File.join(ENV['DB_VIDEOS_DIR'], filename))
        metadata && !metadata['is_dir'] && metadata['bytes'] && metadata['bytes'] > 0
      rescue DropboxError => e
        false
      end
    end

    def upload(filepath)
      open(filepath) do |file|
        metadata = db_client.put_file(File.join(ENV['DB_VIDEOS_DIR'], File.basename(filepath)), file, true)
        metadata && !metadata['is_dir'] && metadata['bytes'] && metadata['bytes'] > 0
      end
    end

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion_vj-0.1.0 lib/motion_vj/client.rb