Class: UptimeReportsSpreadsheet::Spreadsheet

Inherits:
Object
  • Object
show all
Defined in:
lib/uptime_reports_spreadsheet/spreadsheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scopes = [1,4]) ⇒ Spreadsheet

Returns a new instance of Spreadsheet.



10
11
12
13
14
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 10

def initialize scopes=[1,4]
  @auth=UptimeReportsSpreadsheet::Auth.new scopes
  @service=auth.service

end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



8
9
10
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 8

def auth
  @auth
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 8

def response
  @response
end

#serviceObject

Returns the value of attribute service.



8
9
10
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 8

def service
  @service
end

#spreadsheetObject

Returns the value of attribute spreadsheet.



8
9
10
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 8

def spreadsheet
  @spreadsheet
end

Instance Method Details

#createObject



25
26
27
28
29
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 25

def create
  service.authorization = auth.authorize
  request_body = Google::Apis::SheetsV4::Spreadsheet.new
  @spreadsheet = service.create_spreadsheet(request_body)
end

#deleteObject



39
40
41
42
43
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 39

def delete
  service = Google::Apis::DriveV3::DriveService.new
  service.authorization = auth.authorize
  service.delete_file spreadsheet.spreadsheet_id
end

#sampleObject



16
17
18
19
20
21
22
23
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 16

def sample
  service.authorization = auth.authorize

  spreadsheet_id = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'
  range = 'Class Data!A2:E'
  response = service.get_spreadsheet_values(spreadsheet_id, range)
  response.values
end

#set_title(title) ⇒ Object



31
32
33
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 31

def set_title title
  spreadsheet.properties.update!(title: title)
end

#titleObject



35
36
37
# File 'lib/uptime_reports_spreadsheet/spreadsheet.rb', line 35

def title
  spreadsheet.properties.title
end