studyplus_for_school_sync_go

module
v0.0.0-...-7c98ed9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0

README

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

Directories

Path Synopsis
Package auth is a generated GoMock package.
Package auth is a generated GoMock package.
examples

Jump to

Keyboard shortcuts

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