goil

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: MIT Imports: 16 Imported by: 0

README

Goil : Go iseplive.fr (old version) interface

Build Status Go Report Card GoDoc

WARNING: OBSOLETE. THIS DOESN'T WORK ON THE NEW WEBSITE. NOT MAINTAINED.

A library interface for iseplive.fr, a student website. Warning: Still in development !

go get github.com/aabizri/goil

Documentation for the master branch is on godoc (https://godoc.org/github.com/aabizri/goil) !

Getting started:

Logging in

Start a session

import "net/http"
session,err := goil.Login(USERNAME,PASSWORD, &http.Client{})
Students

Get the list of all students alors with their data

studentList,err := session.GetStudentList()

Export it in csv format through whatever io.writer you prefer, here with os.Stdout

err = studentList.WriteCSV(os.Stdout)
Publications

Publish something

publication := CreatePublication("Hello World", goil.Divers)
err := session.PostPublication(post)

Delete a publication

err := session.DeletePublication(1750)

Documentation

Overview

Package goil provides an interface to iseplive.fr, it's currently a WIP Supported features:

  • Posting
  • Deleting a post by ID
  • Retrieving a student by URL
  • Retrieving a list of all students along with their data

Incoming

  • Retrieving only one student's data
  • Retrieving students pictures
  • Retrieving publications
  • Commenting
  • Liking / Disliking

Index

Constants

View Source
const (
	MB                         uint = 1 << (10 * 2)
	AttachmentMaxSizePictures       = 5 * MB
	AttachmentMaxSizeVideos         = 800 * MB
	AttachmentMaxSizeAudio          = 20 * MB
	AttachmentMaxSizeDocuments      = 10 * MB
)
View Source
const (
	Divers     Category = 8
	News                = 6
	Photos              = 1
	Videos              = 2
	Journal             = 3
	Gazettes            = 10
	Podcasts            = 4
	Evenements          = 5
	Sondages            = 9
	Annales             = 7
)
View Source
const BaseURLString string = "http://iseplive.fr/"

Variables

View Source
var BaseURL *url.URL = &url.URL{
	Scheme: "http",
	Host:   "iseplive.fr",
}

Functions

This section is empty.

Types

type Attachment added in v0.1.0

type Attachment struct {
	// Filename sent to the server, optional
	BasePath string

	// File to be sent, be sure to check max length
	Reader io.Reader
	// contains filtered or unexported fields
}

An attachment

type Attachments added in v0.1.0

type Attachments struct {
	/* Restrictions
	- can't be more than 5Mo in size each
	- must be of PNG, JPEG or GIF format
	*/
	Pictures []Attachment

	/* Restrictions
	- can't be more than 800Mo in size each
	- must have an audio track
	*/
	Videos []Attachment

	/* Restrictions
	- can't be more than 20Mo in size each
	- must have an .mp3 extension (and probably must be mp3 themselves)
	*/
	Audio []Attachment

	/* Restrictions
	- can't be more than 10Mo in size each
	- must have an extension, (i.e must match regex "\.[a-z0-9]{2,4}")
	- but can't have a .jpg, .png, .gif, .mp3, .flv extension (i.e must not match regex "\.(jpg|png|gif|mp3|flv)")
	*/
	Documents []Attachment
}

Attachments filepath

func (Attachments) AttachAudio added in v0.1.0

func (as Attachments) AttachAudio(filename string, r io.Reader)

Attach an audio file given a filepath and a io.Reader

func (Attachments) AttachDocument added in v0.1.0

func (as Attachments) AttachDocument(filename string, r io.Reader)

Attach a document given a filepath and a io.Reader

func (Attachments) AttachPicture added in v0.1.0

func (as Attachments) AttachPicture(filename string, r io.Reader)

Attach a picture given a filepath and a io.Reader

func (Attachments) AttachVideo added in v0.1.0

func (as Attachments) AttachVideo(filename string, r io.Reader)

Attach a video given a filepath and a io.Reader

func (Attachments) Populated added in v0.1.0

func (as Attachments) Populated() bool

Checks if there are any attachments

type Category

type Category uint8

func (Category) Check added in v0.1.0

func (c Category) Check() error

type Event added in v0.1.0

type Event struct {
	// The name of the event, mandatory
	Name string

	// Start and end times
	Start time.Time
	End   time.Time
}

An event Currently only filled in / used when publishing

func (Event) Check added in v0.1.0

func (e Event) Check() error

Check() checks an event's validity

type Group

type Group uint8
const (
	NoGroup    Group = 0
	HustleISEP       = 46
)

Groups ID

type Publication added in v0.1.0

type Publication struct {
	// Publication's ID
	// Not populated when posting, currently unused
	ID PublicationID

	// Message is the text body of a publication
	// Mandatory for publishing
	Message string

	// The category of the publication meant to be published
	// Only filled in on publishing
	// Mandatory for publishing
	Category Category

	// The Group responsible for the publication
	// Only filled in on publishing
	Group Group

	// Whether that messages is official in reference to the group
	// Only used when publishing
	// If Group == 0 then it has no effect
	Official bool

	// Whether the publication should be private
	Private bool

	// Whether the dislike button should be activated
	Dislike bool

	// Event
	Event Event

	// Survey
	Survey Survey

	// Attachments paths for upload
	Attachments Attachments
}

A publication on Iseplive Not all fields are filled in when getting publications

func CreatePublication added in v0.1.0

func CreatePublication(message string, category Category) *Publication

TODO Check if when post with no group "official" field exists

func (*Publication) AddEvent added in v0.1.0

func (p *Publication) AddEvent(event Event)

Add an event to a publication

func (*Publication) AddSurvey added in v0.1.0

func (p *Publication) AddSurvey(survey Survey)

Adds a survey to a publication

func (*Publication) Check added in v0.1.0

func (p *Publication) Check() error

func (*Publication) PublishAs added in v0.1.0

func (p *Publication) PublishAs(group Group, official bool)

Post as a group

type PublicationID added in v0.1.0

type PublicationID uint

A publication's ID

type Session

type Session struct {
	Client *http.Client
}

func CreateSessionByCookie added in v0.1.0

func CreateSessionByCookie(cookie *http.Cookie, client *http.Client) *Session

CreateSessionByCookie creates a Session with the given http.Cookie and http.Client

func CreateSessionByCookieValue

func CreateSessionByCookieValue(cookieValue string, client *http.Client) *Session

CreateSessionByCookieValue creates a Session with the given cookie value and http.Client

func Login

func Login(username string, password string, client *http.Client) (*Session, error)

Login creates a session given a username/password combo and a *http.Client Warning: It is your responsibility to add a timeout

func (*Session) Cookie

func (s *Session) Cookie() (*http.Cookie, error)

Retrieve the login cookie from a session

func (*Session) DeletePublication added in v0.1.0

func (s *Session) DeletePublication(publicationID PublicationID) error

GET http://iseplive.fr/ajax/post/PUBLICATIONID/delete TODO: More info can be retrieved before redirect, notably the success/failure of the delete. retrieve it.

func (*Session) GetAvailableGroups added in v0.1.0

func (s *Session) GetAvailableGroups() (map[Group]string, error)

Find out what groups are available to the session

func (s *Session) GetStudentByLink(link string) (Student, error)

Get a Student given a relative link to iseplive.fr: "/student/alexandrebezri" endpoint: http://iseplive.fr/student/{studentIdentifier}

func (*Session) GetStudentList

func (s *Session) GetStudentList() (StudentList, error)

Return list of every student with data

func (*Session) Logout added in v0.1.0

func (s *Session) Logout() error

Logout does what its name says

func (*Session) PostPublication added in v0.1.0

func (s *Session) PostPublication(publication *Publication) error

Publish publication

type Student

type Student struct {
	ID        string
	Promo     string
	Name      string
	ISEPEmail string
	Email     string
	Cell      string
	Birthday  string
	Quote     string
}

A Student

type StudentList

type StudentList []Student

A list of students

func (StudentList) WriteCSV added in v0.1.0

func (sl StudentList) WriteCSV(writer io.Writer) error

Export StudentList to CSV

func (StudentList) WriteJSON added in v0.1.0

func (sl StudentList) WriteJSON(writer io.Writer) error

Export StudentList to JSON

type Survey added in v0.1.0

type Survey struct {
	// Mandatory
	Question string

	End time.Time // Format in "DD/MM/YYYY à HH:MM"

	Answers []string

	// Whether the survey accepts multiple answers
	Multiple bool
}

A survey Currently only filled in / used when publishing

func CreateSurvey added in v0.1.0

func CreateSurvey(question string, end time.Time, multiple bool, answers ...string) Survey

CreateSurvey creates a survey structure

func (Survey) Check added in v0.1.0

func (s Survey) Check() error

Check validity

Jump to

Keyboard shortcuts

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