37 lines
764 B
Ruby

require 'airrecord'
module SpreadsheetBackends
class Airtable
attr_accessor :form, :user
def initialize(form)
@form = form
@user = form.user
end
def url
"https://airtable.com/#{form.airtable_app_key}"
end
def append(data)
result = table.create(data, typecast: true)
result.id.present?
rescue Airrecord::Error => e
return false
end
def create
# Airtable must already exist
# TODO: maybe add validation here?
end
def headers
table.records.first&.fields&.keys # we only know the headers once we have at least one record
end
def table
@table ||= Airrecord.table(form.airtable_api_key, form.airtable_app_key, form.airtable_table)
end
end
end