#AIS QuickBase Ruby Gem
This gem is designed to be a concise, clear and maintainable collection of common Quickbase API calls used in ruby development. It implements a subset of the total Quickbase API.
##Example
require 'quickbase'
# Create a new API connection
qb_api = AdvantageQuickbase::API.new( domain, username, password, app_token, ticket, user_token )
# Load all of the Books in our table
query_options = { query: "{6.EX.'Book'}", clist: [7] }
books = qb_api.do_query( 'books_db_id', query_options )
puts books.inspect
# => [ {"7" => "Lord of the Flies"}, {"7" => "The Giver"} ]
##API Documentation ###New Connection
qb_api = Advantage::QuickbaseAPI.new( domain, username, password, app_token, ticket, user_token )
###Find find(db_id, record_id, query_options) => [json] record
query_options
expects a hash containing any (or none) of the following options:
-
clist
- a list (Array or period-separated string) of fields to return -
fmt
- defaults to "structured"; usefmt: ''
to set api responses to unstructured
#Load the record that has a Record ID 8 from the books table
book = qb_api.find( 'books_db_id', 8, clist: [3, 7] )
puts book.inspect
# => {"3" => "8", "7" =>"The Giver"}
###Get DB Var get_db_var( app_id, variable_name ) => [string] Variable Value
value = qb_api.get_db_var( 'abcd1234', 'test' )
###Set DB Var set_db_var( app_id, variable_name, value=nil ) => [bool] Success?
qb_api.set_db_var( 'abcd1234', 'test', 'value' )
###Do Query Count do_query_count( db_id, query=nil ) => [int] Record Count
today = Date.today.strftime( '%Y-%m-%d' )
num_records = qb_api.do_query_count( 'abcd1234', "{1.EX.'#{today}'}" )
###Do Query do_query( db_id, query_options ) => [json] records
query_options
expects a hash containing any (or none) of the following options:
-
query
- typical Quickbase query string. ex:"{3.EX.'123'}"
-
qid
- report or query id to load (should not be used withquery
orqname
) -
qname
- report or query name to load (should not be used withquery
orqid
) -
clist
- a list (Array or period-separated string) of fields to return -
slist
- a list (Array or period-separated string) of fields to sort by -
fmt
- defaults to "structured"; usefmt: ''
to set api responses to unstructured -
options
- string of additional options. ex:"num-200.skp-#{records_processed}"
records = qb_api.do_query( 'bdjwmnj33', query: "{3.EX.'123'}", clist: [3, 6, 10] )
###Add Record add_record( db_id, new_data ) => [int] New Record Id
new_data = { 6 => 'Book', 7 => 'My New Title', 8 => 'John Smith'}
new_record_id = qb_api.add_record( 'abcd1234', new_data )
###Edit Record edit_record( db_id, record_id, new_data ) => [bool] Success?
new_data = { 7 => 'My Second Title', 8 => 'John Smith'}
call_successful = qb_api.edit_record( 'abcd1234', 136, new_data )
###Delete Record delete_record( db_id, record_id ) => [bool] Success?
call_successful = qb_api.delete_record( 'abcd1234', 136 )
###Purge Records purge_records( db_id, options ) => [int] Records Deleted
options
expects a hash containing any of the following options:
-
query
- typical Quickbase query string. ex:"{3.EX.'123'}"
-
qid
- report or query id to load (should not be used withquery
orqname
) -
qname
- report or query name to load (should not be used withquery
orqid
)
records_deleted = qb_api.purge_records( 'abcd1234', {qid: 6} )
###Get Schema Get the complete schema of the whole quickbase app
get_schema( db_id )
app_schema = qb_api.get_schema( 'abcd1234' )
###Import From CSV import_from_csv( db_id, data, column_field_ids ) => [json] New Record Ids
new_data = [
['Book', 'Lord of the Flies', 'William Golding'],
['Book', 'A Tale of Two Cities', 'Charles Dickens'],
['Book', 'Animal Farm', 'George Orwell']
]
record_ids = qb_api.import_from_csv( 'abcd1234', new_data, [6, 7, 8] )
###Create App Token Create an app token that gives you access to that Quickbase app
create_app_token(db_id, description, page_token)
-
db_id
- database id -
description
- description of what the token is for -
page_token
- token hidden in the page DOM
app_token = qb_api.create_app_token( 'abcd1234', 'Access all the books in the database', 'TugHxxkil9t6Kdebac' )