class Operationcode::Airtable

Constants

VERSION

Public Class Methods

new(api_key: nil, base_id:, table:) click to toggle source

Library for the Operation code Airtable service github.com/Airtable/airtable-ruby Airtable is where we store user information, contacts, and other various settings for the Operation Code platform

@param base_id [String] base_id for the airtable base. This can be found on the tables API page @param table [String] the name of the airbase table @return [OperationCode::Airtable]

# File lib/operationcode/airtable.rb, line 17
def initialize(api_key: nil, base_id:, table:)
  api_key = ENV.fetch('AIRTABLE_API_KEY') if api_key.nil?
  raise(KeyError, 'AIRTABLE_API_KEY is blank') if api_key.delete(' ') == ''

  client = ::Airtable::Client.new(api_key)
  @table = client.table(base_id, table)
end

Public Instance Methods

all() click to toggle source

Lists all records in the table @return [Array]

# File lib/operationcode/airtable.rb, line 27
def all
  @table.all
end
create(record) click to toggle source

Creates a record in airtables

@param record [Hash] A hash containing all, some, or none of the key/value pairs of columns in the table @return [Airtable::Record] if successful, `false` if there was an error

# File lib/operationcode/airtable.rb, line 35
def create(record)
  record = ::Airtable::Record.new(record)
  @table.create record
end
find_by(params) click to toggle source
# File lib/operationcode/airtable.rb, line 40
def find_by(params)
  raise ArgumentError unless params.kind_of? Hash
  column, value = params.first
  result = @table.select(limit: 1, formula: "#{column} = \"#{value}\"")
  result == [] ? nil : result
end