Skip to content

Commit

Permalink
Release v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Oct 28, 2023
1 parent 94a66bb commit b075d3f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 122 deletions.
121 changes: 0 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
The Seam Go library provides convenient access to the Seam API from Go.
<!-- End Title -->

# Documentation

[![go shield](https://img.shields.io/badge/go-docs-blue)](https://pkg.go.dev/github.com/seamapi/go)

The Go package documentation is available at [`pkg.go.dev`](https://pkg.go.dev/github.com/seamapi/go).

# Requirements

This module requires Go version >= 1.13.

<!-- Begin Installation, generated by Fern -->
# Installation

Expand All @@ -35,117 +25,6 @@ client := goclient.NewClient(goclient.WithAuthApiKey("<YOUR_AUTH_TOKEN>"))
```
<!-- End Usage -->

## Access Codes

```go
import goclient "github.com/seamapi/go/client"

client := goclient.NewClient(goclient.WithAuthApiKey("<YOUR_AUTH_TOKEN>"))
accessCode, err := client.AccessCodes.Create(
context.TODO(),
&seamgo.AccessCodesCreateRequest{
DeviceId: someDevice.DeviceId,
Name: seamgo.String("Test code"),
Code: seamgo.String("4444"),
},
)
```

## Timeouts

Setting a timeout for each individual request is as simple as using the standard
`context` library. Setting a one second timeout for an individual API call looks
like the following:

```go
import seamgo "github.com/seamapi/go"

ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

devices, err = client.Devices.List(
ctx,
&seamgo.DevicesListRequest{
DeviceType: seamgo.DeviceTypeAugustLock.Ptr(),
},
)
```

## Client Options

A variety of client options are included to adapt the behavior of the library, which includes
configuring authorization tokens to be sent on every request, or providing your own instrumented
`*http.Client`. Both of these options are shown below:

```go
client := goclient.NewClient(
goclient.WithAuthApiKey("<YOUR_AUTH_TOKEN>"),
goclient.WithHTTPClient(
&http.Client{
Timeout: 5 * time.Second,
},
),
)
```

> Providing your own `*http.Client` is recommended. Otherwise, the `http.DefaultClient` will be used,
> and your client will wait indefinitely for a response (unless the per-request, context-based timeout
> is used).
## Errors

Structured error types are returned from API calls that return non-success status codes. For example,
you can check if the error was due to a bad request (i.e. status code 400) with the following:

```go
accessCode, err := client.AccessCodes.Create(
context.TODO(),
&seamgo.AccessCodesCreateRequest{
Name: seamgo.String("Bad Request"),
},
)
if err != nil {
if badRequestErr, ok := err.(*seamgo.BadRequestError);
// Do something with the bad request ...
}
return err
}
```

These errors are also compatible with the `errors.Is` and `errors.As` APIs, so you can access the error
like so:

```go
accessCode, err := client.AccessCodes.Create(
context.TODO(),
&seamgo.AccessCodesCreateRequest{
Name: seamgo.String("Bad Request"),
},
)
if err != nil {
var badRequestErr *seamgo.BadRequestError
if errors.As(err, badRequestErr) {
// Do something with the bad request ...
}
return err
}
```

If you'd like to wrap the errors with additional information and still retain the ability to access the type
with `errors.Is` and `errors.As`, you can use the `%w` directive:

```go
accessCode, err := client.AccessCodes.Create(
context.TODO(),
&seamgo.AccessCodesCreateRequest{
Name: seamgo.String("Bad Request"),
},
)
if err != nil {
return fmt.Errorf("failed to create access code: %w", err)
}
```

<!-- Begin Status, generated by Fern -->
# Beta Status

Expand Down
2 changes: 1 addition & 1 deletion core/client_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ func (c *ClientOptions) cloneHeader() http.Header {
headers := c.HTTPHeader.Clone()
headers.Set("X-Fern-Language", "Go")
headers.Set("X-Fern-SDK-Name", "github.com/seamapi/go")
headers.Set("X-Fern-SDK-Version", "0.1.0")
headers.Set("X-Fern-SDK-Version", "0.1.1")
return headers
}

0 comments on commit b075d3f

Please sign in to comment.