Skip to content

Commit d7e9cf4

Browse files
authored
Add initial implementation (#1)
1 parent c2ebc75 commit d7e9cf4

File tree

210 files changed

+9891
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+9891
-0
lines changed

.github/workflows/test.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "**.md"
9+
10+
env:
11+
CI: "true"
12+
13+
concurrency:
14+
group: ${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
sdk:
19+
name: SDK
20+
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
go-version: ["1.20", "1.21"]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Go
30+
uses: actions/setup-go@v4
31+
with:
32+
go-version: ${{ matrix.go-version }}
33+
34+
- name: Check format
35+
run: |
36+
if [[ -n $( gofmt -l . ) ]]; then
37+
gofmt -l .
38+
exit 1
39+
fi
40+
41+
- name: Test
42+
run: |
43+
go test -count=1 ./...

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024 UserHub, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
11
# UserHub Go SDK
2+
3+
Stability: alpha
4+
5+
## Usage
6+
7+
```go
8+
package main
9+
10+
import (
11+
"context"
12+
"fmt"
13+
14+
"github.com/userhubdev/go-sdk/adminapi"
15+
)
16+
17+
func main() {
18+
adminApi, err := adminapi.New("sk_123...")
19+
if err != nil {
20+
panic(err)
21+
}
22+
23+
res, err := adminApi.Users().List(context.TODO(), &adminapi.UserListInput{
24+
PageSize: 5,
25+
})
26+
if err != nil {
27+
panic(err)
28+
}
29+
30+
for _, user := range res.Users {
31+
fmt.Println(user.Id, user.DisplayName)
32+
}
33+
}
34+
```

adminapi/adminapi.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Code generated. DO NOT EDIT.
2+
3+
package adminapi
4+
5+
import (
6+
"net/http"
7+
"strings"
8+
9+
"github.com/userhubdev/go-sdk/internal"
10+
"github.com/userhubdev/go-sdk/internal/options"
11+
"github.com/userhubdev/go-sdk/option"
12+
"github.com/userhubdev/go-sdk/types"
13+
)
14+
15+
type Error = types.UserHubError
16+
17+
// New returns a new Admin API client.
18+
func New(adminKey string, opts ...option.ClientOption) (Client, error) {
19+
o := &options.ClientOptions{
20+
BaseUrl: internal.ApiBaseUrl,
21+
Headers: http.Header{},
22+
}
23+
for _, opt := range opts {
24+
if opt != nil {
25+
opt.Apply(o)
26+
}
27+
}
28+
if err := o.Validate(); err != nil {
29+
return nil, err
30+
}
31+
32+
adminKey = strings.TrimSpace(adminKey)
33+
if adminKey == "" {
34+
return nil, internal.Errorf(nil, nil, "adminKey required")
35+
} else if !strings.HasPrefix(adminKey, internal.AdminKeyPrefix) {
36+
return nil, internal.Errorf(nil, nil, "adminKey must start with `%s`", internal.AdminKeyPrefix)
37+
} else {
38+
o.Headers.Set(internal.AuthHeader, "Bearer "+adminKey)
39+
}
40+
41+
transport := internal.NewHttpTransport(o.BaseUrl, o.Headers)
42+
43+
return newClient(transport), nil
44+
}
45+
46+
// Some is used to set an Optional value in update methods.
47+
func Some[T any](v T) types.Optional[T] {
48+
return types.Optional[T]{
49+
Value: v,
50+
Present: true,
51+
}
52+
}

adminapi/client.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Code generated. DO NOT EDIT.
2+
3+
package adminapi
4+
5+
import (
6+
"github.com/userhubdev/go-sdk/internal"
7+
)
8+
9+
// The Admin API.
10+
type Client interface {
11+
// The flow methods.
12+
Flows() Flows
13+
// The invoice methods.
14+
Invoices() Invoices
15+
// The organization methods.
16+
Organizations() Organizations
17+
// The subscription methods.
18+
Subscriptions() Subscriptions
19+
// The user methods.
20+
Users() Users
21+
}
22+
23+
type clientImpl struct {
24+
transport internal.Transport
25+
}
26+
27+
func newClient(transport internal.Transport) Client {
28+
return &clientImpl{transport: transport}
29+
}
30+
31+
func (c *clientImpl) Flows() Flows {
32+
return &flowsImpl{transport: c.transport}
33+
}
34+
35+
func (c *clientImpl) Invoices() Invoices {
36+
return &invoicesImpl{transport: c.transport}
37+
}
38+
39+
func (c *clientImpl) Organizations() Organizations {
40+
return &organizationsImpl{transport: c.transport}
41+
}
42+
43+
func (c *clientImpl) Subscriptions() Subscriptions {
44+
return &subscriptionsImpl{transport: c.transport}
45+
}
46+
47+
func (c *clientImpl) Users() Users {
48+
return &usersImpl{transport: c.transport}
49+
}

0 commit comments

Comments
 (0)