Class: GoogleSpreadsheetFetcher::Fetcher
- Inherits:
-
Object
- Object
- GoogleSpreadsheetFetcher::Fetcher
- Defined in:
- lib/google_spreadsheet_fetcher/fetcher.rb
Constant Summary collapse
- OOB_URI =
'urn:ietf:wg:oauth:2.0:oob'
Instance Method Summary collapse
- #fetch_all_rows(range, skip: 0) ⇒ Object
- #fetch_all_rows_by!(index: nil, sheet_id: nil, title: nil, skip: 0) ⇒ Object
-
#initialize(spreadsheet_id, user_id, config: nil, application_name: nil) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #service ⇒ Object
Constructor Details
#initialize(spreadsheet_id, user_id, config: nil, application_name: nil) ⇒ Fetcher
Returns a new instance of Fetcher.
14 15 16 17 18 19 |
# File 'lib/google_spreadsheet_fetcher/fetcher.rb', line 14 def initialize(spreadsheet_id, user_id, config: nil, application_name: nil) @spreadsheet_id = spreadsheet_id @user_id = user_id @config = config || GoogleSpreadsheetFetcher.config @application_name = application_name end |
Instance Method Details
#fetch_all_rows(range, skip: 0) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/google_spreadsheet_fetcher/fetcher.rb', line 23 def fetch_all_rows(range, skip: 0) rows = service.batch_get_spreadsheet_values(@spreadsheet_id, ranges: [range])&.value_ranges&.first&.values return [] if rows.blank? rows.slice!(0, skip) rows end |
#fetch_all_rows_by!(index: nil, sheet_id: nil, title: nil, skip: 0) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/google_spreadsheet_fetcher/fetcher.rb', line 31 def fetch_all_rows_by!(index: nil, sheet_id: nil, title: nil, skip: 0) sheet = fetch_sheet_by!(index: index, sheet_id: sheet_id, title: title) range = "#{sheet.properties.title}!A:Z" fetch_all_rows(range, skip: skip) end |
#service ⇒ Object
38 39 40 41 42 43 |
# File 'lib/google_spreadsheet_fetcher/fetcher.rb', line 38 def service @service ||= Google::Apis::SheetsV4::SheetsService.new.tap do |service| service. = fetch_credentials service..application_name = @application_name if @application_name.present? end end |