Class: Gslide::Models::Spreadsheet

Inherits:
Object
  • Object
show all
Includes:
Concerns::Requests
Defined in:
lib/gslide/models/spreadsheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Requests

#get_request, #post_request

Constructor Details

#initialize(id, auth: nil) ⇒ Spreadsheet

Returns a new instance of Spreadsheet.



10
11
12
13
# File 'lib/gslide/models/spreadsheet.rb', line 10

def initialize(id, auth: nil)
  @id = id
  @auth = auth
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#batch_update(options = {}) ⇒ Object

Returns True when update successful.

Parameters:

  • options (Hash) (defaults to: {})

    the request body.

Returns:

  • True when update successful.

See Also:



31
32
33
34
35
36
37
# File 'lib/gslide/models/spreadsheet.rb', line 31

def batch_update(options = {})
  uri = URI(GOOGLE_SHEETS + "/#{@id}:batchUpdate")
  request_body = options.convert_keys { |k| k.to_s.lower_camel_case }.to_json

  response_body = post_request(uri, auth_token: @auth.token, body: request_body)
  response_body["spreadsheetId"] == @id
end

#getHash

Returns data from a Google Sheets spreadsheet.

Returns:

  • (Hash)

    data from a Google Sheets spreadsheet.

See Also:



17
18
19
20
21
22
# File 'lib/gslide/models/spreadsheet.rb', line 17

def get
  uri = URI(GOOGLE_SHEETS + "/#{@id}")

  response_body = get_request(uri, auth_token: @auth.token)
  response_body.convert_keys {|k| k.snake_case.to_sym }
end

#get_sheetsObject



39
40
41
42
# File 'lib/gslide/models/spreadsheet.rb', line 39

def get_sheets
  parsed_body = get
  parsed_body[:sheets].collect { |h| Sheet.new(h) }
end


24
25
26
# File 'lib/gslide/models/spreadsheet.rb', line 24

def link_url
  "https://docs.google.com/spreadsheets/d/#{@id}/edit"
end