Class: Dropbox::Session

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_key, oauth_secret, options = {}) ⇒ Session



15
16
17
18
19
# File 'lib/dummy_dropbox.rb', line 15

def initialize(oauth_key, oauth_secret, options={})
  @ssl = false
  @consumer = OpenStruct.new( :key => "dummy key consumer" )
  @request_token = "dummy request token"
end

Class Method Details

.deserialize(data) ⇒ Object



37
38
39
# File 'lib/dummy_dropbox.rb', line 37

def self.deserialize(data)
  return Dropbox::Session.new( 'dummy_key', 'dummy_secret' )
end

Instance Method Details

#accountObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/dummy_dropbox.rb', line 104

def 
  response = "  {\n      \"country\": \"\",\n      \"display_name\": \"John Q. User\",\n      \"quota_info\": {\n          \"shared\": 37378890,\n          \"quota\": 62277025792,\n          \"normal\": 263758550\n      },\n      \"uid\": \"174\"\n  }\n  RESPONSE\n  \n  return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively\nend\n"

#authorize(options = {}) ⇒ Object



25
26
27
# File 'lib/dummy_dropbox.rb', line 25

def authorize(options={})
  return true
end

#authorize_url(*args) ⇒ Object



21
22
23
# File 'lib/dummy_dropbox.rb', line 21

def authorize_url(*args)
  return 'dummy url'
end

#authorized?Boolean



29
30
31
# File 'lib/dummy_dropbox.rb', line 29

def authorized?
  return true
end

#create_folder(path, options = {}) ⇒ Object



49
50
51
52
53
# File 'lib/dummy_dropbox.rb', line 49

def create_folder(path, options={})
  FileUtils.mkdir( "#{Dropbox.files_root_path}/#{path}" )
  
  return self.( path )
end

#download(path, options = {}) ⇒ Object

API methods



45
46
47
# File 'lib/dummy_dropbox.rb', line 45

def download(path, options={})
  File.read( "#{Dropbox.files_root_path}/#{path}" )
end

#list(path, options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dummy_dropbox.rb', line 79

def list(path, options={})
  result = []
  
  Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
    element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
    
    element = 
      OpenStruct.new(
        :icon => 'folder',
        :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
        :path => element_path,
        :thumb_exists => false,
        :modified => Time.parse( '2010-01-01 10:10:10' ),
        :revision => 1,
        :bytes => 0,
        :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
        :size => '0 bytes'
      )
    
    result << element
  end
  
  return result
end

#metadata(path, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dummy_dropbox.rb', line 63

def (path, options={})
  response = "    {\n      \"thumb_exists\": false,\n      \"bytes\": \"\#{File.size( \"\#{Dropbox.files_root_path}/\#{path}\" )}\",\n      \"modified\": \"Tue, 04 Nov 2008 02:52:28 +0000\",\n      \"path\": \"\#{path}\",\n      \"is_dir\": \#{File.directory?( \"\#{Dropbox.files_root_path}/\#{path}\" )},\n      \"size\": \"566.0KB\",\n      \"root\": \"dropbox\",\n      \"icon\": \"page_white_acrobat\"\n    }\n  RESPONSE\n  return parse_metadata(JSON.parse(response).symbolize_keys_recursively).to_struct_recursively\nend\n"

#serializeObject



33
34
35
# File 'lib/dummy_dropbox.rb', line 33

def serialize
  return 'dummy serial'
end

#upload(local_file_path, remote_folder_path, options = {}) ⇒ Object

TODO: the original gem method allow a lot of types for ‘local_path’ parameter this dummy version only allows a file_path



57
58
59
60
61
# File 'lib/dummy_dropbox.rb', line 57

def upload(local_file_path, remote_folder_path, options={})
  FileUtils.cp( local_file_path, "#{Dropbox.files_root_path}/#{remote_folder_path}/" )
  
  return self.( "#{remote_folder_path}/#{File.basename(local_file_path)}" )
end