mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 03:38:03 +01:00
Generating of auth URL is api.API's responsibility
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type API interface {
|
||||
AuthUrl() string
|
||||
UploadAsciicast(string) (string, string, error)
|
||||
}
|
||||
|
||||
@@ -33,6 +34,10 @@ func New(url, user, token, version string) *AsciinemaAPI {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AsciinemaAPI) AuthUrl() string {
|
||||
return fmt.Sprintf("%v/connect/%v", a.url, a.token)
|
||||
}
|
||||
|
||||
func (a *AsciinemaAPI) UploadAsciicast(path string) (string, string, error) {
|
||||
files, err := filesForUpload(path)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,20 +3,20 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asciinema/asciinema/util"
|
||||
"github.com/asciinema/asciinema/api"
|
||||
)
|
||||
|
||||
type AuthCommand struct {
|
||||
cfg *util.Config
|
||||
api api.API
|
||||
}
|
||||
|
||||
func NewAuthCommand(cfg *util.Config) *AuthCommand {
|
||||
return &AuthCommand{cfg}
|
||||
func NewAuthCommand(api api.API) *AuthCommand {
|
||||
return &AuthCommand{api}
|
||||
}
|
||||
|
||||
func (c *AuthCommand) Execute() error {
|
||||
fmt.Println("Open the following URL in your browser to register your API token and assign any recorded asciicasts to your profile:")
|
||||
fmt.Printf("%v/connect/%v\n", c.cfg.ApiUrl(), c.cfg.ApiToken())
|
||||
fmt.Println("Open the following URL in a browser to register your API token and assign any recorded asciicasts to your profile:")
|
||||
fmt.Println(c.api.AuthUrl())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ type testAPI struct {
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (a *testAPI) AuthUrl() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *testAPI) UploadAsciicast(path string) (string, string, error) {
|
||||
if a.err != nil {
|
||||
return "", "", a.err
|
||||
|
||||
Reference in New Issue
Block a user