Skip to content

a-tommyyy/studyplus_for_school_sync_go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Studyplus for School SYNC API Client

This project is currently alpha, possibility having breaking changes.

Maintainability github action workflow

studyplus_for_school_sync_go is a API client for Studyplus for School SYNC

Getting Started

Authorization

It is a NOT required implementation, most users can use golang.org/x/oauth2 for Oauth2 authorization process.

import (
	"fmt"
	"os"

	. "github.com/atomiyama/studyplus_for_school_sync_go/auth"
	"golang.org/x/oauth2"
)

type DBTokenStore struct {
	// some fields. 
}

func (s *DBTokenStore) Get() (*oauth2.Token, error) {
	// fetch persited token from DB.
}

func (s *DBTokenStore) Save(t *oauth2.Token) error {
	// Persist token.
}

func main() {
	var endpoint oauth2.Endpoint
	EndpointFromEnv(&endpoint, EnvDevelopment)
	cnf := &oauth2.Config{
		ClientID:     os.Getenv("CLIENT_ID"),
		ClientSecret: os.Getenv("CLIENT_SECRET"),
		RedirectURL:  os.Getenv("REDIRECT_URL"),
		Scopes:       []string{"learning_material_supplier"},
		Endpoint:     endpoint,
	}
	src := &DBTokenStore{}
	authorization := NewAuthorization(cnf, src)
	url := authorization.AuthCodeURL("state")

	var code string // get auth code.

	ctx := context.Background()
	authorization.AuthorizeFromCode(ctx, code)

	ctx = context.Background()
	client, err := authorization.Client(ctx)
	if err != nil {
		log.Fatal(err)
	}
	// Request API via client.
}

Creating LearningMaterial

import (
	"fmt"
	"log"
	"net/http"

	. "github.com/atomiyama/studyplus_for_school_sync_go/fssync"
)

func main() {
	client := &http.Client{} // It should have injected Authorization Header when requesting.
	service, err := NewService(client, BaseURLDevelopment)
	if err != nil {
		log.Fatal(err)
	}
	lm := &LearningMaterial{
		Name:     "SAMPLE_NAME",
		ImageUrl: "https://exmaple.com/image.jpeg",
	}
	lm, err = service.LearningMaterial.Create(lm).Do()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("New LearningMaterial: %+v\n", lm)
}

Creating Partner

TBD

Creating Student

TBD

Creating StudyRecord

TBD

About

An API Client package for Studyplus for School SYNC API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages