amizone

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrBadClient              = "the http client passed must have a cookie jar, or be nil"
	ErrFailedToVisitPage      = "failed to visit page"
	ErrFailedToFetchPage      = "failed to fetch page"
	ErrFailedToReadResponse   = "failed to read response body"
	ErrFailedLogin            = "failed to login"
	ErrInvalidCredentials     = ErrFailedLogin + ": invalid credentials"
	ErrInternalFailure        = "internal failure"
	ErrFailedToComposeRequest = ErrInternalFailure + ": failed to compose request"
	ErrFailedToParsePage      = ErrInternalFailure + ": failed to parse page"
	ErrInvalidMac             = "invalid MAC address passed"
	ErrNoMacSlots             = "no free wifi mac slots"
	ErrFailedToRegisterMac    = "failed to register mac address"
)

Errors

View Source
const (
	BaseURL = "https://" + internal.AmizoneDomain
)

Endpoints

View Source
const (
	ErrNon200StatusCode = "received non-200 status code from amizone - is it down?"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the main struct for the amizone package, exposing the entire API surface for the portal as implemented here. The struct must always be initialized through a public constructor like NewClient()

func NewClient

func NewClient(cred Credentials, httpClient *http.Client) (*Client, error)

NewClient create a new client instance with Credentials passed, then attempts to log in to the website. The *http.Client parameter can be nil, in which case a default client will be created in its place. To get a non-logged in client, pass empty credentials, ala Credentials{}.

func (*Client) DidLogin

func (a *Client) DidLogin() bool

DidLogin returns true if the client ever successfully logged in.

func (*Client) GetAttendance

func (a *Client) GetAttendance() (models.AttendanceRecords, error)

GetAttendance retrieves, parses and returns attendance data from Amizone for courses the client user is enrolled in for their latest semester.

func (*Client) GetClassSchedule

func (a *Client) GetClassSchedule(year int, month time.Month, date int) (models.ClassSchedule, error)

GetClassSchedule retrieves, parses and returns class schedule data from Amizone. The date parameter is used to determine which schedule to retrieve, however as Amizone imposes arbitrary limits on the date range, as in scheduled for dates older than some months are not stored by Amizone, we have no way of knowing if a request will succeed.

func (*Client) GetCourses

func (a *Client) GetCourses(semesterRef string) (models.Courses, error)

GetCourses retrieves, parses and returns a SemesterList from Amizone for the semester referred by semesterRef. Semester references should be retrieved through GetSemesters, which returns a list of valid semesters with names and references.

func (*Client) GetCurrentCourses

func (a *Client) GetCurrentCourses() (models.Courses, error)

GetCurrentCourses retrieves, parses and returns a SemesterList from Amizone for the most recent semester.

func (*Client) GetCurrentExaminationResult added in v0.8.0

func (a *Client) GetCurrentExaminationResult() (*models.ExamResultRecords, error)

GetExaminationResult retrieves, parses and returns a ExaminationResultRecords from Amizone for their latest semester for which the result is available

func (*Client) GetExamSchedule

func (a *Client) GetExamSchedule() (*models.ExaminationSchedule, error)

GetExamSchedule retrieves, parses and returns exam schedule data from Amizone. Amizone only allows to retrieve the exam schedule for the current semester, and only close to the exam dates once the date sheets are out, so we don't take a parameter here.

func (*Client) GetExaminationResult added in v0.8.0

func (a *Client) GetExaminationResult(semesterRef string) (*models.ExamResultRecords, error)

GetExaminationResult retrieves, parses and returns a ExaminationResultRecords from Amizone for the semester referred by semesterRef. Semester references should be retrieved through GetSemesters, which returns a list of valid semesters with names and references.

func (*Client) GetSemesters

func (a *Client) GetSemesters() (models.SemesterList, error)

GetSemesters retrieves, parses and returns a SemesterList from Amizone. This list includes all semesters for which information can be retrieved through other semester-specific methods like GetCourses.

func (*Client) GetUserProfile added in v0.7.0

func (a *Client) GetUserProfile() (*models.Profile, error)

GetUserProfile retrieves, parsed and returns the current user's profile from Amizone.

func (*Client) GetWiFiMacInformation added in v0.7.0

func (a *Client) GetWiFiMacInformation() (*models.WifiMacInfo, error)

func (*Client) RegisterWifiMac added in v0.3.0

func (a *Client) RegisterWifiMac(addr net.HardwareAddr, bypassLimit bool) error

RegisterWifiMac registers a mac address on Amizone. If bypassLimit is true, it bypasses Amizone's artificial 2-address limitation. However, only the 2 oldest mac addresses are reflected in the GetWifiMacInfo response. TODO: is the bypassLimit functional?

func (*Client) RemoveWifiMac added in v0.3.0

func (a *Client) RemoveWifiMac(addr net.HardwareAddr) error

RemoveWifiMac removes a mac address from the Amizone mac address registry. If the mac address is not registered in the first place, this function does nothing.

func (*Client) SubmitFacultyFeedbackHack added in v0.6.0

func (a *Client) SubmitFacultyFeedbackHack(rating int32, queryRating int32, comment string) (int32, error)

SubmitFacultyFeedbackHack submits feedback for *all* faculties, giving the same ratings and comments to all. This is a hack because we're not allowing fine-grained control over feedback points or individual faculties. This is because the form is a pain to parse, and the feedback system is a pain to work with in general. Returns: the number of faculties for which feedback was submitted. Note that this number would be zero if the feedback was already submitted or is not open.

type ClientFactoryInterface

type ClientFactoryInterface func(cred Credentials, httpClient *http.Client) (ClientInterface, error)

ClientFactoryInterface is a type for functions that return ClientInterface instances. Functions returning concrete types need to be wrapped by functions that return the interface; apparently a limitation of the Go compiler's type inference.

type ClientInterface

type ClientInterface interface {
	DidLogin() bool
	GetAttendance() (models.AttendanceRecords, error)
	GetClassSchedule(year int, month time.Month, date int) (models.ClassSchedule, error)
	GetExamSchedule() (*models.ExaminationSchedule, error)
}

ClientInterface is an exported interface for client to make mocking and testing more convenient.

type Credentials

type Credentials struct {
	Username string
	Password string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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