-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from co-cddo/gather_data_from_rapid
Gather data from rapid
- Loading branch information
Showing
48 changed files
with
949 additions
and
399 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
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 was deleted.
Oops, something went wrong.
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,41 @@ | ||
# Use in data tables where source of data is (can be) Airtable. | ||
# Add the class via extend. For example: | ||
# | ||
# class FooBar < DataTable | ||
# extend AirtableDataSource | ||
# | ||
|
||
module AirtableDataSource | ||
def search_via_air_table(text) | ||
query = { "filterByFormula" => %[SEARCH("#{text}",{Name})] } | ||
data = AirTableApi.data_for(air_table_path, query:) | ||
return none if data[:records].empty? | ||
|
||
ids = data[:records].pluck(:id) | ||
where(record_id: ids) | ||
end | ||
|
||
def data_from_air_table | ||
data = {} | ||
records = {} | ||
# API returns 100 records at a time. | ||
# If there are more records, API returns an offset key that needs to be | ||
# passed into the next query | ||
while data.empty? || data[:offset].present? | ||
query = data[:offset].present? ? { offset: data[:offset] } : {} | ||
data = AirTableApi.data_for(air_table_path, query:) | ||
data[:records].each do |record| | ||
next if record[:fields].empty? | ||
next if is_draft?(record) | ||
|
||
records[record[:id]] = record[:fields] | ||
end | ||
end | ||
records | ||
end | ||
|
||
def air_table_path | ||
table_id = AirTableTable.id_for_name(air_table_name) | ||
"#{AirTableBase.base_id}/#{table_id}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module RapidDataSource | ||
def data_from_rapid | ||
data = RapidApi.output_for(rapid_table_name) | ||
|
||
data.each_with_object({}) do |(_key, record), hash| | ||
record[:name] = record[rapid_name_field] | ||
hash[record.fetch(:id, record[:name])] = record # Identifiy via the id within the record if present, else use name | ||
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
Oops, something went wrong.