lib/google-simple-client/session.rb in google-simple-client-0.1.1 vs lib/google-simple-client/session.rb in google-simple-client-0.1.2

- old
+ new

@@ -7,10 +7,19 @@ module GoogleSimpleClient class Session OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive.readonly' REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' + # Create the object and parse options + # @param [options] + # Required options are: + # :client_id, :client_secret, :email, and :password + # Optional options are: + # :redirect_uri, :scope, and :verbose + # + # Options may be provided as paramters or via an init file + # ./.google-simple-client or ~/.google-simple-client def initialize options = {} @options = { redirect_uri: REDIRECT_URI, scope: OAUTH_SCOPE, client_id: nil, @@ -23,18 +32,22 @@ @options.merge!(options) @verbose = @options.delete(:verbose) raise Error.new("Missing option error #{@options.inspect}") unless @options.values.all? end + # Authenticates with Google Drive def authenticate init_client uri = @client.authorization.authorization_uri code = scrape_web_and_return_code(uri) @client.authorization.code = code @client.authorization.fetch_access_token! @drive = @client.discovered_api('drive', 'v2') end + # Gets the files matching the title in the requested format + # @param [title] The name of the requested document + # @param [format] The format, available formats are: 'pdf', 'html', 'csv', etc. def get(title, format) files = find_files(title) return "No files found for title #{title}" if files.empty? if format files.map { |f| download_file(f, format) }