Skip to content

Commit

Permalink
SearchAPI export
Browse files Browse the repository at this point in the history
Exported `SearchAPI` interface to public interface.
Updated initialization method for `Tidal` interface.
  • Loading branch information
filippomenchini committed Nov 20, 2023
1 parent 7197789 commit 0d19fd2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/src/search/search_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// ignore_for_file: constant_identifier_names
import 'package:http/http.dart' as http;

import '../authorization/tidal_auth_token.dart';
import '../types/tidal_search_response.dart';
import 'search_for_catalog_items_impl.dart';

enum TidalSearchType {
UNDEFINED,
Expand Down Expand Up @@ -38,3 +41,31 @@ abstract class SearchAPI {
TidalSearchPopularity popularity = TidalSearchPopularity.UNDEFINED,
});
}

/// An implementation of the [SearchAPI] interface for accessing Tidal search interface.
class SearchAPIImpl implements SearchAPI {
final http.Client client;
final TidalAuthToken tidalAuthToken;

/// Creates a [SearchAPIImpl] instance with the specified [client] and [tidalAuthToken].
const SearchAPIImpl({
required this.client,
required this.tidalAuthToken,
});

@override
Future<TidalSearchResponse> searchForCatalogItems({
required String query,
required String countryCode,
int offset = 0,
int limit = 10,
TidalSearchType type = TidalSearchType.UNDEFINED,
TidalSearchPopularity popularity = TidalSearchPopularity.UNDEFINED,
}) =>
searchForCatalogItemsImpl(
client,
tidalAuthToken: tidalAuthToken,
query: query,
countryCode: countryCode,
);
}
5 changes: 5 additions & 0 deletions lib/src/tidal_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import 'artist/artist_api.dart';
import 'tidal_impl.dart';
import 'track/track_api.dart';
import 'video/video_api.dart';
import 'search/search_api.dart';

export 'album/album_api.dart' show AlbumAPI;
export 'artist/artist_api.dart' show ArtistAPI;
export 'track/track_api.dart' show TrackAPI;
export 'video/video_api.dart' show VideoAPI;
export 'search/search_api.dart' show SearchAPI;

/// The entry point for interacting with the Tidal service.
///
Expand All @@ -28,6 +30,9 @@ abstract class Tidal {
/// Provides access to video-related operations through the [VideoAPI] interface.
VideoAPI get video;

/// Provides access to search-related operations through the [SearchAPI] interface.
SearchAPI get search;

/// Initializes and sets up a Tidal instance for making API requests.
///
/// Parameters:
Expand Down
12 changes: 12 additions & 0 deletions lib/src/tidal_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:http/http.dart' as http;
import 'album/album_api.dart';
import 'artist/artist_api.dart';
import 'authorization/authorize.dart';
import 'search/search_api.dart';
import 'tidal_base.dart';
import 'track/track_api.dart';
import 'video/video_api.dart';
Expand All @@ -13,6 +14,7 @@ class TidalImpl implements Tidal {
final AlbumAPI albumAPI;
final TrackAPI trackAPI;
final VideoAPI videoAPI;
final SearchAPI searchAPI;
final http.Client client;

/// Creates a [TidalImpl] instance with the provided artist and album API implementations and an HTTP client.
Expand All @@ -21,6 +23,7 @@ class TidalImpl implements Tidal {
required this.albumAPI,
required this.trackAPI,
required this.videoAPI,
required this.searchAPI,
required this.client,
});

Expand All @@ -36,6 +39,9 @@ class TidalImpl implements Tidal {
@override
VideoAPI get video => videoAPI;

@override
SearchAPI get search => searchAPI;

@override
void dispose() => client.close();
}
Expand Down Expand Up @@ -82,11 +88,17 @@ Future<Tidal> initializeImpl({
tidalAuthToken: tidalAuthToken,
);

final searchAPI = SearchAPIImpl(
client: client,
tidalAuthToken: tidalAuthToken,
);

return TidalImpl(
artistAPI: artistAPI,
albumAPI: albumAPI,
trackAPI: trackAPI,
videoAPI: videoAPI,
searchAPI: searchAPI,
client: client,
);
}

0 comments on commit 0d19fd2

Please sign in to comment.