Class: Readiness::GoogleSheets::Client

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

Overview

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

Author:

  • Jason Colyer

Since:

  • 1.0.39

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Readiness::GoogleSheets::Configuration.new) ⇒ Client

Creates a new Readiness::GoogleSheets::Client instance

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
client = Readiness::GoogleSheets::Client.new(config)
pp client.spreadsheet_id
# => "abc123"

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.39



30
31
32
33
# File 'lib/support_readiness/google_sheets/client.rb', line 30

def initialize(config = Readiness::GoogleSheets::Configuration.new)
  @service = generate_service(config)
  @spreadsheet_id = config.spreadsheet_id
end

Instance Attribute Details

#serviceObject

Since:

  • 1.0.39



14
15
16
# File 'lib/support_readiness/google_sheets/client.rb', line 14

def service
  @service
end

#spreadsheet_idObject

Since:

  • 1.0.39



14
15
16
# File 'lib/support_readiness/google_sheets/client.rb', line 14

def spreadsheet_id
  @spreadsheet_id
end

Instance Method Details

#generate_service(config) ⇒ Object

Generates a service connection to Google Calendar

Examples:

require 'support_readiness'
config = Readiness::GoogleSheets::Configuration.new
config.spreadsheet_id = 'abc123'
config.filepath = 'data/config.json'
service = Readiness::GoogleSheets::Client.generate_service(config)

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.39



47
48
49
50
51
52
53
54
55
56
# File 'lib/support_readiness/google_sheets/client.rb', line 47

def generate_service(config)
  authorize = Google::Auth::ServiceAccountCredentials.make_creds(
    json_key_io: File.open(config.filepath),
    scope: config.scope
  )
  authorize.fetch_access_token!
  service = Google::Apis::SheetsV4::SheetsService.new
  service.authorization = authorize
  service
end