Class: Embulk::Input::GoogleSpreadsheets::SpreadsheetsClient
- Inherits:
-
Object
- Object
- Embulk::Input::GoogleSpreadsheets::SpreadsheetsClient
- Defined in:
- lib/embulk/input/google_spreadsheets/spreadsheets_client.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#pager ⇒ Object
Returns the value of attribute pager.
-
#spreadsheets_url ⇒ Object
Returns the value of attribute spreadsheets_url.
-
#worksheet_title ⇒ Object
Returns the value of attribute worksheet_title.
Instance Method Summary collapse
- #application_name ⇒ Object
-
#initialize(task, auth:, pager:) ⇒ SpreadsheetsClient
constructor
A new instance of SpreadsheetsClient.
- #logger ⇒ Object
- #service ⇒ Object
- #spreadsheets ⇒ Object
- #spreadsheets_id ⇒ Object
- #worksheet ⇒ Object
- #worksheet_each_record(&block) ⇒ Object
- #worksheet_grid_properties ⇒ Object
- #worksheet_max_column_num ⇒ Object
- #worksheet_max_row_num ⇒ Object
- #worksheet_properties ⇒ Object
- #worksheet_values(range) ⇒ Object
Constructor Details
#initialize(task, auth:, pager:) ⇒ SpreadsheetsClient
Returns a new instance of SpreadsheetsClient.
12 13 14 15 16 17 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 12 def initialize(task, auth:, pager:) @spreadsheets_url = task['spreadsheets_url'] @worksheet_title = task['worksheet_title'] @auth = auth @pager = pager end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
10 11 12 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 10 def auth @auth end |
#pager ⇒ Object
Returns the value of attribute pager.
10 11 12 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 10 def pager @pager end |
#spreadsheets_url ⇒ Object
Returns the value of attribute spreadsheets_url.
10 11 12 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 10 def spreadsheets_url @spreadsheets_url end |
#worksheet_title ⇒ Object
Returns the value of attribute worksheet_title.
10 11 12 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 10 def worksheet_title @worksheet_title end |
Instance Method Details
#application_name ⇒ Object
23 24 25 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 23 def application_name @application_name ||= 'embulk-input-google_spreadsheets' end |
#logger ⇒ Object
19 20 21 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 19 def logger GoogleSpreadsheets.logger end |
#service ⇒ Object
65 66 67 68 69 70 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 65 def service @service ||= Google::Apis::SheetsV4::SheetsService.new.tap do |s| s..application_name = application_name s. = auth.authenticate end end |
#spreadsheets ⇒ Object
31 32 33 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 31 def spreadsheets service.get_spreadsheet(spreadsheets_id, ranges: worksheet_title, include_grid_data: false) end |
#spreadsheets_id ⇒ Object
27 28 29 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 27 def spreadsheets_id SpreadsheetsUrlUtil.capture_id(spreadsheets_url) end |
#worksheet ⇒ Object
35 36 37 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 35 def worksheet spreadsheets.sheets.first end |
#worksheet_each_record(&block) ⇒ Object
61 62 63 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 61 def worksheet_each_record(&block) pager.each_record(self, &block) end |
#worksheet_grid_properties ⇒ Object
43 44 45 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 43 def worksheet_grid_properties worksheet_properties.grid_properties end |
#worksheet_max_column_num ⇒ Object
51 52 53 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 51 def worksheet_max_column_num worksheet_grid_properties.column_count end |
#worksheet_max_row_num ⇒ Object
47 48 49 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 47 def worksheet_max_row_num worksheet_grid_properties.row_count end |
#worksheet_properties ⇒ Object
39 40 41 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 39 def worksheet_properties worksheet.properties end |
#worksheet_values(range) ⇒ Object
55 56 57 58 59 |
# File 'lib/embulk/input/google_spreadsheets/spreadsheets_client.rb', line 55 def worksheet_values(range) range = "#{worksheet_title}!#{range}" logger.info { "`embulk-input-google_spreadsheets`: load data from spreadsheet: '#{spreadsheets_url}', range: '#{range}'" } service.get_spreadsheet_values(spreadsheets_id, range).values end |