api

package
v0.0.0-...-20f0d7a Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package api provides abstractions for the REST API.

Index

Constants

View Source
const APIVersion = "v3.2.0"

APIVersion is the API version this library is compatible with.

Variables

View Source
var (
	ErrMultipleLateStarts = errors.New("multiple late starts found")
	ErrSchoolNotOpen      = errors.New("school not open")
)
View Source
var DefaultBaseURL, _ = url.Parse("https://maclyonsden.com/api/")

Functions

func GetImageFromMd

func GetImageFromMd(src string) (alt, url string, found bool)

Types

type Ann

type Ann struct {
	Id           AnnID     `json:"id"`
	Author       Username  `json:"author"`
	Org          OrgName   `json:"organization"`
	Tags         []Tag     `json:"tags"`
	Created      time.Time `json:"created_date"`
	LastModified time.Time `json:"last_modified_date"`
	Title        string    `json:"title"`
	Body         string    `json:"body"`
	Public       bool      `json:"is_public"`

	// fields below are not in the API
	XAuthor    UserResp
	XOrg       Org
	XImageURL  string
	XImagePath string
	XImageAlt  string
	XURL       string
}

Ann represents an announcement. Model: core.models.post.Announcement Serializer: core.api.serializers.announcement.AnnouncementSerializer

func (Ann) ReqOrg

func (a Ann) ReqOrg(c *Client) (Org, error)

func (Ann) String

func (a Ann) String() string

func (Ann) URL

func (a Ann) URL(c *Client) *url.URL

type AnnFeedReq

type AnnFeedReq struct {
	Auth
}

func (AnnFeedReq) Req

func (req AnnFeedReq) Req(c *Client) (*http.Request, error)

type AnnFeedResp

type AnnFeedResp []Ann

type AnnID

type AnnID uint

func (AnnID) Deref

func (id AnnID) Deref(c *Client) (Ann, error)

type AnnReq

type AnnReq struct{}

func (AnnReq) Req

func (req AnnReq) Req(c *Client) (*http.Request, error)

type AnnResp

type AnnResp = []Ann

type Auth

type Auth struct {
	Access    string    `json:"access"`
	Refresh   string    `json:"refresh"`
	Generated time.Time `json:"-"`
}

type AuthReReq

type AuthReReq struct {
	Auth
}

func (AuthReReq) Req

func (req AuthReReq) Req(c *Client) (*http.Request, error)

type AuthReResp

type AuthReResp struct {
	Access string `json:"access"`
}

func (AuthReResp) UpdateAuth

func (resp AuthReResp) UpdateAuth(a *Auth)

type AuthReq

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

func (AuthReq) Req

func (req AuthReq) Req(c *Client) (*http.Request, error)

type AuthResp

type AuthResp struct {
	Refresh string `json:"refresh"`
	Access  string `json:"access"`
}

func (AuthResp) UpdateAuth

func (resp AuthResp) UpdateAuth(a *Auth)

type Client

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

func DefaultClient

func DefaultClient() *Client

func NewClient

func NewClient(client HTTPClient, baseURL *url.URL) *Client

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

func (*Client) CheckAPIVersion

func (c *Client) CheckAPIVersion() (string, bool, error)

CheckAPIVersion checks whether the API server supports the API version the Client is compatible with.

func (*Client) CourseEvents

func (c *Client) CourseEvents() (evs []Event, err error)

CourseEvents generates Event s from the course schedule.

TODO: use MeScheduleResp or MeTimetableResp to generate events for 2+ weeks.

func (*Client) Do

func (c *Client) Do(req Req, v interface{}) (err error)

func (*Client) Events deprecated

func (c *Client) Events(req EventsReq) (resp EventsResp, err error)

Deprecated: use Client.Do instead.

func (*Client) HTTPClient

func (c *Client) HTTPClient() HTTPClient

func (*Client) Rel

func (c *Client) Rel(u *url.URL) *url.URL

type Course

type Course struct {
	Id        CourseID    `json:"id"`
	Code      CourseCode  `json:"code"`
	Term      TermID      `json:"term"`
	Desc      string      `json:"description"`
	Position  int         `json:"position"`
	Submitter interface{} `json:"submitter"`
}

Course represents a course. TODO: fill model Model: core.models.course.Course Serializer: core.api.serializers.course.CourseSerializer

func (Course) String

func (c Course) String() string

func (Course) URL

func (c Course) URL(c2 *Client) *url.URL

type CourseCode

type CourseCode string

func (CourseCode) Deref

func (code CourseCode) Deref(c *Client) (Course, error)

type CourseID

type CourseID = uint

type Data

type Data interface {
	URL(c *Client) *url.URL
}

type Event

type Event struct {
	Id     EventID   `json:"id"`
	Name   string    `json:"name"`
	Desc   string    `json:"description"`
	Tags   []Tag     `json:"tags"`
	Term   TermID    `json:"term"`
	Org    Org       `json:"organization"`
	Start  time.Time `json:"start_date"`
	End    time.Time `json:"end_date"`
	Public bool      `json:"is_public"`
}

Event represents an event, Model: core.models.course.Event Serializer: core.api.serializers.course.EventSerializer

func (Event) PerDay

func (e Event) PerDay() bool

PerDay returns whether the Event is an all-day event. Note: "all-day event" means that the event is at least 23:59:00 long and is shorter than 24:00:00.

func (Event) String

func (e Event) String() string

func (Event) URL

func (e Event) URL(c *Client) *url.URL

type EventID

type EventID = int // negative is evs not on server (generated)

type Events

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

func NewEvents

func NewEvents(resp EventsResp) *Events

type EventsReq

type EventsReq struct {
	Start *time.Time
	End   *time.Time
}

EventsReq has the options for a Client.Events API call.

func (EventsReq) Query

func (req EventsReq) Query() (v url.Values)

Query serializes the options in EventsReq to a new url.Values.

func (EventsReq) Req

func (req EventsReq) Req(c *Client) (*http.Request, error)

type EventsResp

type EventsResp = []Event

EventsResp is the expected response from a Client.Events API call.

type HTTPClient

type HTTPClient interface {
	Do(r *http.Request) (resp *http.Response, err error)
}

HTTPClient is a subset of the *http.Client interface.

type MeReq

type MeReq struct {
	Auth
}

func (MeReq) Req

func (req MeReq) Req(c *Client) (*http.Request, error)

type MeResp

type MeResp struct {
	Username       string   `json:"username"`
	FirstName      string   `json:"first_name"`
	LastName       string   `json:"last_name"`
	Bio            string   `json:"bio"`
	Timezone       string   `json:"timezone"`
	GraduatingYear *int     `json:"graduating_year"`
	Organizations  []string `json:"organizations"`
	TagsFollowing  []string `json:"tags_following"`
}

type MeScheduleReq

type MeScheduleReq struct {
	Auth
}

func (MeScheduleReq) Req

func (req MeScheduleReq) Req(c *Client) (*http.Request, error)

type MeScheduleResp

type MeScheduleResp = []Schedule

type MeScheduleWeekReq

type MeScheduleWeekReq struct {
	Auth
}

func (MeScheduleWeekReq) Req

func (req MeScheduleWeekReq) Req(c *Client) (*http.Request, error)

type MeScheduleWeekResp

type MeScheduleWeekResp map[string][]Schedule

type MeTimetableReq

type MeTimetableReq struct {
	Auth
}

func (MeTimetableReq) Req

func (req MeTimetableReq) Req(c *Client) (*http.Request, error)

type MeTimetableResp

type MeTimetableResp struct {
	Id      int      `json:"id"`
	Owner   User     `json:"owner"`
	Term    Term     `json:"term"`
	Courses []Course `json:"courses"`
}

type OauthReq

type OauthReq struct {
	Token *oauth2.Token
	Inner Req
}

OauthReq adds oauth authentication to a Req.

func (OauthReq) Req

func (req OauthReq) Req(c *Client) (*http.Request, error)

Req implements Req.

type Org

type Org struct {
	Id          int       `json:"id"`
	Owner       User      `json:"owner"`
	Supervisors []User    `json:"supervisors"`
	Execs       []User    `json:"execs"`
	Tags        []Tag     `json:"tags"`
	Name        OrgName   `json:"name"`
	Bio         string    `json:"bio"`
	Extra       string    `json:"extra_content"`
	Slug        OrgSlug   `json:"slug"`
	Registered  time.Time `json:"registered_date"`
	Open        bool      `json:"is_open"`
	AppsOpen    bool      `json:"applications_open"`
	Banner      string    `json:"banner"`
	Icon        string    `json:"icon"`
}

Org represents an organization. Model:core.models.organization.Org Serializer: core.api.serializers.organization.OrganizationSerializer

func (Org) IconURL

func (o Org) IconURL(c *Client) *url.URL

func (Org) URL

func (o Org) URL(c *Client) *url.URL

type OrgName

type OrgName = string

type OrgReq

type OrgReq struct {
	Id int
}

func (OrgReq) Req

func (req OrgReq) Req(c *Client) (*http.Request, error)

type OrgResp

type OrgResp = Org

type OrgSlug

type OrgSlug string

func (OrgSlug) Deref

func (slug OrgSlug) Deref(c *Client) (org Org, err error)

type OrgsReq

type OrgsReq struct{}

func (OrgsReq) Req

func (req OrgsReq) Req(c *Client) (*http.Request, error)

type OrgsResp

type OrgsResp = []Org

type Req

type Req interface {
	Req(c *Client) (*http.Request, error)
}

type Schedule

type Schedule struct {
	Description struct {
		Time   string `json:"time"`
		Course string `json:"course"`
	} `json:"description"`
	Time   Timeframe   `json:"time"`
	Pos    []int       `json:"position"`
	Cycle  string      `json:"cycle"`
	Course *CourseCode `json:"course"`
}

func (Schedule) Event

func (s Schedule) Event(c *Client) (Event, error)

func (Schedule) URL

func (s Schedule) URL(_ *Client) *url.URL

type StatusError

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

func (StatusError) Error

func (err StatusError) Error() string

type Tag

type Tag struct {
	ID    TagID  `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

Tag represents a single tag from the API.

func (Tag) URL

func (t Tag) URL(c *Client) *url.URL

type TagID

type TagID = uint

type Term

type Term struct {
	Id     TermID    `json:"id"`
	Name   string    `json:"name"`
	Desc   string    `json:"description"`
	Fmt    string    `json:"timetable_format"`
	Start  time.Time `json:"start"`
	End    time.Time `json:"end"`
	Frozen bool      `json:"is_frozen"`
}

Term represents a term. TODO: fill model Model: core.models.course.Term Serializer: core.api.serializers.course.TermSerializer

func (Term) URL

func (t Term) URL(c *Client) *url.URL

type TermID

type TermID = uint

type TermsReq

type TermsReq struct{}

func (TermsReq) Req

func (req TermsReq) Req(c *Client) (*http.Request, error)

type TermsResp

type TermsResp struct{}

type Timeframe

type Timeframe struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

func (Timeframe) URL

func (t Timeframe) URL(_ *Client) *url.URL

type User

type User struct {
	Username       Username      `json:"username"`
	FirstName      string        `json:"first_name"`
	LastName       string        `json:"last_name"`
	Bio            string        `json:"bio"`
	Timezone       string        `json:"timezone"`
	GraduatingYear int           `json:"graduating_year"`
	Organizations  []string      `json:"organizations"`
	TagsFollowing  []interface{} `json:"tags_following"`
}

func (User) Name

func (u User) Name() string

func (User) URL

func (u User) URL(c *Client) *url.URL

type UserReq

type UserReq struct {
	Username string
}

func (UserReq) Req

func (req UserReq) Req(c *Client) (*http.Request, error)

type UserResp

type UserResp User

type Username

type Username string

func (Username) Deref

func (username Username) Deref(c *Client) (resp UserResp, err error)

type VersionReq

type VersionReq struct{}

func (VersionReq) Req

func (req VersionReq) Req(c *Client) (*http.Request, error)

type VersionResp

type VersionResp struct {
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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