From 88fc47dae0be8c9eecf4a401854a94ca94505d78 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 12 Mar 2015 12:31:46 +0100 Subject: [PATCH] Generating of auth URL is api.API's responsibility --- api/api.go | 5 +++++ commands/auth.go | 12 ++++++------ commands/rec_test.go | 4 ++++ main.go | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/api/api.go b/api/api.go index a0c28014f..8c6d17b49 100644 --- a/api/api.go +++ b/api/api.go @@ -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 { diff --git a/commands/auth.go b/commands/auth.go index 8300eb2e4..45ab61556 100644 --- a/commands/auth.go +++ b/commands/auth.go @@ -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 } diff --git a/commands/rec_test.go b/commands/rec_test.go index d0b1b71bb..7e62af22a 100644 --- a/commands/rec_test.go +++ b/commands/rec_test.go @@ -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 diff --git a/main.go b/main.go index 37ac487d2..fbe16a3e9 100644 --- a/main.go +++ b/main.go @@ -137,7 +137,7 @@ func main() { err = cmd.Execute(filename) case "auth": - cmd := commands.NewAuthCommand(cfg) + cmd := commands.NewAuthCommand(api) err = cmd.Execute() }