api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	DELETE = "DELETE"
	PUT    = "PUT"
)

HTTP Methods

View Source
const (
	OK              = 200
	MUTIPLE_CHOICES = 300
	BAD_REQUEST     = 400
	NOT_FOUND       = 404
)

Status codes

View Source
const API_KEY_HEADER = "MC-Api-Key"

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

type ApiClient interface {
	Do(request HciRequest) (*HciResponse, error)
	GetApiURL() string
	GetApiKey() string
}

func NewApiClient

func NewApiClient(apiURL, apiKey string) ApiClient

func NewInsecureApiClient

func NewInsecureApiClient(apiURL, apiKey string) ApiClient

type HciApiClient

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

func (HciApiClient) Do

func (hciClient HciApiClient) Do(request HciRequest) (*HciResponse, error)

Does the API call to server and returns a HCIResponse. hci errors will be returned in the HCIResponse body, not in the error return value. The error return value is reserved for unexpected errors.

func (HciApiClient) GetApiKey

func (hciClient HciApiClient) GetApiKey() string

func (HciApiClient) GetApiURL

func (hciClient HciApiClient) GetApiURL() string

type HciError

type HciError struct {
	ErrorCode string                 `json:"errorCode"`
	Message   string                 `json:"message"`
	Context   map[string]interface{} `json:"context"`
}

An API error

type HciErrorResponse

type HciErrorResponse HciResponse

An Api Response with errors

func (HciErrorResponse) Error

func (errorResponse HciErrorResponse) Error() string

type HciRequest

type HciRequest struct {
	Method   string
	Endpoint string
	Body     []byte
	Options  map[string]string
}

A request object

type HciResponse

type HciResponse struct {
	TaskId     string
	TaskStatus string
	StatusCode int
	Data       []byte
	Errors     []HciError
	MetaData   map[string]interface{}
}

An Api Response

func NewHciResponse

func NewHciResponse(response *http.Response) (*HciResponse, error)

func (HciResponse) IsError

func (hciResponse HciResponse) IsError() bool

Returns true if API response has errors

Jump to

Keyboard shortcuts

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