Class: MotionVj::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_vj/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, videos_dir) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/motion_vj/client.rb', line 7

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

Instance Attribute Details

#db_clientObject (readonly)

Returns the value of attribute db_client.



5
6
7
# File 'lib/motion_vj/client.rb', line 5

def db_client
  @db_client
end

#videos_dirObject (readonly)

Returns the value of attribute videos_dir.



5
6
7
# File 'lib/motion_vj/client.rb', line 5

def videos_dir
  @videos_dir
end

Class Method Details

.get_token(app_key, app_secret) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#file_exist?(filename) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/motion_vj/client.rb', line 12

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

#upload(filepath) ⇒ Object



21
22
23
24
25
26
# File 'lib/motion_vj/client.rb', line 21

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