Categorygithub.com/gocancel/gocancel-go
modulepackage
0.5.1
Repository: https://github.com/gocancel/gocancel-go.git
Documentation: pkg.go.dev

# README

gocancel-go

Build Status GoDoc

gocancel-go is a Go client library for accessing the GoCancel API.

You can view the client API docs here: http://godoc.org/github.com/gocancel/gocancel-go.

You can view the GoCancel API docs here: https://app.gocxl.com/docs.

Installation

gocancel-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/gocancel/gocancel-go

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/gocancel/gocancel-go"

and run go get without parameters.

Usage

import "github.com/gocancel/gocancel-go"

Construct a new client, then use the various services on the client to access different parts of the GoCancel API. For example:

client := gocancel.NewClient(nil)

// list all organizations.
organizations, _, err := client.Organizations.List(context.Background(), nil)

Authentication

The gocancel-go library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you. The easiest and recommended way to do this is using the oauth2 library, but you can always use any other library that provides an http.Client. If you have a OAuth2 client ID and client secret, you can use it with the oauth2 library using:

import (
  "github.com/gocancel/gocancel-go"
  "golang.org/x/oauth2/clientcredentials"
)

func main() {
	ctx := context.Background()

	conf := &clientcredentials.Config{
		ClientID:     "... your client id ...",
		ClientSecret: "... your client secret ...",
		Scopes:       []string{"read:categories"},
		TokenURL:     gocancel.Endpoint.TokenURL,
	}
	tc := conf.Client(ctx)

	client := gocancel.NewClient(tc)

	// list all categories
	categories, _, err := client.Categories.List(ctx)
}

Note that when using an authenticated Client, all calls made by the client will include the specified OAuth client credentials. Therefore, authenticated clients should almost never be shared between different accounts.

See the oauth2 docs for complete instructions on using that library.

Testing

The API client found in gocancel-go is HTTP based. Interactions with the HTTP API can be faked by serving up your own in-memory server within your test. One benefit of using this approach is that you don’t need to define an interface in your runtime code; you can keep using the concrete struct types returned by the client library.

To fake HTTP interactions we can make use of the httptest package found in the standard library. The server URL obtained from creating the test server can be passed to the client struct by overriding the BaseURL field. This instructs the client to route all traffic to your test server rather than the live API. Here is an example of what doing this looks like:

import (
  "fmt"
  "net/http"
  "net/http/httptest"
  "net/url"

  "github.com/gocancel/gocancel-go"
)

// mux is the HTTP request multiplexer used with the test server.
mux := http.NewServeMux()

mux.HandleFunc("/api/v1/categories/foo", func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, `{"id":"foo"}`)
})

mux.HandleFunc("/api/v1/organizations/bar", func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, `{"id":"bar"}`)
})

// ts is a test HTTP server used to provide mock API responses.
ts := httptest.NewServer(mux)
defer ts.Close()

// client is the GoCancel client being tested.
client := gocancel.NewClient(nil)
url, _ := url.Parse(server.URL + "/")
// Pass the test server's URL to the API client.
client.BaseURL = url

# Packages

No description provided by the author

# Functions

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
CheckResponse checks the API response for errors, and returns them if present.
Int is a helper routine that allocates a new int value to store v and returns a pointer to it.
Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.
Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.
New returns a new GoCancel API client instance.
NewClient returns a new GoCancel API client.
SetBaseURL is a client option for setting the base URL.
SetRequestHeaders sets optional HTTP headers on the client that are sent on each HTTP request.
SetUserAgent is a client option for setting the user agent.
String is a helper routine that allocates a new string value to store v and returns a pointer to it.
Stringify attempts to create a reasonable string representation of types in the GoCancel API library.

# Variables

Endpoint is GoCancel's OAuth 2.0 default endpoint.

# Structs

Account represents a GoCancel account.
Address represents an embeddable address.
No description provided by the author
No description provided by the author
Category represents a GoCancel category.
CategoryLocale represents the localized variant of the category.
CategoryProvider represents the provider of the category.
A Client manages communication with the GoCancel API.
Error is the response returned when a call is unsuccessful.
Letter represents a GoCancel letter.
LetterRequest represents a base request for creating or updating a letter.
No description provided by the author
No description provided by the author
LetterTemplate represents an embeddable letter template.
No description provided by the author
No description provided by the author
MarkLetterAsDraftedRequest represents a `mark letter as drafted` request.
Metadata represents the cursors for list responses.
Organization represents a GoCancel organization.
OrganizationLocale represents the localized variant of the organization.
No description provided by the author
No description provided by the author
OrganizationProvider represents the provider of the organization.
No description provided by the author
No description provided by the author
Product represents a product of an organization.
ProductLocale represents the localized variant of the product.
ProductProvider represents the provider of the product.
No description provided by the author
Provider represents a GoCancel provider.
No description provided by the author
No description provided by the author
No description provided by the author
Response is a GoCancel API response.
Timestamp represents a time that can be unmarshalled from a JSON string formatted as an RFC3339 timestamp.
Webhook represents a GoCancel webhook.
WebhooksListOptions specifies the optional parameters to the WebhooksService.List method.
No description provided by the author

# Type aliases

AccountMetadata represents key-value attributes for a specific account.
AccountsService provides access to the account related functions in the GoCancel API.
CategoriesService provides access to the category related functions in the GoCancel API.
ClientOpt are options for New.
LetterParameters represents key-value parameters for a letter.
LettersService provides access to the letter related functions in the GoCancel API.
OrganizationsService provides access to the organization related functions in the GoCancel API.
ProductsService provides access to the product related functions in the GoCancel API.
No description provided by the author
ProvidersService provides access to the provider related functions in the GoCancel API.
WebhooksService provides access to the webhook related functions in the GoCancel API.