From 14facea0543ad1afb8a4e64fbd4c41842d6922b3 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 22 Jun 2024 12:44:40 -0700 Subject: [PATCH] Cleanup --- .github/workflows/go.yml | 37 ------ LICENSE | 21 --- README.md | 177 -------------------------- cmd/main.go | 43 ------- go.mod | 4 +- testdata/base_schema.json | 72 ----------- testdata/create_records.json | 22 ---- testdata/delete_record.json | 8 -- testdata/delete_records.json | 12 -- testdata/get_bases.json | 15 --- testdata/get_record.json | 9 -- testdata/get_records_with_filter.json | 32 ----- 12 files changed, 2 insertions(+), 450 deletions(-) delete mode 100644 .github/workflows/go.yml delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 cmd/main.go delete mode 100644 testdata/base_schema.json delete mode 100644 testdata/create_records.json delete mode 100644 testdata/delete_record.json delete mode 100644 testdata/delete_records.json delete mode 100644 testdata/get_bases.json delete mode 100644 testdata/get_record.json delete mode 100644 testdata/get_records_with_filter.json diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 8a9f0b0..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - name: Build - runs-on: ubuntu-latest - steps: - - - name: Set up Go 1.18 - uses: actions/setup-go@v1 - with: - go-version: 1.18 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - - - name: Generate coverage report - run: go test -race -coverprofile=coverage.txt -covermode=atomic - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - file: ./coverage.txt - name: codecov-umbrella - fail_ci_if_error: true diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 901c9e9..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Mike Berezin - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 8588cbd..0000000 --- a/README.md +++ /dev/null @@ -1,177 +0,0 @@ -Golang Airtable API -================ - -[![GoDoc](https://godoc.org/github.com/mehanizm/airtable?status.svg)](https://pkg.go.dev/github.com/mehanizm/airtable) -![Go](https://github.com/mehanizm/airtable/workflows/Go/badge.svg) -[![codecov](https://codecov.io/gh/mehanizm/airtable/branch/master/graph/badge.svg)](https://codecov.io/gh/mehanizm/airtable) -[![Go Report](https://goreportcard.com/badge/github.com/mehanizm/airtable)](https://goreportcard.com/badge/github.com/mehanizm/airtable) -[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) - -A simple #golang package to access the [Airtable API](https://airtable.com/api). - -Table of contents -=== -- [Golang Airtable API](#golang-airtable-api) -- [Table of contents](#table-of-contents) - - [Installation](#installation) - - [Basic usage](#basic-usage) - - [Initialize client](#initialize-client) - - [Get table](#get-table) - - [List records](#list-records) - - [Add records](#add-records) - - [Get record by ID](#get-record-by-id) - - [Update records](#update-records) - - [Delete record](#delete-record) - - [Bulk delete records](#bulk-delete-records) - - [Special thanks](#special-thanks) - - -## Installation - -The Golang Airtable API has been tested compatible with Go 1.13 on up. - -``` -go get github.com/mehanizm/airtable -``` - -## Basic usage - -### Initialize client - -You should get `your_api_token` in the airtable [account page](https://airtable.com/account) -```Go -client := airtable.NewClient("your_api_token") -``` - -You can use custom http client here -```Go -client.SetCustomClient(http.DefaultClient) -``` - -### Custom context -Each method below can be used with custom context. Simply use `MethodNameContext` call and provide context as first argument. - -### List bases - -```Go -bases, err := client.GetBases().WithOffset("").Do() -``` - -### Get base schema - -```Go -schema, err := client.GetBaseSchema("your_database_ID").Do() -``` - -### Get table - -To get the `your_database_ID` you should go to [main API page](https://airtable.com/api) and select the database. - -```Go -table := client.GetTable("your_database_ID", "your_table_name") -``` - -### List records - -To get records from the table you can use something like this - -```Go -records, err := table.GetRecords(). - FromView("view_1"). - WithFilterFormula("AND({Field1}='value_1',NOT({Field2}='value_2'))"). - WithSort(sortQuery1, sortQuery2). - ReturnFields("Field1", "Field2"). - InStringFormat("Europe/Moscow", "ru"). - Do() -if err != nil { - // Handle error -} -``` - -### Add records - -```Go -recordsToSend := &airtable.Records{ - Records: []*airtable.Record{ - { - Fields: map[string]any{ - "Field1": "value1", - "Field2": true, - }, - }, - }, -} -receivedRecords, err := table.AddRecords(recordsToSend) -if err != nil { - // Handle error -} -``` - -### Get record by ID - -```Go -record, err := table.GetRecord("recordID") -if err != nil { - // Handle error -} -``` - -### Update records - -To partial update one record - -```Go -res, err := record.UpdateRecordPartial(map[string]any{"Field_2": false}) -if err != nil { - // Handle error -} -``` - -To full update records - -```Go -toUpdateRecords := &airtable.Records{ - Records: []*airtable.Record{ - { - Fields: map[string]any{ - "Field1": "value1", - "Field2": true, - }, - }, - { - Fields: map[string]any{ - "Field1": "value1", - "Field2": true, - }, - }, - }, -} -updatedRecords, err := table.UpdateRecords(toUpdateRecords) -if err != nil { - // Handle error -} -``` - -### Delete record - -```Go -res, err := record.DeleteRecord() -if err != nil { - // Handle error -} -``` - -### Bulk delete records - -To delete up to 10 records - -```Go -records, err := table.DeleteRecords([]string{"recordID1", "recordsID2"}) -if err != nil { - // Handle error -} -``` - -## Special thanks - -Inspired by [Go Trello API](github.com/adlio/trello) \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go deleted file mode 100644 index cbd9a85..0000000 --- a/cmd/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/mehanizm/airtable" -) - -const ( - airtableAPIKey = "xxx" - airtableDBName = "xxx" - airtableTableName = "xxx" -) - -func main() { - airtableClient := airtable.NewClient(airtableAPIKey) - airtableTable := airtableClient.GetTable(airtableDBName, airtableTableName) - - offset := "" - - for { - records, err := airtableTable.GetRecords(). - WithFilterFormula("NOT({SomeBoolColumn})"). - ReturnFields("Column1", "Column2", "Column3", "Column4"). - MaxRecords(100). - PageSize(10). - WithOffset(offset). - Do() - if err != nil { - panic(err) - } - - for recordNum, record := range records.Records { - fmt.Println("====iteration====") - fmt.Println(recordNum, record) - } - - offset = records.Offset - if offset == "" { - break - } - } -} diff --git a/go.mod b/go.mod index 2500c8b..101f719 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/mehanizm/airtable +module github.com/flamingcow66/airtable -go 1.20 +go 1.22 diff --git a/testdata/base_schema.json b/testdata/base_schema.json deleted file mode 100644 index 993cae6..0000000 --- a/testdata/base_schema.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "tables": [ - { - "description": "Apartments to track.", - "fields": [ - { - "description": "Name of the apartment", - "id": "fld1VnoyuotSTyxW1", - "name": "Name", - "type": "singleLineText" - }, - { - "id": "fldoaIqdn5szURHpw", - "name": "Pictures", - "type": "multipleAttachments" - }, - { - "id": "fldumZe00w09RYTW6", - "name": "District", - "options": { - "inverseLinkFieldId": "fldWnCJlo2z6ttT8Y", - "isReversed": false, - "linkedTableId": "tblK6MZHez0ZvBChZ", - "prefersSingleRecordLink": true - }, - "type": "multipleRecordLinks" - } - ], - "id": "tbltp8DGLhqbUmjK1", - "name": "Apartments", - "primaryFieldId": "fld1VnoyuotSTyxW1", - "views": [ - { - "id": "viwQpsuEDqHFqegkp", - "name": "Grid view", - "type": "grid" - } - ] - }, - { - "fields": [ - { - "id": "fldEVzvQOoULO38yl", - "name": "Name", - "type": "singleLineText" - }, - { - "description": "Apartments that belong to this district", - "id": "fldWnCJlo2z6ttT8Y", - "name": "Apartments", - "options": { - "inverseLinkFieldId": "fldumZe00w09RYTW6", - "isReversed": false, - "linkedTableId": "tbltp8DGLhqbUmjK1", - "prefersSingleRecordLink": false - }, - "type": "multipleRecordLinks" - } - ], - "id": "tblK6MZHez0ZvBChZ", - "name": "Districts", - "primaryFieldId": "fldEVzvQOoULO38yl", - "views": [ - { - "id": "viwi3KXvrKug2mIBS", - "name": "Grid view", - "type": "grid" - } - ] - } - ] -} diff --git a/testdata/create_records.json b/testdata/create_records.json deleted file mode 100644 index 1c33526..0000000 --- a/testdata/create_records.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "records": [ - { - "id": "recnTq6CsvFM6vX2m", - "fields": { - "Field1": "Field1", - "Field2": true, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:57.000Z" - }, - { - "id": "recr3qAQbM7juKa4o", - "fields": { - "Field1": "Field1", - "Field2": true, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:49.000Z" - } - ] -} \ No newline at end of file diff --git a/testdata/delete_record.json b/testdata/delete_record.json deleted file mode 100644 index b79bcb8..0000000 --- a/testdata/delete_record.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "records": [ - { - "id": "recnTq6CsvFM6vX2m", - "deleted": true - } - ] -} \ No newline at end of file diff --git a/testdata/delete_records.json b/testdata/delete_records.json deleted file mode 100644 index 92e59bd..0000000 --- a/testdata/delete_records.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "records": [ - { - "id": "recnTq6CsvFM6vX2m", - "deleted": true - }, - { - "id": "recr3qAQbM7juKa4o", - "deleted": true - } - ] -} \ No newline at end of file diff --git a/testdata/get_bases.json b/testdata/get_bases.json deleted file mode 100644 index c59793b..0000000 --- a/testdata/get_bases.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "bases": [ - { - "id": "appLkNDICXNqxSDhG", - "name": "Apartment Hunting", - "permissionLevel": "create" - }, - { - "id": "appSW9R5uCNmRmfl6", - "name": "Project Tracker", - "permissionLevel": "edit" - } - ], - "offset": "itr23sEjsdfEr3282/appSW9R5uCNmRmfl6" -} diff --git a/testdata/get_record.json b/testdata/get_record.json deleted file mode 100644 index be22029..0000000 --- a/testdata/get_record.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id": "recnTq6CsvFM6vX2m", - "fields": { - "Field1": "Field1", - "Field2": true, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:57.000Z" -} \ No newline at end of file diff --git a/testdata/get_records_with_filter.json b/testdata/get_records_with_filter.json deleted file mode 100644 index 47d8816..0000000 --- a/testdata/get_records_with_filter.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "records": [ - { - "id": "recnTq6CsvFM6vX2m", - "fields": { - "Field1": "Field1", - "Field2": true, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:57.000Z" - }, - { - "id": "recr3qAQbM7juKa4o", - "fields": { - "Field1": "Field1", - "Field2": true, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:49.000Z" - }, - { - "id": "recr3qAQbM7juKa4a", - "fields": { - "Field1": "Field1", - "Field2": false, - "Field3": "2020-04-06T06:00:00.000Z" - }, - "createdTime": "2020-04-10T11:30:49.000Z" - } - ], - "offset": "10" -} \ No newline at end of file