sdk

package module
v0.0.0-...-c013c52 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 10 Imported by: 0

README

Durudex SDK

Setup

go get github.com/durudex/durudex-go/sdk

Documentation

Index

Constants

View Source
const (
	// Durudex test API url.
	TestAPIEndpoint string = "https://api.test.durudex.com/query"

	// Default non-auth HTTP client transport type.
	DefaultTransportType TransportType = iota
	// Auth HTTP client transport type.
	AuthTransportType

	// Bearer authorization token type.
	BearerTokenType TokenType = "Bearer"
)

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Returns pointer on you value.

Types

type AuthConfig

type AuthConfig struct {
	// Refresh token.
	Refresh string
	// Client secret key.
	Secret string
	// Authorization token type.
	TokenType TokenType
	// Refresh token TTL.
	RefreshTTL time.Duration
}

Authorization client config.

type AuthTransport

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

Auth client transport.

func NewAuthTransport

func NewAuthTransport() *AuthTransport

Creating a new auth transport.

func (*AuthTransport) RoundTrip

func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

Executing auth HTTP transaction.

func (*AuthTransport) SetAccessToken

func (t *AuthTransport) SetAccessToken(access string)

Sets authorization access token.

type Client

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

Durudex API client.

func NewClient

func NewClient(cfg ClientConfig) *Client

Creating a new Durudex API client.

func (*Client) CreatePost

func (c *Client) CreatePost(ctx context.Context, input types.CreatePostInput) (ksuid.KSUID, error)

Creating a new post.

func (*Client) DeletePost

func (c *Client) DeletePost(ctx context.Context, id ksuid.KSUID) (bool, error)

Deleting a post.

func (*Client) DeleteSession

func (c *Client) DeleteSession(ctx context.Context, id ksuid.KSUID) (bool, error)

Deleting a user session.

func (*Client) ForgotPassword

func (c *Client) ForgotPassword(ctx context.Context, input types.ForgotPasswordInput) (bool, error)

Forgot a user password.

func (*Client) GetMe

func (c *Client) GetMe(ctx context.Context) (User, error)

Getting a me.

func (*Client) GetPost

func (c *Client) GetPost(ctx context.Context, id ksuid.KSUID) (*types.Post, error)

Getting a post.

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, id ksuid.KSUID) (*types.Session, error)

Getting a user session.

func (*Client) GetSessionsEdges

func (c *Client) GetSessionsEdges(ctx context.Context, sort types.SortOptions) ([]*types.SessionEdge, error)

Getting a user sessions edges.

func (*Client) GetSessionsNodes

func (c *Client) GetSessionsNodes(ctx context.Context, sort types.SortOptions) ([]*types.Session, error)

Getting a user sessions nodes.

func (*Client) GetTotalSessionsCount

func (c *Client) GetTotalSessionsCount(ctx context.Context) (int, error)

Getting a total user sessions count.

func (*Client) GetTotalUserPostsCount

func (c *Client) GetTotalUserPostsCount(ctx context.Context, uid ksuid.KSUID) (int, error)

Getting a total user posts count.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, id ksuid.KSUID) (User, error)

Getting a user.

func (*Client) GetUserPostsEdges

func (c *Client) GetUserPostsEdges(ctx context.Context, uid ksuid.KSUID, sort types.SortOptions) ([]*types.PostEdge, error)

Getting a user posts edges.

func (*Client) GetUserPostsNodes

func (c *Client) GetUserPostsNodes(ctx context.Context, uid ksuid.KSUID, sort types.SortOptions) ([]*types.Post, error)

Getting a user posts nodes.

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx context.Context, req *graphql.Request, resp *graphql.Response) error

Making a client request to GraphQL API.

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context, input types.SessionCredInput) (string, error)

Refresh authorization token.

func (*Client) SignIn

func (c *Client) SignIn(ctx context.Context, input types.SignInInput) (types.Tokens, error)

User Sign In.

func (*Client) SignUp

func (c *Client) SignUp(ctx context.Context, input types.SignUpInput) (types.Tokens, error)

User Sign Up.

func (*Client) UpdatePost

func (c *Client) UpdatePost(ctx context.Context, input types.UpdatePostInput) (bool, error)

Updating a post.

type ClientConfig

type ClientConfig struct {
	// API endpoint.
	Endpoint string
	// HTTP client transport type.
	TransportType TransportType
	// HTTP client transport.
	Transport Transport
	// Authorization client config.
	AuthConfig *AuthConfig
	// Client logger.
	Logger Logger
}

Durudex API client config.

type DefaultClientLogger

type DefaultClientLogger struct{}

Default client logger.

func (*DefaultClientLogger) Debug

func (l *DefaultClientLogger) Debug(msg string)

Debug client log message.

func (*DefaultClientLogger) Error

func (l *DefaultClientLogger) Error(msg string)

Error client log message.

func (*DefaultClientLogger) Fatal

func (l *DefaultClientLogger) Fatal(msg string)

Fatal client log message.

func (*DefaultClientLogger) Info

func (l *DefaultClientLogger) Info(msg string)

Info client log message.

type DefaultTransport

type DefaultTransport struct{}

Default non-auth client transport.

func NewDefaultTransport

func NewDefaultTransport() *DefaultTransport

Creating a new default non-auth client transport.

func (*DefaultTransport) RoundTrip

func (t *DefaultTransport) RoundTrip(req *http.Request) (*http.Response, error)

Executing HTTP transaction.

func (*DefaultTransport) SetAccessToken

func (t *DefaultTransport) SetAccessToken(access string)

Sets authorization access token.

type Logger

type Logger interface {
	// Debug client log message.
	Debug(msg string)
	// Info client log message.
	Info(msg string)
	// Error client log message.
	Error(msg string)
	// Fatal client log message.
	Fatal(msg string)
}

Durudex client logger interface.

var DefaultLogger Logger = &DefaultClientLogger{}

Default client logger.

type TokenType

type TokenType string

Authorization token type.

func (TokenType) String

func (t TokenType) String() string

Getting token type in string.

type Transport

type Transport interface {
	http.RoundTripper

	// Sets authorization access token.
	SetAccessToken(access string)
}

Client transport interface.

type TransportType

type TransportType int

HTTP client transport type.

type User

type User struct {
	*types.User
	// contains filtered or unexported fields
}

User type.

func (User) GetPostsEdges

func (u User) GetPostsEdges(ctx context.Context, sort types.SortOptions) ([]*types.PostEdge, error)

Getting a user posts edges.

func (User) GetPostsNodes

func (u User) GetPostsNodes(ctx context.Context, sort types.SortOptions) ([]*types.Post, error)

Getting a user posts nodes.

func (User) GetTotalPostsCount

func (u User) GetTotalPostsCount(ctx context.Context) (int, error)

Getting a total user posts count.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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