Generating of auth URL is api.API's responsibility

This commit is contained in:
Marcin Kulik
2015-03-12 12:31:46 +01:00
parent 7243568f4f
commit 88fc47dae0
4 changed files with 16 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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

View File

@@ -137,7 +137,7 @@ func main() {
err = cmd.Execute(filename)
case "auth":
cmd := commands.NewAuthCommand(cfg)
cmd := commands.NewAuthCommand(api)
err = cmd.Execute()
}