Class: Readiness::GoogleSheets::Spreadsheets

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/google_sheets/spreadsheets.rb

Overview

Defines the class Spreadsheets within the module Readiness::GoogleSheets.

Author:

  • Jason Colyer

Since:

  • 1.0.39

Class Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Class Method Details

.append_data(client, range, values) ⇒ Object

Appends data to a spreadsheet

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
values = [
  ['Tickets 2024-10', 125],
  ['Agents 2024-10', 150],
  ['SSAT 2024-10', '95%']
]
Readiness::GoogleSheets::Spreadsheets.append_data(client, 'Ticket Data!A1:A3', values)

Parameters:

  • client (Object)

    An instance of Client

  • range (String)

    A Google Sheets range

  • values (Array)

    An Array of Arrays for the values to use

Author:

  • Jason Colyer

Since:

  • 1.0.39



92
93
94
95
# File 'lib/support_readiness/google_sheets/spreadsheets.rb', line 92

def self.append_data(client, range, values)
  value_range = Google::Apis::SheetsV4::ValueRange.new(values: values)
  client.service.append_spreadsheet_value(client.spreadsheet_id, range, value_range, value_input_option: 'RAW')
end

.data(client, range) ⇒ Object

Gets data within a spreadsheet

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
data = Readiness::GoogleSheets::Spreadsheets.data(client, 'A1:A3')
pp data.values.first
# => ["Test 1", "Test 2"]

Parameters:

  • client (Object)

    An instance of Client

  • range (String)

    A Google Sheets range

Author:

  • Jason Colyer

Since:

  • 1.0.39



68
69
70
# File 'lib/support_readiness/google_sheets/spreadsheets.rb', line 68

def self.data(client, range)
  client.service.get_spreadsheet_values(client.spreadsheet_id, range)
end

.get_info(client) ⇒ Object

Gets spreadsheet information

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
spreadsheet = Readiness::GoogleSheets::Spreadsheets.get_info(client)
pp spreadsheet.properties.title
# => "Jason Test"

Parameters:

  • client (Object)

    An instance of Client

Author:

  • Jason Colyer

Since:

  • 1.0.39



29
30
31
# File 'lib/support_readiness/google_sheets/spreadsheets.rb', line 29

def self.get_info(client)
  client.service.get_spreadsheet(client.spreadsheet_id)
end

.sheets(spreadsheet) ⇒ Object

Gets a list of spreadsheet sheets

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
spreadsheet = Readiness::GoogleSheets::Spreadsheets.get_info(client)
pp Readiness::GoogleSheets::Spreadsheets.sheets(spreadsheet)
# => ["Sheet1", "Sheet2"]

Parameters:

  • spreadsheet (Object)

    The spreadsheet to use

Author:

  • Jason Colyer

Since:

  • 1.0.39



48
49
50
# File 'lib/support_readiness/google_sheets/spreadsheets.rb', line 48

def self.sheets(spreadsheet)
  spreadsheet.sheets.map { |s| s.properties.title }
end

.update_data(client, range, values) ⇒ Object

Updates data in a spreadsheet

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
values = [
  ['Tickets 2024-10', 125],
  ['Agents 2024-10', 150],
  ['SSAT 2024-10', '95%']
]
Readiness::GoogleSheets::Spreadsheets.update_data(client, 'Ticket Data!A1:A3', values)

Parameters:

  • client (Object)

    An instance of Client

  • range (String)

    A Google Sheets range

  • values (Array)

    An Array of Arrays for the values to use

Author:

  • Jason Colyer

Since:

  • 1.0.39



117
118
119
120
# File 'lib/support_readiness/google_sheets/spreadsheets.rb', line 117

def self.update_data(client, range, values)
  value_range = Google::Apis::SheetsV4::ValueRange.new(values: values)
  client.service.update_spreadsheet_value(client.spreadsheet_id, range, value_range, value_input_option: 'RAW')
end