package amizone
import "github.com/ditsuke/go-amizone/amizone"
Index ¶
- Constants
- type Client
- func NewClient(cred Credentials, httpClient *http.Client) (*Client, error)
- func (a *Client) DidLogin() bool
- func (a *Client) GetAttendance() (models.AttendanceRecords, error)
- func (a *Client) GetClassSchedule(year int, month time.Month, date int) (models.ClassSchedule, error)
- func (a *Client) GetCourses(semesterRef string) (models.Courses, error)
- func (a *Client) GetCurrentCourses() (models.Courses, error)
- func (a *Client) GetCurrentExaminationResult() (*models.ExamResultRecords, error)
- func (a *Client) GetExamSchedule() (*models.ExaminationSchedule, error)
- func (a *Client) GetExaminationResult(semesterRef string) (*models.ExamResultRecords, error)
- func (a *Client) GetSemesters() (models.SemesterList, error)
- func (a *Client) GetUserProfile() (*models.Profile, error)
- func (a *Client) GetWiFiMacInformation() (*models.WifiMacInfo, error)
- func (a *Client) RegisterWifiMac(addr net.HardwareAddr, bypassLimit bool) error
- func (a *Client) RemoveWifiMac(addr net.HardwareAddr) error
- func (a *Client) SubmitFacultyFeedbackHack(rating int32, queryRating int32, comment string) (int32, error)
- type ClientFactoryInterface
- type ClientInterface
- type Credentials
Constants ¶
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
const ( BaseURL = "https://" + internal.AmizoneDomain )
Endpoints
const (
ErrNon200StatusCode = "received non-200 status code from amizone - is it down?"
)
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 ¶
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 ¶
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 ¶
GetCurrentCourses retrieves, parses and returns a SemesterList from Amizone for the most recent semester.
func (*Client) GetCurrentExaminationResult ¶
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 ¶
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 ¶
GetUserProfile retrieves, parsed and returns the current user's profile from Amizone.
func (*Client) GetWiFiMacInformation ¶
func (a *Client) GetWiFiMacInformation() (*models.WifiMacInfo, error)
func (*Client) RegisterWifiMac ¶
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 ¶
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 ¶
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 ¶
Source Files ¶
amizone.go interface.go payload_templates.go requests.go
Directories ¶
Path | Synopsis |
---|---|
amizone/internal | |
amizone/models |
- Version
- v0.8.0 (latest)
- Published
- Jun 9, 2023
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 1 day ago –
Tools for package owners.