api

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const APIKeyHeader = "x-api-key"

Variables

View Source
var (
	ErrInternal     = fmt.Errorf("internal error")
	ErrUnauthorized = fmt.Errorf("unauthorized")
)

Functions

This section is empty.

Types

type API

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

func New

func New(cfg Config) (*API, error)

func (*API) Authentication

func (a *API) Authentication(ctx context.Context, req AuthRequest) (*AuthenticationResponse, error)

func (*API) Check

func (a *API) Check(ctx context.Context, req CheckRequest) (*CheckResponse, error)

func (*API) Retry

func (a *API) Retry(ctx context.Context, req RetryRequest) (*RetryResponse, error)

type AuthRequest

type AuthRequest struct {
	PhoneNumber     string  `json:"phone_number,omitempty"`
	CustomerUUID    string  `json:"customer_uuid,omitempty"`
	IP              *string `json:"ip,omitempty"`
	DeviceID        *string `json:"device_id,omitempty"`
	DeviceType      *string `json:"device_type,omitempty"`
	AppVersion      *string `json:"app_version,omitempty"`
	CallbackURL     *string `json:"callback_url,omitempty"`
	IsReturningUser *bool   `json:"is_returning_user,omitempty"`
}

type AuthSuccessResponse

type AuthSuccessResponse struct {
	AuthenticationUUID string      `json:"authentication_uuid"`
	Status             status.Auth `json:"status"`
	CreatedAt          time.Time   `json:"created_at"`
	ExpiresAt          time.Time   `json:"expires_at"`
}

type AuthenticationResponse

type AuthenticationResponse struct {
	Error   *ErrorResponse
	Success *AuthSuccessResponse
}

TODO(2024-25) -> abstract each endpoint parsing logic using generics

type CheckRequest

type CheckRequest struct {
	CustomerUUID       string `json:"customer_uuid"`
	AuthenticationUUID string `json:"authentication_uuid"`
	CheckCode          string `json:"check_code"`
}

type CheckResponse

type CheckResponse struct {
	Error   *ErrorResponse
	Success *CheckSuccessResponse
}

type CheckSuccessResponse

type CheckSuccessResponse struct {
	AuthenticationUUID string       `json:"authentication_uuid"`
	Status             status.Check `json:"status"`
}

type Config

type Config struct {
	BaseURL           string
	APIKey            string
	MaxNetworkRetries *int
	CustomHTTPClient  *http.Client
	LeveledLogger     LeveledLogger
}

type ErrorCode

type ErrorCode string
const (
	ErrorCodeInternalServer     ErrorCode = "internal_server_error"
	ErrorCodeBadRequest         ErrorCode = "bad_request"
	ErrorCodeInvalidPhoneNumber ErrorCode = "invalid_phone_number"
	ErrorCodeAccountInvalid     ErrorCode = "account_invalid"
	ErrorCodeNegativeBalance    ErrorCode = "negative_balance"
	ErrorCodeInvalidLine        ErrorCode = "invalid_line"
	ErrorCodeUnsupportedRegion  ErrorCode = "unsupported_region"
	ErrorCodeInvalidAuthUUID    ErrorCode = "invalid_auth_uuid"
)

type ErrorResponse

type ErrorResponse struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
	DocURL  string    `json:"doc_url"`
}

type GatewayErrorMessage

type GatewayErrorMessage struct {
	Message string `json:"message"`
}

type LeveledLogger added in v1.1.0

type LeveledLogger interface {
	Debugf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
}

LeveledLogger is an interface that can be implemented by any logger or a logger wrapper to provide leveled logging. The methods accept a message string and a variadic number of key-value pairs.

type RetryRequest

type RetryRequest struct {
	CustomerUUID       string `json:"customer_uuid"`
	AuthenticationUUID string `json:"authentication_uuid"`
}

type RetryResponse

type RetryResponse struct {
	Error   *ErrorResponse
	Success *RetrySuccessResponse
}

type RetrySuccessResponse

type RetrySuccessResponse struct {
	AuthenticationUUID string       `json:"authentication_uuid"`
	Status             status.Retry `json:"status"`
	CreatedAt          time.Time    `json:"created_at"`
	NextRetryAt        time.Time    `json:"next_retry_at"`
	RemainingRetry     int          `json:"remaining_retry"`
}

Jump to

Keyboard shortcuts

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