-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
package spotlike | ||
|
||
import () | ||
import ( | ||
"context" | ||
|
||
"golang.org/x/oauth2" | ||
|
||
spotify "github.com/zmb3/spotify/v2" | ||
spotifyauth "github.com/zmb3/spotify/v2/auth" | ||
|
||
"github.com/yanosea/spotlike/app/config" | ||
) | ||
|
||
// refreshUseCase is a struct that contains the use case of refreshenticating the Spotify client. | ||
type refreshUseCase struct{} | ||
type refreshUseCase struct { | ||
Authenticator *spotifyauth.Authenticator | ||
Config *config.SpotlikeConfig | ||
} | ||
|
||
// NewRefreshUseCase returns a new instance of the RefreshUseCase struct. | ||
func NewRefreshUseCase() *refreshUseCase { | ||
return &refreshUseCase{} | ||
func NewRefreshUseCase(authenticator *spotifyauth.Authenticator, conf *config.SpotlikeConfig) *refreshUseCase { | ||
return &refreshUseCase{ | ||
Authenticator: authenticator, | ||
Config: conf, | ||
} | ||
} | ||
|
||
// Run returns the output of the RefreshUseCase. | ||
func (uc *refreshUseCase) Run() error { | ||
return nil | ||
func (uc *refreshUseCase) Run() *spotify.Client { | ||
tok := &oauth2.Token{ | ||
TokenType: "bearer", | ||
RefreshToken: uc.Config.SpotifyRefreshToken, | ||
} | ||
|
||
return spotify.New(uc.Authenticator.Client(context.Background(), tok)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters