canvasapi

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

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

This Golang project provides access to the Canvas API

The Go canvasapi library provides a struct for every Canvas API endpoint found here: https://canvas.instructure.com/doc/api/[https://canvas.instructure.com/doc/api/]

It is autogenerated using the json version of the documentation found here: https://canvas.instructure.com/doc/api/api-docs.json[https://canvas.instructure.com/doc/api/api-docs.json]

and which leads to json that describes individual endpoints. For example: https://canvas.instructure.com/doc/api/assignments.json[https://canvas.instructure.com/doc/api/assignments.json]

Examples

The Canvas struct

Construct a new Canvas struct. This instance will be passed to all requests to the Canvas API and contains the url of the Canvas instance you will interact with as well as an API token. Note that this library does not manage the token and will return an error if the token is not valid or has expired. The calling code is responsible for handling that error and aquiring a valid token token := os.Getenv("CANVAS_API_TOKEN") canvasURL := "atomicjolt.instructure.com" canvas := canvasapi.New(token, canvasURL)

GET a list of assignments for a given course

` // This example shows listing assignments for the list assignments endpoint documented here: // https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.index[https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.index]

// Construct a new ListAssignmentsAssignments struct listAssignments := requests.ListAssignmentsAssignments{}

// 'Path' parameters are used to build the full path to make the request and are typically required. listAssignments.Path.CourseID = courseID

// Query parameters can be added to the 'Query' substruct. Most query parameters are optional. listAssignments.Query.Include = []string{"submission", "can_edit"}

// Call 'Do' on the struct to execute the query. All 'Do' methods require an instance of a Canvas struct. assignments, pager, err := listAssignments.Do(&canvas) if err != nil { t.Errorf("ListAssignmentsAssignments failed: %v", err) }

// Be sure to check for additional pages of results and make additional requests as necessary. if pager.Next != nil { moreAssignments, pager, err := listAssignments.Do(&canvas, pager.Next.URL) } `

Run all Tests:

NOTE!!!!!! This will run against the Canvas Instance you use to generate the token. Create a test account and use that account id in the .env file.

create a .env file and add a valid Canvas API Token CANVAS_API_TOKEN=a valid token CANVAS_ACCOUNT_ID=578

gotest ./... -v

Update packages

go get -u

Build lib:

go mod tidy // Clean up the mod file go build ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimitExceeded = errors.New("403 Forbidden (Rate Limit Exceeded)")

ErrRateLimitExceeded is returned when the api rate limit has been reached.

Functions

func IsRateLimit

func IsRateLimit(e error) bool

IsRateLimit returns true if the error given is a rate limit error.

Types

type Canvas

type Canvas struct {
	AccessToken string
	CanvasURL   string
	UserAgent   string
}

func New

func New(accessToken string, canvasURL string) Canvas

func (*Canvas) Send

func (c *Canvas) Send(canvasUrl *url.URL, method string, body *url.Values) (*http.Response, error)

func (*Canvas) SendRequest

func (c *Canvas) SendRequest(canvasRequest CanvasRequest) (*http.Response, error)

type CanvasModel

type CanvasModel interface {
	HasError() error
}

type CanvasRequest

type CanvasRequest interface {
	GetMethod() string
	GetURLPath() string
	GetQuery() (string, error)
	GetBody() (url.Values, error)
	GetJSON() ([]byte, error)
	HasErrors() error
}
type PagedLink struct {
	URL  *url.URL
	Page int
}

type PagedResource

type PagedResource struct {
	Current, First, Last, Next *PagedLink
}

func ExtractPagedResource

func ExtractPagedResource(header http.Header) (*PagedResource, error)

type QuizUserConversation

type QuizUserConversation struct {
	Body       string `json:"body" url:"body,omitempty"`
	Subject    string `json:"subject" url:"subject,omitempty"`
	Recipients string `json:"recipients" url:"recipients,omitempty"`
}

type SuccessResponse

type SuccessResponse struct {
	Success bool `json:"success"`
}

type UnreadCount

type UnreadCount struct {
	UnreadCount int64 `json:"unread_count"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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