Class: Gslide::Models::Spreadsheet
- Includes:
- Concerns::Requests
- Defined in:
- lib/gslide/models/spreadsheet.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#batch_update(options = {}) ⇒ Object
True when update successful.
-
#get ⇒ Hash
Data from a Google Sheets spreadsheet.
- #get_sheets ⇒ Object
-
#initialize(id, auth: nil) ⇒ Spreadsheet
constructor
A new instance of Spreadsheet.
- #link_url ⇒ Object
Methods included from Concerns::Requests
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
#id ⇒ Object (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.
31 32 33 34 35 36 37 |
# File 'lib/gslide/models/spreadsheet.rb', line 31 def batch_update( = {}) uri = URI(GOOGLE_SHEETS + "/#{@id}:batchUpdate") request_body = .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 |
#get ⇒ Hash
Returns data from a Google Sheets spreadsheet.
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_sheets ⇒ Object
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 |
#link_url ⇒ Object
24 25 26 |
# File 'lib/gslide/models/spreadsheet.rb', line 24 def link_url "https://docs.google.com/spreadsheets/d/#{@id}/edit" end |