Skip to content

Commit

Permalink
impr: add context to Do methods (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehanizm committed Dec 23, 2024
1 parent e0fd5aa commit 56620ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions get-bases.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package airtable

import (
"context"
"net/url"
)

Expand Down Expand Up @@ -35,3 +36,8 @@ func (gbc *GetBasesConfig) WithOffset(offset string) *GetBasesConfig {
func (gbc *GetBasesConfig) Do() (*Bases, error) {
return gbc.client.GetBasesWithParams(gbc.params)
}

// DoContext send the prepared get records request with context.
func (gbc *GetBasesConfig) DoContext(ctx context.Context) (*Bases, error) {
return gbc.client.GetBasesWithParamsContext(ctx, gbc.params)
}
9 changes: 8 additions & 1 deletion get-records.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package airtable

import (
"context"
"fmt"
"net/url"
"strconv"
Expand Down Expand Up @@ -44,7 +45,8 @@ func (grc *GetRecordsConfig) WithFilterFormula(filterFormula string) *GetRecords
func (grc *GetRecordsConfig) WithSort(sortQueries ...struct {
FieldName string
Direction string
}) *GetRecordsConfig {
},
) *GetRecordsConfig {
for queryNum, sortQuery := range sortQueries {
grc.params.Set(fmt.Sprintf("sort[%v][field]", queryNum), sortQuery.FieldName)
grc.params.Set(fmt.Sprintf("sort[%v][direction]", queryNum), sortQuery.Direction)
Expand Down Expand Up @@ -105,3 +107,8 @@ func (grc *GetRecordsConfig) InStringFormat(timeZone, userLocale string) *GetRec
func (grc *GetRecordsConfig) Do() (*Records, error) {
return grc.table.GetRecordsWithParams(grc.params)
}

// DoContext send the prepared get records request with context.
func (grc *GetRecordsConfig) DoContext(ctx context.Context) (*Records, error) {
return grc.table.GetRecordsWithParamsContext(ctx, grc.params)
}

0 comments on commit 56620ac

Please sign in to comment.