Class: GoogleSimpleClient::Session
- Inherits:
-
Object
- Object
- GoogleSimpleClient::Session
- Defined in:
- lib/google-simple-client/session.rb
Constant Summary collapse
- OAUTH_SCOPE =
'https://www.googleapis.com/auth/drive.readonly'
- REDIRECT_URI =
'urn:ietf:wg:oauth:2.0:oob'
Instance Method Summary collapse
-
#authenticate ⇒ Object
Authenticates with Google Drive.
-
#get(title, format) ⇒ Object
Gets the files matching the title in the requested format.
-
#initialize(options = {}) ⇒ Session
constructor
Create the object and parse options Options may be provided as paramters or via an init file ./.google-simple-client or ~/.google-simple-client.
Constructor Details
#initialize(options = {}) ⇒ Session
Create the object and parse options Options may be provided as paramters or via an init file
./.google-simple-client or ~/.google-simple-client
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/google-simple-client/session.rb', line 21 def initialize = {} @options = { redirect_uri: REDIRECT_URI, scope: OAUTH_SCOPE, client_id: nil, client_secret: nil, email: nil, password: nil } = @options.merge!() @options.merge!() @verbose = @options.delete(:verbose) raise Error.new("Missing option error #{@options.inspect}") unless @options.values.all? end |
Instance Method Details
#authenticate ⇒ Object
Authenticates with Google Drive
38 39 40 41 42 43 44 45 |
# File 'lib/google-simple-client/session.rb', line 38 def authenticate init_client uri = @client.. code = scrape_web_and_return_code(uri) @client..code = code @client..fetch_access_token! @drive = @client.discovered_api('drive', 'v2') end |
#get(title, format) ⇒ Object
Gets the files matching the title in the requested format
50 51 52 53 54 55 56 57 58 |
# File 'lib/google-simple-client/session.rb', line 50 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) } else files.map { |f| f.title } end end |