For others coming later, this is code for a custom connector supplied by Tada devs. To use it you’ll need the application ID, API key, and API secret from your Tadabase account.
{
title: 'Tadabase',
connection: {
fields: [
{
name: 'application_id',
optional: false,
label:'Application Id'
},
{
name: 'api_key',
control_type: "password",
optional: false,
label:'API Key'
},
{
name: 'api_secret',
control_type: "password",
optional: false,
label:'API Secret'
}
],
authorization: {
type: "custom_auth",
apply: ->(connection) {
headers("X-Tadabase-App-id": connection["application_id"])
headers("X-Tadabase-App-Key": connection["api_key"])
headers("X-Tadabase-App-Secret": connection["api_secret"])
}
},
base_uri: ->(connection) {
"https://api.tadabase.io/api/v1/data-tables"
}
},
test: ->(connection) {
get("https://api.tadabase.io/api/v1/data-tables")
},
object_definitions: {
data_tables: {
fields: ->(connection) {
get("https://api.tadabase.io/api/v1/data-tables")['data_tables'].
map { |f| { name: f['id'], label: f['name'] } }
}
},
data_fields: {
fields: ->(connection, config_fields) {
next [] if config_fields.blank?
call(:dynamic_fields, { table_id: config_fields['table_id'], with_ID:true })
}
},
data_fields1: {
fields: ->(connection, config_fields) {
next [] if config_fields.blank?
call(:dynamic_fields, { table_id: config_fields['table_id'] })
}
},
c_fields: {
fields: ->(connection, config_fields) {
next [] if config_fields.blank?
call(:dynamic_fields, { table_id: config_fields['table_id'] })
}
},
u_fields: {
fields: ->(connection, config_fields) {
next [] if config_fields.blank?
call(:dynamic_fields, { table_id: config_fields['table_id'], with_ID:true })
}
}
},
methods: {
get_parse_data: ->(input) {
items = input[:items]
fields = call(:full_fields, { table_id: input[:table_id] })
items.each { |item|
fields.each { |field|
value = item[ field['slug'] ]
if item[ field['slug'] ].present?
case field['type']
when 'Checkbox', 'Multi-Select'
data = ""
if !value.blank?
data = value.smart_join(",")
end
item[ field['slug'] ] = data
#when 'File'
# file = ""
# if !value.blank? && value[ 'url' ].present?
# file = value[ 'url' ]
# end
# item[ field['slug'] ] = file
when 'Image'
image = ""
if !value.blank? && value[ 'src' ].present?
image = value[ 'src' ]
end
item[ field['slug'] ] = image
when 'Connection', 'Join'
values = item[ field['slug'] + '_val' ]
arr = {
"id" => "",
"val" => ""
}
if !values.blank? && values.length > 0
ids = []
vals = []
values.each_with_index { |v,index|
ids[index] = v["id"] != "null" ? v["id"] : ""
vals[index] = v["val"] != "null" ? v["val"] : ""
}
arr["id"] = ids.smart_join(',')
arr["val"] = vals.smart_join(',')
end
item[ field['slug'] ].clear
item[ field['slug'] ] = arr
end
end
}
}
},
full_fields: ->(input) {
get("https://api.tadabase.io/api/v1/data-tables/#{input[:table_id]}/full-fields-info")['fields']
},
dynamic_fields: ->(input) {
next [] if input.blank?
fields = call(:full_fields, { table_id: input[:table_id] })
fields = fields.map { |f|
vals = { name: f['slug'], label: f['name'] }
case f['type']
when 'Name'
vals['type'] = :object
vals['properties'] = f[ 'fields' ].map { |sf| { name: sf['key'], label: sf['name'] } }
when 'Address'
vals['type'] = :object
properties = f[ 'fields' ].map { |sf| { name: sf['key'], label: sf['name'] } }
properties[properties.length] = { name: "lat", label: "Longitude" }
properties[properties.length] = { name: "lng", label: "Latitude" }
vals['properties'] = properties
when 'Link'
vals['type'] = :object
vals['properties'] = [
{ name: "link", label: "Link", control_type:'url' },
{ name: "text", label: "Text" }
]
when 'Select', 'Multi-Select','Radio'
vals['control_type'] = 'select'
vals['pick_list'] = f[ 'options' ].pluck('value', 'label')
vals['toggle_hint'] = "Select from list"
vals['toggle_field'] = {
name: f['slug'],
label: f['name'],
type: :string,
control_type: "text",
toggle_hint: "Enter Custom Value"
}
when 'Checkbox'
vals['control_type'] = 'checkbox'
vals['pick_list'] = f[ 'options' ].pluck('value', 'label')
vals['toggle_hint'] = "Select from list"
vals['toggle_field'] = {
name: f['slug'],
label: f['name'],
type: :string,
control_type: "text",
toggle_hint: "Enter Custom Value"
}
when 'Calendar'
vals['type'] = :object
vals['properties'] = [
{ name: "start", label: "Start", control_type:'date_time' },
{ name: "end", label: "End", control_type:'date_time' }
]
when 'Date/Time'
vals['control_type'] = 'date_time'
when 'File'
vals['type'] = :object
vals['properties'] = [
{ name: "fileName", label: "File Name" },
{ name: "url", label: "URL" }
]
when 'Long Text'
vals['control_type'] = 'text-area'
when 'Connection', 'Join'
if input[:with_ID].present? && input[:with_ID].is_true?
vals['type'] = :object
vals['properties'] = [
{ name: "id", label: "ID" },
{ name: "val", label: "Val" }
]
end
end
vals['sticky'] = true
vals
}
if input[:with_ID].present? && input[:with_ID].is_true?
fields[fields.length] = { name: "id", label: "Record ID", hint:'(Tababase Auto Generated ID)', optional: false }
end
fields
}
},
actions: {
search_record: {
title:'Search Record',
description: 'Search for record in <span class="provider">Tadabase</span>',
config_fields: [
{
name: "table_id",
label: "Select Table",
optional: false,
control_type: "select",
pick_list: "data_tables"
},
{
name: "condition",
label: "Condition",
optional: false,
control_type: "select",
pick_list: "condition"
}
],
input_fields: ->(object_definitions) {
object_definitions['data_fields1']
},
execute: ->(connection,input) {
limit = 200
data = input
url = "https://api.tadabase.io/api/v1/data-tables/#{input['table_id']}/records"
input["condition"] = "AND" if input["condition"].blank?
url_qs = "filters[condition]="+input["condition"]
data = data.except(:table_id, :id, :condition).reject{ |n| n.blank? }
if !data.blank?
data.each_with_index { |item, index|
if !url_qs.blank?
url_qs = url_qs + "&filters[items]["+index+"][field_id]="+item[0]+"&filters[items]["+index+"][operator]=is&filters[items]["+index+"][val]="+item[1]
else
url_qs = "filters[items]["+index+"][field_id]="+item[0]+"&filters[items]["+index+"][operator]=is&filters[items]["+index+"][val]="+item[1]
end
}
end
url = url + "?" + url_qs
get(url).params( limit: limit, order: 'id', order_by: 'desc' )
},
output_fields: -> (object_definitions) {
object_definitions['data_fields1']
}
},
create_record: {
title:'Create Record',
description: 'Create record in <span class="provider">Tadabase</span>',
config_fields: [
{
name: "table_id",
label: "Select Table",
optional: false,
control_type: "select",
pick_list: "data_tables"
}
],
input_fields: ->(object_definitions) {
object_definitions["data_fields1"]
},
execute: ->(connection,input) {
data = input
data = data.except(:table_id, :id).reject { |n| n.blank? }
error("No Field Found To Save") if data.blank?
post("https://api.tadabase.io/api/v1/data-tables/#{input['table_id']}/records", data)
},
output_fields: -> (object_definitions) {
object_definitions['data_fields1']
}
},
update_record: {
title:'Update Record',
description: 'Update record in <span class="provider">Tadabase</span>',
config_fields: [
{
name: "table_id",
label: "Select Table",
optional: false,
control_type: "select",
pick_list: "data_tables"
}
],
input_fields: ->(object_definitions) {
object_definitions["data_fields1"]
},
execute: ->(connection,input) {
data = input
data = data.except(:table_id, :id).reject { |n| n.blank? }
error("No Field Found To Save") if data.blank?
post("https://api.tadabase.io/api/v1/data-tables/#{input['table_id']}/records/#{input['id']}", data)
},
output_fields: -> (object_definitions) {
object_definitions['data_fields1']
}
},
get_record_by_id: {
title:'Get Record By ID',
description: 'Get record by ID in <span class="provider">Tadabase</span>',
config_fields: [
{
name: "table_id",
label: "Select Table",
optional: false,
control_type: "select",
pick_list: "data_tables"
}
],
input_fields: ->(object_definitions) {
{
name: "id",
label: "Record ID",
optional: false,
}
},
execute: ->(connection,input) {
response = get("https://api.tadabase.io/api/v1/data-tables/#{input['table_id']}/records/#{input['id']}")
error("The record was not found.") if response['type'] == 'error'
response['item']
},
output_fields: -> (object_definitions) {
object_definitions['data_fields']
}
}
},
triggers: {
new_records: {
title:'New Record',
description: 'New record in <span class="provider">Tadabase</span>',
type: :paging_desc,
config_fields: [
{
name: "table_id",
label: "Select Table",
optional: false,
control_type: "select",
pick_list: "data_tables"
}
],
poll: ->(connection,input,page) {
page ||= 1
limit = 10
response = get("https://api.tadabase.io/api/v1/data-tables/#{input['table_id']}/records").
params(
page: page,
limit: limit,
order: 'id',
order_by: 'desc'
)
length = response['items'].length
next_page = response['total_pages'] == response['current_page'].to_i ? nil : (page + 1)
items = []
if length > 0
items = call(:get_parse_data, { items: response['items'], table_id: input['table_id'] })
end
{
events: items,
next_page: next_page
}
},
output_fields: -> (object_definitions) {
object_definitions['data_fields']
}
}
},
pick_lists: {
data_tables: ->(connection) {
tabels = get("https://api.tadabase.io/api/v1/data-tables").
after_error_response(400) do |code, body, headers, message|
error("Error loading Data Tables: #{body[/(?<=error\"\:\").*(?=\"\})/]}")
end
tabels = tabels['data_tables'].pluck('name', 'id')
tabels
},
condition: ->(connection) {
[
[ "AND", "AND" ],
[ "OR", "OR" ]
]
},
}
}