studip

package module
v0.0.0-...-da7709c Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: MIT Imports: 9 Imported by: 0

README

studip library for golang

studip is a library to communicate with the StudIP platform implemented by the Univerity Passau. It works with Shibboleth SAML authentication and contains adjustments to work with this specific site. It could be adapted to other StudIP platforms with similar login mechanisms.

Usage

$ go get github.com/blang/studip

Note: Always vendor your dependencies or fix on a specific version tag.

import github.com/blang/studip

jar, err := cookiejar.New(nil)
client := &http.Client{}
client.Jar = jar

api := &studip.API{
    Client: client,
}

err := api.Login(username, password)

tree, err := api.DocumentTree()

reader, err := api.GetFile("file_id")

Also check the GoDocs.

Features

  • Shibboleth SAML Login
  • DocumentTree
  • GetFileContent

Motivation

A working studip api implementation could be used to create several services like automatic document download or notifications about new entries. I simply couldn't find any lib supporting the studip api.

Contribution

Feel free to make a pull request. For bigger changes create a issue first to discuss about it.

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultUserAgent = "StudIP Golang Library (github.com/blang/studip)"

DefaultUserAgent if not already set by API.Header

View Source
var StudIPAPIBaseURL = "https://studip.uni-passau.de/studip/api.php/"

StudIPAPIBaseURL, the url to the api

Functions

This section is empty.

Types

type API

type API struct {
	Header http.Header
	Client HTTPClient
}

API to communicate with StudIP

func (*API) DocumentTree

func (a *API) DocumentTree() (*DocumentTree, error)

DocumentTree represents a tree of all semesters and corresponding documents. An error is returned if the request could not be completed. The error can be a StatusCodeError.

func (*API) GetFile

func (a *API) GetFile(fileid string) (io.ReadCloser, error)

GetFile returns an io.Reader for the requested file. If the file does not exist, an StatusCodeError with Code: 404 is returned.

func (*API) Login

func (a *API) Login(username, password string) error

Login performs a full SAML Client authentication to studip. If the login could not be completed, an error is returned.

type APIError

type APIError struct {
	Msg          string
	InvalidLogin bool
	Parent       error
}

APIError is returned if the remote api responds with an error.

func (APIError) Error

func (e APIError) Error() string

Error returns the error message

type DocumentTree

type DocumentTree []struct {
	SemesterID  string `json:"semester_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Courses     []struct {
		CourseID string   `json:"course_id"`
		CourseNr string   `json:"course_nr"`
		Title    string   `json:"title"`
		Folders  []Folder `json:"folders"`
	} `json:"courses"`
}

DocumentTree represents a tree of all semesters and its documents. API Endpoints: - api/studip-client-core/documenttree/

type Folder

type Folder struct {
	FolderID    string `json:"folder_id"`
	Name        string `json:"name"`
	Mkdate      string `json:"mkdate"`
	Chdate      string `json:"chdate"`
	Permissions struct {
		Visible    bool `json:"visible"`
		Writable   bool `json:"writable"`
		Readable   bool `json:"readable"`
		Extendable bool `json:"extendable"`
	} `json:"permissions"`
	Subfolders []Folder `json:"subfolders"`
	Files      []struct {
		DocumentID string `json:"document_id"`
		Name       string `json:"name"`
		Mkdate     string `json:"mkdate"`
		Chdate     string `json:"chdate"`
		Filename   string `json:"filename"`
		Filesize   string `json:"filesize"`
		Protection string `json:"protection"`
		MimeType   string `json:"mime_type"`
	} `json:"files"`
}

Folder represents a folder in studips documents.

type HTTPClient

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

HTTPClient is a general interface for http requests. Implemented by *http.Client

type StatusCodeError

type StatusCodeError struct {
	Code int
	Msg  string
}

StatusCodeError is returned if the error is only specified by an invalid status code.

func (StatusCodeError) Error

func (e StatusCodeError) Error() string

Error returns the error message

Jump to

Keyboard shortcuts

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