Skip to content

Commit 54315f6

Browse files
Add selected v1 API endpoints to SDK (#1)
1 parent b008c8d commit 54315f6

25 files changed

Lines changed: 1758 additions & 67 deletions

.github/workflows/labels.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
steps:
1313
- uses: actions/github-script@v7
1414
with:
15+
result-encoding: string
1516
script: |
16-
if (join(github.event.pull_request.labels) === '' {
17-
core.setFailed('at least one label is required')
18-
}
17+
console.log(context.payload.pull_request.labels.length + " label(s) applied")
18+
if (context.payload.pull_request.labels.length < 1) {
19+
core.setFailed("At least one label is required.")
20+
}

.github/workflows/test.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,31 @@ jobs:
1010
golangci-lint:
1111
name: Lint
1212
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: golangci/golangci-lint-action@v6
16+
with:
17+
version: latest
18+
go-test:
19+
name: Test
20+
runs-on: ubuntu-latest
1321
steps:
1422
- uses: actions/checkout@v4
1523
- uses: actions/setup-go@v5
1624
with:
25+
go-version: '1.23.2'
1726
go-version-file: "go.mod"
1827
cache: true
1928
- run: go mod download
20-
- run: go build -v .
21-
- uses: golangci/golangci-lint-action@v6
22-
with:
23-
version: latest
24-
29+
- run: go test -v -coverprofile coverage.out ./...
30+
- env:
31+
COVERAGE_THRESHOLD_PCT: 40
32+
run: |
33+
coverage=$(go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
34+
if (( $(echo "$coverage > $COVERAGE_THRESHOLD_PCT" | bc -l) )); then
35+
echo "Test coverage exceeds minimum threshold"
36+
else
37+
echo "Test coverage is below minimum threshold"
38+
go tool cover -func=coverage.out
39+
exit 1
40+
fi

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default: lint
33
# Run unit tests
44
.PHONY: tests
55
tests:
6-
go test ./... -v $(TESTARGS) -timeout 120m
6+
go test ./... -v $(TESTARGS) -cover -timeout 120m
77

88
# Run linter
99
.PHONY: lint

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ func main() {
6262

6363
```
6464

65-
Naming conventions for this package follow a {Verb}{Object(s)} pattern mirroring the actions and objects outlined
66-
in the [API Documentation](https://www.tines.com/api/). For example, retrieving an individual Story is `GetStory()`,
67-
updating an individual Folder is `UpdateFolder()`, etc.
65+
Naming conventions for this package follow a `{Verb}{Object(s)}` pattern mirroring the actions and objects outlined
66+
in the [API Documentation](https://www.tines.com/api/). For example, retrieving an individual Folder is `GetFolder()`,
67+
updating an individual Folder is `UpdateFolder()`, listing all Folders is `ListFolders()`, etc.
6868

69-
The Tines SDK supports [Uber's zap logging library](https://github.com/uber-go/zap/). To enable logging,
70-
pass in a configured logger when creating a new client.
69+
The Tines SDK supports [Uber's zap logging library](https://github.com/uber-go/zap/) for debugging purposes. To enable logging,
70+
pass in a configured logger when creating a new client. The Tines SDK only logs at a debug level - any errors will be passed
71+
back to your application and should be handled according to your normal error-handling logic.
7172

7273
```go
73-
logger := zap.Must(zap.NewProduction())
74+
logger := zap.Must(zap.NewDevelopment())
7475
defer logger.Sync()
7576

7677
cli, err := tines.NewClient(

go.mod

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ module github.com/tines/go-sdk
22

33
go 1.23.2
44

5-
require go.uber.org/zap v1.27.0
5+
require (
6+
github.com/stretchr/testify v1.10.0
7+
go.uber.org/zap v1.27.0
8+
)
69

7-
require go.uber.org/multierr v1.11.0 // indirect
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
go.uber.org/multierr v1.11.0 // indirect
14+
gopkg.in/yaml.v3 v3.0.1 // indirect
15+
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
6-
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
5+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
77
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
88
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
99
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
1010
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1111
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
1212
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1315
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1416
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/paginate/paginate_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package paginate_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/tines/go-sdk/internal/paginate"
8+
)
9+
10+
var TestCursorWithLimit = paginate.Cursor{
11+
Meta: paginate.Meta{
12+
CurrentPage: "https://example.com/?per_page=1&page=1",
13+
PreviousPage: "",
14+
NextPage: "https://example.com?per_page=1&page=2",
15+
NextPageNum: 2,
16+
PerPage: 1,
17+
Pages: 3,
18+
Count: 3,
19+
},
20+
TotalRequested: 2,
21+
}
22+
23+
var TestCursorNoLimit = paginate.Cursor{
24+
Meta: paginate.Meta{
25+
CurrentPage: "https://example.com/?per_page=1&page=1",
26+
PreviousPage: "",
27+
NextPage: "https://example.com?per_page=1&page=2",
28+
NextPageNum: 2,
29+
PerPage: 1,
30+
Pages: 2,
31+
Count: 2,
32+
},
33+
TotalRequested: 0,
34+
}
35+
36+
func TestPaginationWithLimit(t *testing.T) {
37+
assert := assert.New(t)
38+
39+
assert.Equal(true, TestCursorWithLimit.MoreResultsAvailable(), "indicate that more results are available if next page is not nil")
40+
assert.Equal(false, TestCursorWithLimit.MaxResultsReturned(), "indicate that the maximum requested number of results has not been returned yet")
41+
assert.Equal(true, TestCursorWithLimit.ReturnMoreResults(), "indicate that more results should be returned")
42+
assert.Equal(0, TestCursorWithLimit.CurrentCounter(), "indicate that no results have been returned yet")
43+
44+
TestCursorWithLimit.IncrementCounter()
45+
46+
assert.Equal(1, TestCursorWithLimit.CurrentCounter(), "counter should increment by one")
47+
48+
params := TestCursorWithLimit.GetNextPageParams()
49+
50+
assert.Equal(map[string]interface{}{"page": "2", "per_page": "1"}, params, "next page params should get successfully extracted")
51+
52+
TestCursorWithLimit.IncrementCounter()
53+
54+
assert.Equal(false, TestCursorWithLimit.ReturnMoreResults(), "indicate that the maximum number of requested results have been returned")
55+
}
56+
57+
func TestPaginationNoLimit(t *testing.T) {
58+
assert := assert.New(t)
59+
60+
assert.Equal(false, TestCursorNoLimit.MaxResultsReturned(), "indicate that there is no maximum number of results to return")
61+
62+
newMeta := paginate.Meta{
63+
// Next Page info will be nil in the server response, so we don't set it here.
64+
CurrentPage: "https://example.com/?per_page=1&page=2",
65+
PreviousPage: "https://example.com?per_page=1&page=1",
66+
PerPage: 1,
67+
Pages: 2,
68+
Count: 2,
69+
}
70+
71+
TestCursorNoLimit.UpdatePagination(newMeta)
72+
73+
assert.Equal(false, TestCursorNoLimit.MoreResultsAvailable(), "indicate that no more results are available")
74+
}

internal/utils/formatting.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
package utils
22

3-
import (
4-
"fmt"
5-
"runtime/debug"
6-
)
7-
8-
func SetClientVersion() string {
9-
version := "development"
10-
build, ok := debug.ReadBuildInfo()
11-
if ok {
12-
version = build.Main.Version
13-
}
14-
return version
15-
}
16-
173
func SetUserAgent(ua string) string {
184
if ua == "" {
19-
return fmt.Sprintf("TinesGoSdk/%s", SetClientVersion())
5+
return "Tines/GoSdk"
206
}
217
return ua
228
}

internal/utils/formatting_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package utils_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/tines/go-sdk/internal/utils"
8+
)
9+
10+
func TestSetUserAgent(t *testing.T) {
11+
assert := assert.New(t)
12+
tests := []struct {
13+
input string
14+
expected string
15+
expectedErr error
16+
}{
17+
{input: "", expected: "Tines/GoSdk", expectedErr: nil},
18+
{input: "foo", expected: "foo", expectedErr: nil},
19+
}
20+
21+
for _, tt := range tests {
22+
actual := utils.SetUserAgent(tt.input)
23+
assert.Equal(tt.expected, actual)
24+
}
25+
}

tines/actions.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
package tines
22

3-
type Action struct {
4-
Id int `json:"id,omitempty"`
5-
Type string `json:"type,omitempty"`
6-
UserID int `json:"user_id,omitempty"`
7-
Options ActionOptions `json:"options,omitempty"`
8-
Name string `json:"name,omitempty"`
9-
Schedule []ActionSchedule `json:"schedule,omitempty"`
10-
BlendedEventsCt int `json:"blended_events_count,omitempty"`
11-
LogsCt int `json:"logs_count,omitempty"`
12-
}
13-
14-
type ActionOptions struct {
15-
Mode string `json:"mode,omitempty"`
16-
}
17-
18-
type ActionSchedule struct {
19-
Cron string `json:"cron,omitempty"`
20-
Timezone string `json:"timezone,omitempty"`
21-
}
3+
// TODO: This endpoint is not fully implemented in the SDK yet.

0 commit comments

Comments
 (0)