Created
December 7, 2012 01:23
-
-
Save kenpratt/4229985 to your computer and use it in GitHub Desktop.
Testing a very simple Dropbox API scenario and timing the results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..")) | |
$:.unshift File.join(ROOT_PATH, "vendor", "dropbox-ruby-sdk", "lib") | |
require "dropbox_sdk" | |
require "fileutils" | |
app_key = ENV["DROPBOX_APP_KEY"] | |
app_secret = ENV["DROPBOX_APP_SECRET"] | |
auth_key = ENV["DROPBOX_AUTH_KEY"] | |
auth_secret = ENV["DROPBOX_AUTH_SECRET"] | |
access_type = ENV["DROPBOX_ACCESS_TYPE"] || "dropbox" # "app_folder" | |
session = DropboxSession.new(app_key, app_secret) | |
session.set_access_token(auth_key, auth_secret) | |
client = DropboxClient.new(session, access_type) | |
def print_res(res) | |
puts case res | |
when Hash | |
"(data)" | |
else | |
res.inspect | |
end | |
end | |
start = Time.now | |
path = "/tmp/hello#{rand(1000)}" | |
print "Creating #{path}: " | |
res = client.file_create_folder(path) | |
print_res(res) | |
print "Fetching metadata for #{path}: " | |
res = client.metadata(path) | |
print_res(res) | |
f0path = "#{path}/tmp.rb" | |
print "Uploading #{f0path}: " | |
File.open(__FILE__, "r") {|f| res = client.put_file(f0path, f); print_res(res) } | |
print "Fetching metadata for #{f0path}: " | |
res = client.metadata(path) | |
print_res(res) | |
f1path = "#{path}/tmp.rb" | |
print "Uploading #{f1path}: " | |
File.open(__FILE__, "r") {|f| res = client.put_file(f1path, f); print_res(res) } | |
print "Fetching metadata for #{f1path}: " | |
res = client.metadata(path) | |
print_res(res) | |
f2path = "#{path}/tmp.rb" | |
print "Uploading #{f2path}: " | |
File.open(__FILE__, "r") {|f| res = client.put_file(f2path, f); print_res(res) } | |
print "Fetching metadata for #{f2path}: " | |
res = client.metadata(path) | |
print_res(res) | |
print "Fetching metadata for #{path}: " | |
res = client.metadata(path) | |
print_res(res) | |
finish = Time.now | |
puts "Took #{((finish - start)*1000).round}ms" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment