studyplus_for_school_sync_go is a API client for Studyplus for School SYNC
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.
}
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)
}
TBD
TBD
TBD