-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import data from a google spreadsheet #903
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
41d18a6
Add google api client gem and spreadsheet service model
363b4f1
Add csv import from a google spreadsheet endpoint and fields in the f…
114303a
Delete open3 require from import_wizards_controller.rb
5262725
Add params validation before importing from a google spreadsheet
334fb2c
Add placeholder to spreadsheet url input and make it wider
f48d28c
Add google sheets api key documentation in README.md
4be22e1
Catch exception when importing from google sheets fails and display a…
06af00a
Add ids to clickable icons and change onclick functions to be based o…
22c2b3e
Fix Import Wizard forms
matiasgarciaisaia e57750b
Support setting Google Sheets API Key via environment
matiasgarciaisaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we need to add some error handling regarding the Spreadsheet import - catch the exception, log it, show some error to the user asking to contact the site admin? |
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if the same user imports a spreadsheet into a collection after having imported a previous one? What potential conflicts could arise then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file's content gets overwritten with the spreadsheet content that the user inputs. Filename does not change, but content does. We could use the spreadsheet id as the filename, but then we will have stored a csv file for every single spreadsheet users want to import.
With the current code we will have one spreadsheet per user that used the feature as the worst case scenario.