Class: Remi::Extractor::Gsheet
- Inherits:
-
FileSystem
- Object
- Remi::Extractor
- FileSystem
- Remi::Extractor::Gsheet
- Defined in:
- lib/remi/data_subjects/gsheet.rb
Overview
Contains methods shared between Salesforce Extractor/Parser/Encoder/Loader
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#expire_time ⇒ Object
readonly
Returns the value of attribute expire_time.
-
#ref_token ⇒ Object
readonly
Returns the value of attribute ref_token.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes inherited from FileSystem
#created_within, #group_by, #local_path, #most_recent_by, #most_recent_only, #pattern, #remote_path
Attributes inherited from Remi::Extractor
Instance Method Summary collapse
-
#all_entries ⇒ Array<Extractor::FileSystemEntry>
(Memoized) list of objects in the bucket/prefix.
-
#all_entries! ⇒ Array<Extractor::FileSystemEntry>
(Memoized) list of objects in the bucket/prefix.
- #authorize ⇒ Object
- #extract ⇒ Object
- #get_file_list(folder_id) ⇒ Object
- #get_spreadsheet_vals(service, spreadsheet_id, sheet_name = 'Sheet1') ⇒ Object
-
#initialize(*args, **kargs, &block) ⇒ Gsheet
constructor
A new instance of Gsheet.
- #service_list_files(service, folder_id) ⇒ Object
Methods inherited from FileSystem
#entries, #get_created_within, #matching_entries, #most_recent_matching_entry, #most_recent_matching_entry_in_group
Constructor Details
#initialize(*args, **kargs, &block) ⇒ Gsheet
Returns a new instance of Gsheet.
12 13 14 15 |
# File 'lib/remi/data_subjects/gsheet.rb', line 12 def initialize(*args, **kargs, &block) super init_gsheet_extractor(*args, **kargs) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
20 21 22 |
# File 'lib/remi/data_subjects/gsheet.rb', line 20 def access_token @access_token end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
18 19 20 |
# File 'lib/remi/data_subjects/gsheet.rb', line 18 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
19 20 21 |
# File 'lib/remi/data_subjects/gsheet.rb', line 19 def client_secret @client_secret end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/remi/data_subjects/gsheet.rb', line 17 def data @data end |
#expire_time ⇒ Object (readonly)
Returns the value of attribute expire_time.
23 24 25 |
# File 'lib/remi/data_subjects/gsheet.rb', line 23 def expire_time @expire_time end |
#ref_token ⇒ Object (readonly)
Returns the value of attribute ref_token.
21 22 23 |
# File 'lib/remi/data_subjects/gsheet.rb', line 21 def ref_token @ref_token end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
22 23 24 |
# File 'lib/remi/data_subjects/gsheet.rb', line 22 def scope @scope end |
Instance Method Details
#all_entries ⇒ Array<Extractor::FileSystemEntry>
Returns (Memoized) list of objects in the bucket/prefix.
69 70 71 |
# File 'lib/remi/data_subjects/gsheet.rb', line 69 def all_entries @all_entries ||= all_entries! end |
#all_entries! ⇒ Array<Extractor::FileSystemEntry>
Returns (Memoized) list of objects in the bucket/prefix.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/remi/data_subjects/gsheet.rb', line 74 def all_entries! gsheet_entries = get_file_list(@default_folder_id) gsheet_entries.map do |entry| entry = entry.to_h FileSystemEntry.new( pathname: File.join(@default_folder_id, entry[:name]), create_time: entry[:created_time], modified_time: entry[:created_time], raw: entry[:id] ) end end |
#authorize ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/remi/data_subjects/gsheet.rb', line 25 def credentials = Google::Auth::UserRefreshCredentials.new( client_id: @client_id, client_secret: @client_secret, scope: @scope, access_token: @access_token, refresh_token: @refresh_token, expires_at: @expiration_time / 1000 ) end |
#extract ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/remi/data_subjects/gsheet.rb', line 53 def extract service = Google::Apis::SheetsV4::SheetsService.new service..application_name = @application_name service. = () @data = [] entries.each do |file| logger.info "Extracting Google Sheet data from #{file.pathname}, with sheet name : #{@sheet_name}" response = get_spreadsheet_vals(service, file.raw, @sheet_name) data.push(response) end self end |
#get_file_list(folder_id) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/remi/data_subjects/gsheet.rb', line 37 def get_file_list(folder_id) service = Google::Apis::DriveV3::DriveService.new service..application_name = @application_name service. = () response = service_list_files(service, folder_id) response.files end |
#get_spreadsheet_vals(service, spreadsheet_id, sheet_name = 'Sheet1') ⇒ Object
49 50 51 |
# File 'lib/remi/data_subjects/gsheet.rb', line 49 def get_spreadsheet_vals(service, spreadsheet_id, sheet_name = 'Sheet1') service.get_spreadsheet_values(spreadsheet_id, sheet_name) end |
#service_list_files(service, folder_id) ⇒ Object
45 46 47 |
# File 'lib/remi/data_subjects/gsheet.rb', line 45 def service_list_files(service, folder_id) service.list_files(q: "'#{folder_id}' in parents", page_size: 10, order_by: 'createdTime desc', fields: 'nextPageToken, files(id, name, createdTime, mimeType)') end |