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

Returns a new instance of Session.



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

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



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

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

Instance Method Details

#accountObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/dummy_dropbox.rb', line 129

def 
  response = <<-RESPONSE
  {
      "country": "",
      "display_name": "John Q. User",
      "email": "[email protected]",
      "quota_info": {
          "shared": 37378890,
          "quota": 62277025792,
          "normal": 263758550
      },
      "uid": "174"
  }
  RESPONSE
  
  return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
end

#authorize(options = {}) ⇒ Object



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

def authorize(options={})
  return true
end

#authorize_url(*args) ⇒ Object



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

def authorize_url(*args)
  return 'https://www.dropbox.com/0/oauth/authorize'
end

#authorized?Boolean

Returns:

  • (Boolean)


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

def authorized?
  return true
end

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



63
64
65
66
67
# File 'lib/dummy_dropbox.rb', line 63

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

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



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

def delete(path, options={})
  FileUtils.rm_rf( "#{Dropbox.files_root_path}/#{path}" )
  
  return true
end

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

API methods



53
54
55
# File 'lib/dummy_dropbox.rb', line 53

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

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/dummy_dropbox.rb', line 104

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dummy_dropbox.rb', line 87

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

#serializeObject



41
42
43
# File 'lib/dummy_dropbox.rb', line 41

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dummy_dropbox.rb', line 71

def upload(local_file_path, remote_folder_path, options={})
  if(local_file_path.kind_of? StringIO)
    local_file = Tempfile.new("dummy_dropbox_#{Time.now.to_i}") do |f|
      f.write local_file_path.to_s
    end
    local_file_path = local_file.path
    FileUtils.cp( local_file_path, "#{Dropbox.files_root_path}/#{remote_folder_path}/#{options[:as]}" )
    outfile = "#{remote_folder_path}/#{options[:as]}"
  else
    FileUtils.cp( local_file_path, "#{Dropbox.files_root_path}/#{remote_folder_path}/" )
    outfile = "#{remote_folder_path}/#{File.basename(local_file_path)}"
  end
  
  return self.( outfile )
end