Skip to content

Instantly share code, notes, and snippets.

@tylr
Created August 25, 2010 15:19
Show Gist options
  • Save tylr/549692 to your computer and use it in GitHub Desktop.
Save tylr/549692 to your computer and use it in GitHub Desktop.
module API
def self.has_access?(token)
network = const_get token.for
network.has_access? token.key, token.secret
end
def display_files(files, token)
network = const_get token.for
network.display_files files, token.key, token.secret
end
module Dropbox
def self.key
'asdasd'
end
def self.secret
'asdasd'
end
def self.version
0
end
def self.oauth=(val)
@oauth = val
end
def self.oauth
return @oauth if @oauth
@oauth = OauthUtil.new
@oauth.consumer_key = key
@oauth.consumer_secret = secret
@oauth
end
def self.account_info(token, secret)
url = request_url(:path => '/account/info',
:token => token,
:secret => secret)
get(url)
end
def self.ls(path, token, secret)
url = request_url(:path => "/metadata/dropbox#{path}",
:token => token,
:secret => secret)
get(url)
end
def self.thumbnail(path, token, secret)
url = request_url(:path => "/thumbnails/dropbox#{path}",
:token => token,
:secret => secret,
:host => 'api-content.dropbox.com',
:query => {'size' => 'large'})
end
def self.request_url(opts)
options = {
:path => '/',
:version => 0,
:host => 'api.dropbox.com',
:method => :get,
:token => '',
:secret => '',
:query => {} }
options.merge!(opts)
oauth.token = options[:token]
oauth.token_secret = options[:secret]
query = options[:query].collect{|k,v| "#{k}=#{v}" }.join('&')
uri = URI::HTTP.build(:scheme => 'http',
:host => options[:host],
:path => "/#{options[:version]}#{options[:path]}",
:query => query)
oauth_uri = oauth.sign(uri)
p "#{uri.scheme}://#{uri.host}#{uri.path}?#{oauth.sign(uri).query_string}"
"#{uri.scheme}://#{uri.host}#{uri.path}?#{oauth.sign(uri).query_string}"
end
def self.get(url)
response = Typhoeus::Request.get(url)
Yajl::Parser.parse(response.body)
end
def self.post(url)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment