Class: SheetsDB::Session
- Inherits:
-
Object
show all
- Defined in:
- lib/sheets_db/session.rb
Defined Under Namespace
Classes: GoogleDriveIdNotFoundError, IllegalDefaultError, InvalidGoogleDriveUrlError, NoDefaultSetError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(google_drive_session) ⇒ Session
Returns a new instance of Session.
28
29
30
|
# File 'lib/sheets_db/session.rb', line 28
def initialize(google_drive_session)
@google_drive_session = google_drive_session
end
|
Class Method Details
.default ⇒ Object
17
18
19
20
21
22
|
# File 'lib/sheets_db/session.rb', line 17
def self.default
unless @default
raise NoDefaultSetError.new("No default Session defined yet")
end
@default
end
|
.default=(default) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/sheets_db/session.rb', line 10
def self.default=(default)
unless default.is_a?(self)
raise IllegalDefaultError.new("Default must be a SheetsDB::Session")
end
@default = default
end
|
.from_service_account_key(*args) ⇒ Object
24
25
26
|
# File 'lib/sheets_db/session.rb', line 24
def self.from_service_account_key(*args)
new(GoogleDrive::Session.from_service_account_key(*args))
end
|
Instance Method Details
#raw_file_by_id(id) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/sheets_db/session.rb', line 32
def raw_file_by_id(id)
@google_drive_session.file_by_id(id)
rescue Google::Apis::ClientError => e
(raise GoogleDriveIdNotFoundError, id) if e.message.match(/File not found/)
raise
end
|
#raw_file_by_url(url) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/sheets_db/session.rb', line 39
def raw_file_by_url(url)
@google_drive_session.file_by_url(url)
rescue GoogleDrive::Error => e
(raise InvalidGoogleDriveUrlError, url) if e.message.match(/not a known Google Drive URL/)
raise
end
|