-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import data from a google spreadsheet (#903)
* Add google api client gem and spreadsheet service model * Add csv import from a google spreadsheet endpoint and fields in the form to paste the spreadsheet url * Delete open3 require from import_wizards_controller.rb * Add params validation before importing from a google spreadsheet * Add placeholder to spreadsheet url input and make it wider * Add google sheets api key documentation in README.md * Catch exception when importing from google sheets fails and display an error message to the user. * Add ids to clickable icons and change onclick functions to be based on those ids and not on icon classes * Fix Import Wizard forms The code had the wrong identation, so the upload controls were only shown for empty collections. This commit moves the code to where it belongs, so only the Download section changes depending on having sites or not. * Support setting Google Sheets API Key via environment So we can easily configure it on Rancher/Docker Co-authored-by: Diego <dduarte@manas.com.ar> Co-authored-by: Matias Garcia Isaia <mgarcia@manas.tech>
- Loading branch information
1 parent
3a21e89
commit 82bc51b
Showing
10 changed files
with
207 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'google/apis/sheets_v4' | ||
|
||
class SpreadsheetService | ||
def self.get_data(spreadsheet_id) | ||
service = Google::Apis::SheetsV4::SheetsService.new | ||
service.key = Settings.google_sheet_api_key | ||
|
||
range = SpreadsheetService.get_range(spreadsheet_id) | ||
begin | ||
response = service.get_spreadsheet_values(spreadsheet_id, range) | ||
rescue Exception => e | ||
Rails.logger.error e.message + "\n" + e.backtrace.join("\n") | ||
raise ActionController::BadRequest.new(), e.message() | ||
end | ||
|
||
response.values | ||
end | ||
|
||
def self.get_range(spreadsheet_id) | ||
service = Google::Apis::SheetsV4::SheetsService.new | ||
service.key = Settings.google_sheet_api_key | ||
|
||
begin | ||
sheet = service.get_spreadsheet(spreadsheet_id) | ||
range = sheet.sheets[0].properties.title | ||
range | ||
rescue Exception => e | ||
Rails.logger.error e.message + "\n" + e.backtrace.join("\n") | ||
raise ActionController::BadRequest.new(), e.message() | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters