Object
DropboxSession is responsible for holding OAuth information. It knows how to take your consumer key and secret and request an access token, an authorize url, and get an access token. You just need to pass it to DropboxClient after its been authorized.
Takes a serialized DropboxSession YAML String and returns a new DropboxSession object
# File lib/dropbox_sdk.rb, line 234 def self.deserialize(ser) ser = YAML::load(ser) session = DropboxSession.new(ser.pop, ser.pop) session.set_request_token(ser.pop, ser.pop) if ser.length > 0 session.set_access_token(ser.pop, ser.pop) end session end
consumer_key - Your Dropbox application's "app key".
consumer_secret - Your Dropbox application's "app secret".
# File lib/dropbox_sdk.rb, line 26 def initialize(consumer_key, consumer_secret) @consumer_key = consumer_key @consumer_secret = consumer_secret @request_token = nil @access_token = nil end
Returns the access token, or nil if one hasn't been acquired yet.
# File lib/dropbox_sdk.rb, line 171 def access_token @access_token end
Clears the access_token
# File lib/dropbox_sdk.rb, line 161 def clear_access_token @access_token = nil end
# File lib/dropbox_sdk.rb, line 85 def do_http_with_body(uri, request, body) if body != nil if body.is_a?(Hash) form_data = {} body.each {|k,v| form_data[k.to_s] = v if !v.nil?} request.set_form_data(form_data) elsif body.respond_to?(:read) if body.respond_to?(:length) request["Content-Length"] = body.length.to_s elsif body.respond_to?(:stat) && body.stat.respond_to?(:size) request["Content-Length"] = body.stat.size.to_s else raise ArgumentError, "Don't know how to handle 'body' (responds to 'read' but not to 'length' or 'stat.size')." end request.body_stream = body else s = body.to_s request["Content-Length"] = s.length request.body = s end end do_http(uri, @access_token, request) end
Returns the access token. If this DropboxSession doesn't yet have an access_token, it requests one using the request_token generate from your app's token and secret. This request will fail unless your user has gone to the authorize_url and approved your request
# File lib/dropbox_sdk.rb, line 192 def get_access_token return @access_token if authorized? if @request_token.nil? raise DropboxAuthError.new("No request token. You must set this or get an authorize url first.") end @access_token = get_token("/access_token", @request_token, "Couldn't get access token.") end
This returns a request token. Requests one from the dropbox server using the provided application key and secret if nessecary.
# File lib/dropbox_sdk.rb, line 140 def get_request_token() @request_token ||= get_token("/request_token", nil, "Error getting request token. Is your app key and secret correctly set?") end
Returns the request token, or nil if one hasn't been acquired yet.
# File lib/dropbox_sdk.rb, line 166 def request_token @request_token end
serialize the DropboxSession. At DropboxSession's state is capture in three key/secret pairs. Consumer, request, and access. Serialize returns these in a YAML string, generated from a converted array of the form:
access_token is only included if it already exists in the DropboxSesssion
# File lib/dropbox_sdk.rb, line 219 def serialize toreturn = [] if @access_token toreturn.push @access_token.secret, @access_token.key end get_request_token toreturn.push @request_token.secret, @request_token.key toreturn.push @consumer_secret, @consumer_key toreturn.to_yaml end
Given a saved access token and secret, you set this Session to use that token and secret
token - this is the access token
secret - this is the access token secret
# File lib/dropbox_sdk.rb, line 185 def set_access_token(key, secret) @access_token = OAuthToken.new(key, secret) end
Given a saved request token and secret, set this location's token and secret
token - this is the request token
secret - this is the request token secret
# File lib/dropbox_sdk.rb, line 178 def set_request_token(key, secret) @request_token = OAuthToken.new(key, secret) end
Generated with the Darkfish Rdoc Generator 2.