Class: Operationcode::Airtable
- Inherits:
-
Object
- Object
- Operationcode::Airtable
- Defined in:
- lib/operationcode/airtable.rb,
lib/operationcode/airtable/version.rb
Constant Summary collapse
- VERSION =
'0.3.0'
Instance Method Summary collapse
-
#all ⇒ Array
Lists all records in the table.
-
#create(record) ⇒ Airtable::Record
Creates a record in airtables.
- #find_by(params) ⇒ Object
-
#initialize(api_key: nil, base_id:, table:) ⇒ OperationCode::Airtable
constructor
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.
Constructor Details
#initialize(api_key: nil, base_id:, table:) ⇒ OperationCode::Airtable
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
17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#all ⇒ Array
Lists all records in the table
27 28 29 |
# File 'lib/operationcode/airtable.rb', line 27 def all @table.all end |
#create(record) ⇒ Airtable::Record
Creates a record in airtables
35 36 37 38 |
# File 'lib/operationcode/airtable.rb', line 35 def create(record) record = ::Airtable::Record.new(record) @table.create record end |
#find_by(params) ⇒ Object
40 41 42 43 44 45 |
# 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 |