Skip to content

Commit d685c34

Browse files
author
Brian Strauch
committed
move spotify api to separate repo
1 parent 4ebbae3 commit d685c34

42 files changed

Lines changed: 97 additions & 622 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
spotify
1+
.idea/
22
dist/
3+
spotify

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/blang/semver v3.5.1+incompatible
7+
github.com/brianstrauch/spotify v0.0.0
78
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
89
github.com/rhysd/go-github-selfupdate v1.2.3
910
github.com/spf13/cobra v1.1.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
2626
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
2727
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
2828
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
29+
github.com/brianstrauch/spotify v0.0.0 h1:uZ8caTHsX64ZirKZALo7jWhpJQ6JYwg8yRxNxf4iGHE=
30+
github.com/brianstrauch/spotify v0.0.0/go.mod h1:Y5x5ohQj98clyYZe2wo04Hz0HdW/PHYLKaVqG1C4GTY=
2931
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
3032
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
3133
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=

internal/auth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package internal
33
import (
44
"errors"
55
"spotify/internal/login"
6-
"spotify/pkg"
76
"time"
87

8+
"github.com/brianstrauch/spotify"
99
"github.com/spf13/viper"
1010
)
1111

12-
func Authenticate() (*pkg.API, error) {
12+
func Authenticate() (*spotify.API, error) {
1313
if time.Now().Unix() > viper.GetInt64("expiration") {
1414
if err := refresh(); err != nil {
1515
return nil, err
@@ -21,13 +21,13 @@ func Authenticate() (*pkg.API, error) {
2121
return nil, errors.New(NotLoggedInErr)
2222
}
2323

24-
return pkg.NewAPI(token), nil
24+
return spotify.NewAPI(token), nil
2525
}
2626

2727
func refresh() error {
2828
refresh := viper.GetString("refresh_token")
2929

30-
token, err := pkg.RefreshToken(refresh)
30+
token, err := spotify.RefreshToken(refresh)
3131
if err != nil {
3232
return err
3333
}

internal/back/back.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"errors"
55
"spotify/internal"
66
"spotify/internal/status"
7-
"spotify/pkg"
8-
"spotify/pkg/model"
97

8+
"github.com/brianstrauch/spotify"
9+
"github.com/brianstrauch/spotify/model"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -32,7 +32,7 @@ func NewCommand() *cobra.Command {
3232
}
3333
}
3434

35-
func back(api pkg.APIInterface) (string, error) {
35+
func back(api spotify.APIInterface) (string, error) {
3636
playback, err := api.Status()
3737
if err != nil {
3838
return "", err

internal/back/back_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package back
33
import (
44
"errors"
55
"spotify/internal"
6-
"spotify/pkg"
7-
"spotify/pkg/model"
86
"testing"
97

8+
"github.com/brianstrauch/spotify"
9+
"github.com/brianstrauch/spotify/model"
1010
"github.com/stretchr/testify/mock"
1111
"github.com/stretchr/testify/require"
1212
)
1313

1414
func TestBackCommand(t *testing.T) {
15-
api := new(pkg.MockAPI)
15+
api := new(spotify.MockAPI)
1616

1717
playback1 := &model.Playback{
1818
IsPlaying: true,
@@ -42,7 +42,7 @@ func TestBackCommand(t *testing.T) {
4242
}
4343

4444
func TestNoPreviousErr(t *testing.T) {
45-
api := new(pkg.MockAPI)
45+
api := new(spotify.MockAPI)
4646
api.On("Status").Return(new(model.Playback), nil)
4747
api.On("Back").Return(errors.New(internal.RestrictionViolatedSpotifyErr))
4848

@@ -51,7 +51,7 @@ func TestNoPreviousErr(t *testing.T) {
5151
}
5252

5353
func TestNoActiveDeviceErr(t *testing.T) {
54-
api := new(pkg.MockAPI)
54+
api := new(spotify.MockAPI)
5555
api.On("Status").Return(nil, nil)
5656

5757
_, err := back(api)

internal/login/login.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11-
"spotify/pkg"
12-
"spotify/pkg/model"
1311
"time"
1412

13+
"github.com/brianstrauch/spotify"
14+
"github.com/brianstrauch/spotify/model"
1515
"github.com/pkg/browser"
1616
"github.com/spf13/cobra"
1717
"github.com/spf13/viper"
@@ -60,7 +60,7 @@ func authorize() (*model.Token, error) {
6060
// https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce
6161

6262
// 1. Create the code verifier and challenge
63-
verifier, challenge, err := pkg.StartProof()
63+
verifier, challenge, err := spotify.StartProof()
6464
if err != nil {
6565
return nil, err
6666
}
@@ -70,7 +70,9 @@ func authorize() (*model.Token, error) {
7070
if err != nil {
7171
return nil, err
7272
}
73-
uri := pkg.BuildAuthURI(RedirectURI, challenge, state)
73+
74+
scope := "user-library-modify user-modify-playback-state user-read-playback-state"
75+
uri := spotify.BuildAuthURI(RedirectURI, challenge, state, scope)
7476

7577
// 3. Your app redirects the user to the authorization URI
7678
if err := browser.OpenURL(uri); err != nil {
@@ -83,7 +85,7 @@ func authorize() (*model.Token, error) {
8385
}
8486

8587
// 4. Your app exchanges the code for an access token
86-
token, err := pkg.RequestToken(code, RedirectURI, verifier)
88+
token, err := spotify.RequestToken(code, RedirectURI, verifier)
8789
if err != nil {
8890
return nil, err
8991
}

internal/next/next.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"errors"
55
"spotify/internal"
66
"spotify/internal/status"
7-
"spotify/pkg"
8-
"spotify/pkg/model"
97

8+
"github.com/brianstrauch/spotify"
9+
"github.com/brianstrauch/spotify/model"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -32,7 +32,7 @@ func NewCommand() *cobra.Command {
3232
}
3333
}
3434

35-
func next(api pkg.APIInterface) (string, error) {
35+
func next(api spotify.APIInterface) (string, error) {
3636
playback, err := api.Status()
3737
if err != nil {
3838
return "", err

internal/next/next_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package next
22

33
import (
44
"spotify/internal"
5-
"spotify/pkg"
6-
"spotify/pkg/model"
75
"testing"
86

7+
"github.com/brianstrauch/spotify"
8+
"github.com/brianstrauch/spotify/model"
99
"github.com/stretchr/testify/mock"
1010
"github.com/stretchr/testify/require"
1111
)
1212

1313
func TestNextCommand(t *testing.T) {
14-
api := new(pkg.MockAPI)
14+
api := new(spotify.MockAPI)
1515

1616
playback1 := &model.Playback{
1717
IsPlaying: true,
@@ -41,7 +41,7 @@ func TestNextCommand(t *testing.T) {
4141
}
4242

4343
func TestNoActiveDeviceErr(t *testing.T) {
44-
api := new(pkg.MockAPI)
44+
api := new(spotify.MockAPI)
4545
api.On("Status").Return(nil, nil)
4646

4747
_, err := next(api)

internal/p/p.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"spotify/internal"
66
"spotify/internal/pause"
77
"spotify/internal/play"
8-
"spotify/pkg"
98
"strings"
109

10+
"github.com/brianstrauch/spotify"
1111
"github.com/spf13/cobra"
1212
)
1313

@@ -40,7 +40,7 @@ func NewCommand() *cobra.Command {
4040
}
4141
}
4242

43-
func p(api pkg.APIInterface) (string, error) {
43+
func p(api spotify.APIInterface) (string, error) {
4444
playback, err := api.Status()
4545
if err != nil {
4646
return "", err

0 commit comments

Comments
 (0)