2019-12-13 20:08:26 +02:00
|
|
|
package model
|
|
|
|
|
2019-12-17 22:17:25 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
2019-12-13 20:08:26 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
ErrAppNotFound = errors.New("app not found")
|
|
|
|
)
|
|
|
|
|
|
|
|
type App struct {
|
2019-12-17 22:17:25 +02:00
|
|
|
InstanceDomain string
|
|
|
|
InstanceURL string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type AppRepository interface {
|
|
|
|
Add(app App) (err error)
|
2019-12-17 22:17:25 +02:00
|
|
|
Get(instanceDomain string) (app App, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) Marshal() []byte {
|
|
|
|
str := a.InstanceURL + "\n" + a.ClientID + "\n" + a.ClientSecret
|
|
|
|
return []byte(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) Unmarshal(instanceDomain string, data []byte) error {
|
|
|
|
str := string(data)
|
|
|
|
lines := strings.Split(str, "\n")
|
|
|
|
if len(lines) != 3 {
|
|
|
|
return errors.New("invalid data")
|
|
|
|
}
|
|
|
|
a.InstanceDomain = instanceDomain
|
|
|
|
a.InstanceURL = lines[0]
|
|
|
|
a.ClientID = lines[1]
|
|
|
|
a.ClientSecret = lines[2]
|
|
|
|
return nil
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|