Skip to content

Commit

Permalink
Generating of auth URL is api.API's responsibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Mar 12, 2015
1 parent 7243568 commit 88fc47d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions api/api.go
Expand Up @@ -12,6 +12,7 @@ import (
)

type API interface {
AuthUrl() string
UploadAsciicast(string) (string, string, error)
}

Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions commands/auth.go
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions commands/rec_test.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -137,7 +137,7 @@ func main() {
err = cmd.Execute(filename)

case "auth":
cmd := commands.NewAuthCommand(cfg)
cmd := commands.NewAuthCommand(api)
err = cmd.Execute()
}

Expand Down

0 comments on commit 88fc47d

Please sign in to comment.