jsonbank

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 9 Imported by: 0

README

Jsonbank.io GoLang SDK

The official repository for jsonbank.io GoLang SDK.

Installation

go get github.com/jsonbankio/go-sdk

Usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/jsonbankio/go-sdk"
)

func main() {
	// Initialize the client
	jsb := jsonbank.InitWithoutKeys()

	// Get Public content
	content, err := jsb.GetContent("jsonbank/sdk-test/index.json")
	if err != nil {
		panic(err)
	}

	// convert to json string
	jsonData, _ := json.MarshalIndent(content, "", "  ")

	fmt.Println(string(jsonData))
}
Authenticated Requests
package main

import (
	"encoding/json"
	"fmt"
	"github.com/jsonbankio/go-sdk"
	"github.com/jsonbankio/go-sdk/types"
)

func main() {
	// Initialize the client
	jsb := jsonbank.Init(jsonbank.Config{
		Keys: jsonbank.Keys{
			Public:  "your public key",
			Private: "your private key",
		},
	})

	// Authenticate to check if the keys are valid
	authenticate, err := jsb.Authenticate()
	if err != nil {
		fmt.Println(err)
	}

	// Print authenticated user
	fmt.Println("Authenticated as: ", authenticate.Username)

	// Get Own content
	content, err := jsb.GetOwnContent("sdk-test/index.json")
	if err != nil {
		panic(err)
	}

	// convert to json string
	jsonData, _ := json.MarshalIndent(content, "", "  ")

	fmt.Println(string(jsonData))
}
Testing

Create an .env file in the root of the project and add the following variables

JSB_HOST="https://api.jsonbank.io"
JSB_PUBLIC_KEY="your public key"
JSB_PRIVATE_KEY="your private key"

Then run the tests

go test -v

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidJsonError = RequestError{"invalid_json_content", "Content is not a valid JSON string"}

Functions

func IsValidJsonString

func IsValidJsonString(s string) bool

IsValidJsonString - check if a string is a valid json string

func JsonToReader

func JsonToReader(s any) io.Reader

JsonToReader - convert json string to io.Reader

func MakeDocumentPath

func MakeDocumentPath(document types.CreateDocumentBody) string

MakeDocumentPath - generate a document full path

func MakeFolderPath added in v0.1.5

func MakeFolderPath(folder types.CreateFolderBody) string

MakeFolderPath - generate a folder full path

Types

type Config

type Config struct {
	Host string // Server Host
	Keys Keys   // Keys
}

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

func Init

func Init(config Config) Instance

Init - initializes the jsonbank instance

func InitWithoutKeys

func InitWithoutKeys() Instance

InitWithoutKeys - initializes the jsonbank instance without Keys

func (*Instance) Authenticate

func (jsb *Instance) Authenticate() (*types.AuthenticatedData, *RequestError)

Authenticate - authenticates the jsonbank instance

func (*Instance) Authenticated

func (jsb *Instance) Authenticated() bool

Authenticated - checks if the jsonbank instance is authenticated

func (*Instance) CreateDocument

func (jsb *Instance) CreateDocument(document types.CreateDocumentBody) (*types.NewDocument, *RequestError)

CreateDocument - creates a document

func (*Instance) CreateDocumentIfNotExists

func (jsb *Instance) CreateDocumentIfNotExists(document types.CreateDocumentBody) (*types.NewDocument, *RequestError)

CreateDocumentIfNotExists - creates a document if it does not exist

func (*Instance) CreateFolder

func (jsb *Instance) CreateFolder(body types.CreateFolderBody) (*types.NewFolder, *RequestError)

CreateFolder - creates a folder

func (*Instance) CreateFolderIfNotExists added in v0.1.5

func (jsb *Instance) CreateFolderIfNotExists(body types.CreateFolderBody) (*types.NewFolder, *RequestError)

CreateFolderIfNotExists - creates a folder if it does not exist try to create the folder, if it exists then fetch the folder

func (*Instance) DeleteDocument

func (jsb *Instance) DeleteDocument(idOrPath string) (*types.DeletedDocument, *RequestError)

DeleteDocument - deletes a document

func (*Instance) GetContent added in v0.1.1

func (jsb *Instance) GetContent(idOrPath string) (any, *RequestError)

GetContent - get public content from jsonbank

func (*Instance) GetContentAsString added in v0.1.7

func (jsb *Instance) GetContentAsString(idOrPath string) (string, *RequestError)

GetContentAsString - get public content from jsonbank as string

func (*Instance) GetDocumentMeta added in v0.1.1

func (jsb *Instance) GetDocumentMeta(idOrPath string) (*types.DocumentMeta, *RequestError)

GetDocumentMeta - get public document meta

func (*Instance) GetFolder added in v0.1.5

func (jsb *Instance) GetFolder(idOrPath string) (*types.Folder, *RequestError)

GetFolder - gets a folder

func (*Instance) GetFolderWithStats added in v0.1.5

func (jsb *Instance) GetFolderWithStats(idOrPath string) (*types.Folder, *RequestError)

GetFolderWithStats - gets a folder with stats

func (*Instance) GetGithubContent added in v0.1.1

func (jsb *Instance) GetGithubContent(path string) (any, *RequestError)

GetGithubContent - get public content from GitHub

func (*Instance) GetGithubContentAsString added in v0.1.7

func (jsb *Instance) GetGithubContentAsString(path string) (string, *RequestError)

GetGithubContentAsString - get public content from GitHub as string

func (*Instance) GetOwnContent

func (jsb *Instance) GetOwnContent(idOrPath string) (any, *RequestError)

GetOwnContent - gets the content of a document owned by the authenticated user

func (*Instance) GetOwnContentAsString added in v0.1.7

func (jsb *Instance) GetOwnContentAsString(idOrPath string) (string, *RequestError)

GetOwnContentAsString - gets the content of a document owned by the authenticated user as string

func (*Instance) GetOwnDocumentMeta

func (jsb *Instance) GetOwnDocumentMeta(idOrPath string) (*types.DocumentMeta, *RequestError)

GetOwnDocumentMeta - gets the content meta of the authenticated user

func (*Instance) GetUsername

func (jsb *Instance) GetUsername() string

GetUsername - gets the username of the authenticated user

func (*Instance) HasOwnDocument

func (jsb *Instance) HasOwnDocument(idOrPath string) bool

HasOwnDocument - tries to get the content then returns true if it exists

func (*Instance) SetHost added in v0.1.1

func (jsb *Instance) SetHost(host string)

SetHost - switch the host of the instance

func (*Instance) UpdateOwnDocument

func (jsb *Instance) UpdateOwnDocument(idOrPath string, content string) (*types.UpdatedDocument, *RequestError)

UpdateOwnDocument - Update document owned by the authenticated user

func (*Instance) UploadDocument

func (jsb *Instance) UploadDocument(document types.UploadDocumentBody) (*types.NewDocument, *RequestError)

UploadDocument - uploads a json document

type Keys

type Keys struct {
	Public  string // Public Key
	Private string // Private Key
}

type RequestError

type RequestError struct {
	Code    string
	Message string
}

func (*RequestError) Error

func (error *RequestError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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