Categorygithub.com/thedadams/gotion
modulepackage
0.0.0-20210919194826-9aa71bcd68b7
Repository: https://github.com/thedadams/gotion.git
Documentation: pkg.go.dev

# README

gotion

⛔ WARNING: This is a work in progress! There are no gaurantees until the package reaches v1.0.0 ⛔

Go Reference Go Report Card Maintainability Test Coverage

Go client for the Official Notion API. The goal of this project is to provide type-safety to the Notion API. Instead of page/database properties being interface{} in Go, this project tries to provide safety by having custom (un)marshal methods for the types to transition from Go-like code to the Javascript-type code that is compatible with the Notion API.

There are also some helper functions in the client that will get a page and its children from the Notion API in one call. Also, since Notion has a maximum page size for paginated requests, gotion can make multiple requests to get all results from a paginated request. Never fear: gotion is rate-limited so you won't overwhelm the Notion API.

Installation

go get github.com/thedadams/gotion

Getting started

To obtain an API key, follow Notion’s getting started guide.

Code example

import (
    "context"

    "github.com/thedadams/gotion"
)

func main() {
    client := gotion.NewClient("api-key")
    
    page, err := client.GetPage(context.Background(), "page-id")
    if err != nil {
        // Handler error
    }

    for _, prop := range page.Properties {
        fmt.Printf("Prop name %s with type %s\n", prop.Name, prop.Type)
    }

    page, err = client.GetPageAndChildren(context.Background(), "page-id")
    if err != nil {
        // Handle error
    }
    // Use page
}

Status

All the basic methods (and some helpers) are implemented to enble communciation with the Notion API with one excpetion (see next section).

  • GetPage
  • GetPageAndChildren
  • UpdatePageProperties
  • CreatePage
  • GetDatabae
  • GetDatabases
  • GetDatabaseAndChildren
  • GetBlockChildren
  • AppendBlockChildren
  • QueryDatabase
  • Search

TODO

  • Add basic examples
  • Nested Compound filters
  • Github Actions
  • Unit tests
  • Integration tests

# Packages

No description provided by the author

# Functions

NewClient creates a new gotion client to use with the API.
WithAPIVersion uses the given Notion API version with the gotion client.
WithBackoffStrategy applies the given backoff strategy to the gotion client.
WithMaxRetries sets the maximum number of retries for the gotion client.
WithoutRetryOnHTTP429 sets the gotion client to NOT retry on 429 errors.
WithPesterClient uses the given pester client for the gotion client.
WithRateLimiter users the given rate limiter with the gotion client.
WithRetryOnHTTP429 sets the gotion client to retry on 429 errors.
WithSettings uses the given settings with the gotion client.
WithTimeout sets the timeout parameter for the gotion client.
WithToken uses the given auth token with the gotion client.
WithUserAgent uses the given user agent string with the gotion client.

# Structs

Client is a client used to make calls to the Notion API.
DBQuery represents the parameters needed to query a database in the Notion API.
A Result is a response from the Notion API when getting more than one thing back (i.e.
SearchQuery represents the body needed to search the Notion API.
SearchResults represent the returned results from searching the Notion API.

# Type aliases

An Option is a way of customizing the gotion client.