userkit

package module
v0.0.0-...-29d105c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2018 License: MIT Imports: 4 Imported by: 2

README

Go UserKit

Summary

An experimental UserKit client library for Go. NOTE: May be missing some features or be updated with breaking changes.

Installation

go get github.com/workpail/userkit-go

Documentation

For full examples and docs checkout UserKit documentation.

Example usage

package main

import (
	"fmt"

	userkit "github.com/workpail/userkit-go"
)

func main() {
	uk := userkit.NewUserKit("<YOUR_APP_SECRET_KEY>")

	// create a user
	data := map[string]string{
		"email":    "jane.smith@example.com",
		"password": "secretpass"}

	user, err := uk.Users.Create(data)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("USER: %+v\n", user)

	// fetch a user
	user, _ = uk.Users.Get("usr_j3LB5QPAH8B9UD")

	// update a user
	upData := map[string]string{"name": "Jane Smith"}
	user, _ = uk.Users.Update("usr_j3LB5QPAH8B9UD", upData)

	// login a user
	session, _ := uk.Users.Login("jane.smith@example.com", "secretpass", "")

	// fetch a logged-in user by their session-token
	user, err = uk.Users.GetUserBySession(session.Token)
	if err != nil {
		if err.(userkit.Error).Type == "user_authentication_error" {
			fmt.Println("No logged in user (ask visitor to login)")
		} else {
			fmt.Printf("Some other error: %s\n", err)
		}
		return
	}
	fmt.Printf("Logged in user: %+v\n", user)
}

Running tests

To run tests you need to create a test-app.

Set the USERKIT_KEY environment variable to your test app key, then run go test:

USERKIT_KEY=<YOUR_APP_SECRET_KEY> go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// resources
	Users *usersClient
	// contains filtered or unexported fields
}

Client is a UserKit client through which sub-resources can be accessed

func NewUserKit

func NewUserKit(apiKey string) Client

NewUserKit creates a new client

type CoreError

type CoreError struct {
	Type      string  `json:"type"`
	Code      string  `json:"code"`
	Message   string  `json:"message"`
	RetryWait float64 `json:"retry_wait"`
	Param     string  `json:"param"`
}

CoreError is a base UserKit exception

func (CoreError) Error

func (e CoreError) Error() string

type Error

type Error struct {
	CoreError
	Errors []CoreError
}

Error is what developers should usually expect to handle when using this SDK. It contains an Errors property which is populated with a list of CoreError's when hitting an endpoint which can return multiple errors.

type Requestor

type Requestor struct {
	APIKey string
}

Requestor holds info needed to make an authenticated request to the UserKit API endpoints.

func (*Requestor) Do

func (ukrequest *Requestor) Do(method, url string, payload interface{},
	sessionToken *string) (*UKResponse, error)

Do makes an authenticated request to the UserKit api. payload will be sent as a json request body. Some requests (such as to the users/by_token endpoint) require a sessionToken parameter.

type Session

type Session struct {
	Token            string  `json:"token"`
	ExpiresInSecs    float64 `json:"expires_in_secs"`
	RefreshAfterSecs float64 `json:"refresh_after_secs"`
}

Session represents a UserKit user session

type UKResponse

type UKResponse struct {
	StatusCode int
	Body       []byte
}

UKResponse holds the data from a http response. We need this so that the Do helper method can close the response.Body.

type User

type User struct {
	ID              string  `json:"id"`
	Name            string  `json:"name"`
	Username        string  `json:"username"`
	Email           string  `json:"email"`
	VerifiedEmail   string  `json:"verified_email"`
	VerifiedPhone   string  `json:"verified_phone"`
	AuthType        string  `json:"auth_type"`
	LastFailedLogin float64 `json:"last_failed_login"`
	LastLogin       float64 `json:"last_login"`
	Disabled        bool    `json:"disabled"`
	Created         float64 `json:"created"`
}

User is represents a UserKit User object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL