api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotAllowed

func NotAllowed(c *gin.Context)

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c *gin.Context)

NotFound returns a JSON 404 response for the API.

Types

type APIv1

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

APIv1 implements the EpistolaryClient interface.

func (*APIv1) CreateReading

func (s *APIv1) CreateReading(ctx context.Context, in *Reading) (out *Reading, err error)

func (*APIv1) DeleteReading

func (s *APIv1) DeleteReading(ctx context.Context, id int64) (err error)

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes the response data into the specified struct if requested.

func (*APIv1) FetchReading

func (s *APIv1) FetchReading(ctx context.Context, id int64) (out *Reading, err error)

func (*APIv1) ListReadings

func (s *APIv1) ListReadings(ctx context.Context, in *PageQuery) (out *ReadingPage, err error)

func (*APIv1) Login

func (s *APIv1) Login(ctx context.Context, in *LoginRequest) (out *LoginReply, err error)

func (*APIv1) Logout added in v0.3.0

func (s *APIv1) Logout(ctx context.Context) (err error)

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

NewRequest creates an http.Request with the specified context and method, resolving the path to the root endpoint of the API (e.g. /v1) and serializes the data to JSON. This method also sets the default headers of all Persona v1 client requests.

func (*APIv1) Register

func (s *APIv1) Register(ctx context.Context, in *RegisterRequest) (err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context) (out *StatusReply, err error)

func (*APIv1) UpdateReading

func (s *APIv1) UpdateReading(ctx context.Context, in *Reading) (out *Reading, err error)

type EpistolaryClient

type EpistolaryClient interface {
	Register(context.Context, *RegisterRequest) error
	Login(context.Context, *LoginRequest) (*LoginReply, error)
	Logout(context.Context) error
	Status(context.Context) (*StatusReply, error)

	ListReadings(context.Context, *PageQuery) (*ReadingPage, error)
	CreateReading(context.Context, *Reading) (*Reading, error)
	FetchReading(_ context.Context, id int64) (*Reading, error)
	UpdateReading(context.Context, *Reading) (*Reading, error)
	DeleteReading(_ context.Context, id int64) error
}

func New

func New(endpoint string) (_ EpistolaryClient, err error)

New creates a new api.v1 API client that implements the EpistolaryClient interface.

type LoginReply

type LoginReply struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type OpenIDConfiguration

type OpenIDConfiguration struct {
	Issuer                        string   `json:"issuer"`
	AuthorizationEP               string   `json:"authorization_endpoint"`
	TokenEP                       string   `json:"token_endpoint"`
	DeviceAuthorizationEP         string   `json:"device_authorization_endpoint"`
	UserInfoEP                    string   `json:"userinfo_endpoint"`
	MFAChallengeEP                string   `json:"mfa_challenge_endpoint"`
	JWKSURI                       string   `json:"jwks_uri"`
	RegistrationEP                string   `json:"registration_endpoint"`
	RevocationEP                  string   `json:"revocation_endpoint"`
	ScopesSupported               []string `json:"scopes_supported"`
	ResponseTypesSupported        []string `json:"response_types_supported"`
	CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
	ResponseModesSupported        []string `json:"response_modes_supported"`
	SubjectTypesSupported         []string `json:"subject_types_supported"`
	IDTokenSigningAlgValues       []string `json:"id_token_signing_alg_values_supported"`
	TokenEndpointAuthMethods      []string `json:"token_endpoint_auth_methods_supported"`
	ClaimsSupported               []string `json:"claims_supported"`
	RequestURIParameterSupported  bool     `json:"request_uri_parameter_supported"`
}

type PageQuery

type PageQuery struct {
	PageSize  uint64 `url:"page_size,omitempty" form:"page_size" json:"page_size,omitempty"`
	PageToken string `url:"page_token,omitempty" form:"page_token" json:"page_token,omitempty"`
}

PageQuery allows the user to request the next or previous page from a given cursor.

type Reading

type Reading struct {
	ID          int64     `json:"id,omitempty"`
	Status      string    `json:"status,omitempty"`
	Link        string    `json:"link"`
	Title       string    `json:"title,omitempty"`
	Description string    `json:"description,omitempty"`
	Favicon     string    `json:"favicon,omitempty"`
	Started     Timestamp `json:"started,omitempty"`
	Finished    Timestamp `json:"finished,omitempty"`
	Archived    Timestamp `json:"archived,omitempty"`
	Created     Timestamp `json:"created,omitempty"`
	Modified    Timestamp `json:"modified,omitempty"`
}

type ReadingPage

type ReadingPage struct {
	Readings      []*Reading `json:"readings"`
	NextPageToken string     `json:"next_page_token"`
	PrevPageToken string     `json:"prev_page_token"`
}

type RegisterRequest

type RegisterRequest struct {
	FullName string `json:"full_name"`
	Email    string `json:"email"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty" yaml:"error,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func ErrorResponse

func ErrorResponse(err interface{}) Reply

ErrorResponse constructs an new response from the error or returns a success: false.

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

StatusReply is returned on status requests. Note that no request is needed.

type Timestamp added in v0.3.0

type Timestamp struct {
	time.Time
}

func (Timestamp) MarshalJSON added in v0.3.0

func (t Timestamp) MarshalJSON() ([]byte, error)

func (Timestamp) ToSQL added in v1.0.0

func (t Timestamp) ToSQL() sql.NullTime

func (*Timestamp) UnmarshalJSON added in v1.0.0

func (t *Timestamp) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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