-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch scrobbling and Scrobbler classes #63
Conversation
… internet connections
Also add Alt+T key combo to Syro to insert timestamp to focussed field, and fix unit tests
…upport unit tests across assemblies
Conflicts: src/IF.Lastfm.Core.Tests.Integration/packages.config src/IF.Lastfm.Core.Tests/TestHelper.cs
@Zumicts yo. Do you think this pattern makes sense for you? The intention is that this feature (batching + caching) can be integrated in pretty much one line of code. The core includes a basic non-caching scrobbler (Scrobbler.cs), then scrobblers that use database packages can be distributed separately (the SQLiteScrobbler class in this PR will be distributed in Theoretical code: _scrobbler = new SQLiteScrobbler(auth, databaseFile);
var response = _scrobbler.ScrobbleAsync(track.AsScrobble(DateTimeOffset.Now));
// if _scrobbler.CacheEnabled == true then response.Status will be LastResponseStatus.Cached or LastResponseStatus.CacheFailed, otherwise will be the status of the internal scrobble HTTP request Related issue; I notice in Audiotica you have wrapped calls to the SDK in extra service classes, I'd like for that to be unnecessary if possible to reduce lines of code. So you'd DI ITrackApi directly. Would like your thoughts on that too. |
I think it makes sense, follows the SOLID pattern and in the future it makes it easier to implement other cache scrobblers. All though maybe we can break the cache functionality away from the Scrobbler class and just have something like Yeah, in Audiotica all the related class I use for last.fm are injected. |
Good to hear. Feature should be in master in the next couple days. 👍
I was talking about IScrobblerService specifically. Having a single class to DI is definitely better than seven. Does this class do anything special? If not we can make something like it in Core. |
Oh, yeah it is definitely better to have one class that interacts with the api. The class does not implement anything special. Actually, I think it is using my credential helper class for storing username and password but that can easily be abstracted. EDIT: These rely on the cred helper and should be remove if you plan on distributing it:
|
So I'm thinking of abusing properties a bit and making a super-api class which composes the existing ones. So the README example var auth = new LastAuth("apikey", "apisecret");
// wait for authentication
var response = await auth.GetSessionTokenAsync("username", "pass");
if (response.Success && auth.HasAuthenticated) {
var trackApi = new TrackApi(auth);
var loved = await trackApi.LoveTrackAsync("CIRCLONT6A [141.98][Syrobonkus mix]", "Aphex Twin");
} becomes var lastApi = new SuperLastApi(apikey, apisecret, httpclient, scrobbler);
var response = lastApi.Auth.GetSessionTokenAsync();
if (response.Success && lastApi.Auth.HasAuthenticated)
{
var loved = lastApi.Track.LoveAsync("CIRCLONT6A [141.98][Syrobonkus mix]", "Aphex Twin");
} This'd be flexible to both approaches whilst keeping the codebase tidy. It mirrors the api method names nicely too. |
That seems like a nice way of doing it. Would you use DI, or do some lazy loading like:
|
I don't think it's worth implementing lazy loading since the Super API class will only ever hold around 10 object references. The API classes themselves don't store any references, apart from LastAuth (strings and UserSession), and HttpClient if that is provided. public SuperLastApi(string key, string secret, HttpClient httpClient = null, IScrobbler scrobbler = null)
{
var client = httpClient ?? new HttpClient(); // TODO copy options from command base
Auth = new LastAuth(key, secret, client);
Scrobbler = scrobbler ?? new Scrobbler(client);
Track = new TrackApi(client);
Album = new AlbumApi(client);
Artist = new ArtistApi(client);
Library = new LibraryApi(client);
// etc.
} |
Didn't see this edit earlier. This depends on whether there are other kinds of things we can do with a database in the SDK; |
I guess you're right but should it implement Ok, let's keep what we have and improve as we go, after all this is just 0.2 and we have a long way to 1.0 😆 |
Now that I think of it, all commands should be disposable since each one is using an |
Yuuuuuuup. >_>
#41 covers this, commands created inside a *Api class will use the same HttpClient. *Api classes should be disposable though. I'll do that as part of this PR |
… marking ITrackApi.ScrobbleAsync as obsolete
Adjusted generate method signature to sort by ASCII order
Conflicts: src/IF.Lastfm.Core/Api/Enums/LastResponseStatus.cs
TODO test batching combined with caching in unit tests
Batching and caching scrobbler classes.
Tracking issue for the new auto-caching + batching scrobbler
TODO