cvvapi

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 20 Imported by: 0

README

cvvapi

Classe Viva GO client

In order to run the tests set the environment variables CVV_USER and CVV_PASSWORD and then run go test

  $env:CVV_USER="username";$env:CVV_PASSWORD="pwd";go test

Documentation

Overview

Package to interact programmatically with the school register ClasseViva by Spaggiari

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

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

func NewApiError

func NewApiError(e error) *ApiError

type BoardItem

type BoardItem struct {
	Id        string
	CreatedAt time.Time
	Type      string
	TypeDesc  string
	Read      bool
	SingleDoc bool
	Detail    *BoardItemDetail
}

Board item descriptor

func (*BoardItem) ExpectAnswer

func (o *BoardItem) ExpectAnswer() bool

Check if an answer is expected for a board item

type BoardItemAnswer

type BoardItemAnswer struct {
	AnswerId string
	TextHint string
}

Board item answer descriptor

type BoardItemDetail

type BoardItemDetail struct {
	Title                  string
	Text                   string
	Attachments            []ItemAttachment
	ExpectConfirmAnswer    BoardItemAnswer
	ExpectTextAnswer       BoardItemTextAnswer
	ExpectAttachmentAnswer BoardItemAnswer
}

Board item detail descriptor

type BoardItemTextAnswer

type BoardItemTextAnswer struct {
	BoardItemAnswer
	Value string
}

Board item text answer descriptor

type Class

type Class struct {
	Id       string
	Name     string
	Grade    int
	Section  string
	Building string
	Course   string
	Owned    bool
	Link     string
}

Class descriptor

type ContentItem

type ContentItem struct {
	Id          string
	Title       string
	FolderId    string
	Attachments []ItemAttachment
}

Message content item descriptor

type CvvDate

type CvvDate time.Time

Date in ClasseViva format

func (CvvDate) MarshalJSON

func (o CvvDate) MarshalJSON() ([]byte, error)

func (*CvvDate) UnmarshalJSON

func (o *CvvDate) UnmarshalJSON(b []byte) error

type CvvDateTime

type CvvDateTime time.Time

Date and time in ClasseViva format

func (CvvDateTime) MarshalJSON

func (o CvvDateTime) MarshalJSON() ([]byte, error)

func (*CvvDateTime) UnmarshalJSON

func (o *CvvDateTime) UnmarshalJSON(b []byte) error

type FileResource

type FileResource struct {
	Name        string
	ContentType string
	Data        []byte
}

Resource obtained as a download from the download resource endpoint

type HttpError

type HttpError struct {
	StatusCode int
	// contains filtered or unexported fields
}

func NewHttpError

func NewHttpError(e error, statusCode int) *HttpError

type HttpHandler

type HttpHandler func(*http.Request) (*http.Response, error)

type HttpMiddleware

type HttpMiddleware func(*http.Request, HttpHandler) (*http.Response, error)

func HttpSnapshoterBuilder

func HttpSnapshoterBuilder(path string, printHash bool) HttpMiddleware

Middleware to obtain a snapshot of a test run. It saves to disk the result of every http request, hashing url and body, and reading the snapshotted response if a corresponding file is found

func MemoryCacheBuilder

func MemoryCacheBuilder(expiration time.Duration) HttpMiddleware

Creates a simple in memory cache for http requests hashing url and body. Usable for testing optimization purposes.

type ItemAttachment

type ItemAttachment struct {
	Id       string
	Title    string
	Url      string
	Link     string
	Resource *FileResource
}

Attachment descriptor, both content and board

type Message

type Message struct {
	Id            string
	Read          bool
	CreatedAt     time.Time
	Sender        string
	Subject       string
	Body          string
	UserLink      string
	BoardItemId   string
	BoardItem     *BoardItem
	ContentItemId string
	ContentItem   *ContentItem
}

Message descriptor

type NetworkError

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

func NewNetworkError

func NewNetworkError(e error) *NetworkError

type NotAuthenticatedError

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

func NewNotAuthenticatedError

func NewNotAuthenticatedError(e error) *NotAuthenticatedError

type PkgConfig

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

Configuration structure accessible through chainable setters

func Config

func Config() *PkgConfig

Expose a handle to the module configuration

func (*PkgConfig) GetClient

func (o *PkgConfig) GetClient() *http.Client

Get an http client from the provider function

func (*PkgConfig) SetClientProvider

func (o *PkgConfig) SetClientProvider(provider func() *http.Client) *PkgConfig

Set the http client provider function. Default shared client

func (*PkgConfig) SetHostname

func (o *PkgConfig) SetHostname(hostname string) *PkgConfig

Set the configured hostname. Default "web.spaggiari.eu"

func (*PkgConfig) SetSessionCheckTimeout

func (o *PkgConfig) SetSessionCheckTimeout(timeout time.Duration) *PkgConfig

Set the timeout of the cvv session. Default 20 minutes

func (*PkgConfig) Use

func (o *PkgConfig) Use(mw HttpMiddleware) *PkgConfig

Add a request middleware to the middleware pipeline. Middlewares are executed in the order in which they are added

type Session

type Session struct {
	Username string
	// contains filtered or unexported fields
}

Session of interaction with ClasseViva. It is able to refresh the session token if necessary.

func NewSession

func NewSession(username string, password string) (*Session, error)

Creates a new Session, storing the necessary information to refresh the token.

func (*Session) AnswerBoardItemWithFile

func (o *Session) AnswerBoardItemWithFile(answerId string, file []byte) error

Answer a call to action with a file

func (*Session) AnswerBoardItemWithText

func (o *Session) AnswerBoardItemWithText(answerId string, text string) error

Answer a call to action with text

func (*Session) CheckActive

func (o *Session) CheckActive() (bool, error)

Check if a session is stil usable Asking ClasseViva website

func (*Session) ConfirmBoardItem

func (o *Session) ConfirmBoardItem(answerId string) error

Answer a simple call to action

func (*Session) EnsureActive

func (o *Session) EnsureActive() error

func (*Session) GetBoardItem

func (o *Session) GetBoardItem(boardItemId string) (*BoardItem, error)

Get a specific board item with its details

func (*Session) GetBoardItems

func (o *Session) GetBoardItems(unreadOnly bool) ([]BoardItem, error)

Get all the available board items.

func (*Session) GetClasses

func (o *Session) GetClasses() ([]Class, error)

Get students of a given class

func (*Session) GetContentItem

func (o *Session) GetContentItem(contentId string) (*ContentItem, error)

Get a content item of a message

func (*Session) GetFileResource

func (o *Session) GetFileResource(resourceUrl string) (*FileResource, error)

func (*Session) GetMessages

func (o *Session) GetMessages(unreadOnly bool, page int, pageSize int) ([]Message, error)

Get own messages

func (*Session) GetStudents

func (o *Session) GetStudents(classId string) ([]Student, error)

Get students of a given class

func (*Session) GetTaughtSubjects

func (o *Session) GetTaughtSubjects() ([]Subject, error)

Get own courses

func (*Session) IsActive

func (o *Session) IsActive() bool

Verify if a session is stil usable

func (*Session) LoadBoardItemAttachments

func (o *Session) LoadBoardItemAttachments(boardItem *BoardItem) error

Load the attachments files of a board item

func (*Session) LoadBoardItemDetails

func (o *Session) LoadBoardItemDetails(boardItem *BoardItem) error

Load the detail of a board item obtained with [GetBoardItems]

func (*Session) LoadContentItemAttachments

func (o *Session) LoadContentItemAttachments(contentItem *ContentItem) error

func (*Session) LoadMessageAttachments

func (o *Session) LoadMessageAttachments(message *Message) error

Load message attachments files

func (*Session) LoadMessageDetails

func (o *Session) LoadMessageDetails(message *Message) error

Load message detail (content or boardItem) if any is present

func (*Session) MarkBoardItemsAsRead

func (o *Session) MarkBoardItemsAsRead(items []BoardItem) error

Mark a slice of items as read

func (*Session) MarkMessagesAsRead

func (o *Session) MarkMessagesAsRead(messages []Message) error

Mark a slice of messages as read

func (*Session) Refresh

func (o *Session) Refresh() error

Refresh the session performing a new login to ClasseViva if necessary.

type Student

type Student struct {
	FullName string
	Names    []string
	Surnames []string
	BirthDay CvvDate
	Status   string // present, absent, late, exited, nolesson
}

Student descriptor

type Subject

type Subject struct {
	Id           string
	Name         string
	ClassId      string
	ClassGrade   int
	ClassName    string
	ClassSection string
	ClassLink    string
}

Subject descriptor

Jump to

Keyboard shortcuts

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