Skip to content

Commit

Permalink
Merge pull request #104 from RatakondalaArun/feat/watch-providers
Browse files Browse the repository at this point in the history
feat/watch providers
  • Loading branch information
RatakondalaArun authored Jan 23, 2024
2 parents d78eeba + 5c1311e commit 25daab2
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 63 deletions.
1 change: 1 addition & 0 deletions lib/tmdb_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ part 'versions/v3/category/tv.dart';
part 'versions/v3/category/tv_episode_group.dart';
part 'versions/v3/category/tv_episodes.dart';
part 'versions/v3/category/tv_seasons.dart';
part 'versions/v3/category/watch_providers.dart';
part 'versions/v4.dart';
part 'versions/v4/category/account.dart';
part 'versions/v4/category/auth.dart';
Expand Down
13 changes: 5 additions & 8 deletions lib/utils/tmdb_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ class TMDBException<T> implements Exception {
const TMDBException(this.message, {this.orginal, this.stackTrace});

@override
String toString() =>
'TMDBException(message: $message, orginal: $orginal, stackTrace: $stackTrace)';
String toString() => 'TMDBException(message: $message, orginal: $orginal, stackTrace: $stackTrace)';
}

class TMDBDioError extends TMDBException<DioError> {
class TMDBDioError extends TMDBException<DioException> {
final int? statusCode;

const TMDBDioError(
String message, {
required DioError orginal,
required DioException orginal,
this.statusCode,
}) : super(message, orginal: orginal);

@override
String toString() =>
'TMDBDioError(message: $message,orginal:$orginal, statusCode: $statusCode)';
String toString() => 'TMDBDioError(message: $message,orginal:$orginal, statusCode: $statusCode)';
}

class TMDBOtherException extends TMDBException<dynamic> {
Expand All @@ -34,6 +32,5 @@ class TMDBOtherException extends TMDBException<dynamic> {
StackTrace? stackTrace,
}) : super(message, orginal: orginal, stackTrace: stackTrace);
@override
String toString() =>
'TMDBDioError(message: $message,orginal:$orginal, stackTrace:$stackTrace)';
String toString() => 'TMDBDioError(message: $message,orginal:$orginal, stackTrace:$stackTrace)';
}
3 changes: 3 additions & 0 deletions lib/versions/v3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class V3 extends Version {
late Lists _lists;
late Account _account;
late GuestSession _guestSession;
late WatchProviders _watchProviders;

Movies get movies => _movies;
Tv get tv => _tv;
Expand All @@ -50,6 +51,7 @@ class V3 extends Version {
Lists get lists => _lists;
Account get account => _account;
GuestSession get guestSession => _guestSession;
WatchProviders get watchProviders => _watchProviders;

V3(TMDB tmdb) : super(tmdb, 3) {
_reviews = Reviews(this);
Expand All @@ -76,6 +78,7 @@ class V3 extends Version {
_lists = Lists(this);
_account = Account(this);
_guestSession = GuestSession(this);
_watchProviders = WatchProviders(this);
}

///Queries with the given parameters
Expand Down
70 changes: 70 additions & 0 deletions lib/versions/v3/category/watch_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//tv shows
part of tmdb_api;

/// Watch Providers
class WatchProviders extends Category<V3> {
WatchProviders(V3 v) : super(v, 'watch/providers');

/// Get the list of the countries we have watch provider (OTT/streaming) data for.
///
/// ## Parameters
///
/// `language`: Pass a ISO 639-1 value to display translated data for the fields that support it.
///
/// ## Usage
///
/// ```dart
/// Map result = await tmdb.v3.watchProviders.getAvaliableRegion(language: 'en-US');
/// ```
///
Future<Map> getAvaliableRegion({String? language}) async {
final para = <String>['language=${language ?? _v._tmdb.defaultLanguage}'];
return _v._query('$_endPoint/regions', optionalQueries: para);
}

/// Get the list of streaming providers we have for movies.
///
/// Returns a list of the watch provider (OTT/streaming) data we have available for movies.
/// You can specify a [watchRegion] param if you want to further filter the list by country.
///
/// ## Usage
///
/// ```dart
/// Map result = await tmdb.v3.watchProviders.getMovieProviders(language: 'en-US');
/// ```
Future<Map> getMovieProviders({String? language, String? watchRegion}) async {
final params = {
'language': language ?? _v._tmdb.defaultLanguage,
'watch_region': watchRegion,
};

return _v._query(
'$_endPoint/movie',
optionalQueries:
params.entries.where((element) => element.value != null).map((e) => '${e.key}=${e.value}').toList(),
);
}

/// Get the list of streaming providers we have for TV shows.
///
/// Returns a list of the watch provider (OTT/streaming) data we have available for TV shows.
/// You can specify a [watchRegion] param if you want to further filter the list by country.
///
/// ## Usage
///
/// ```dart
/// Map result = await tmdb.v3.watchProviders.getTVProviders(language: 'en-US');
/// ```
Future<Map> getTVProviders({String? language, String? watchRegion}) async {
final params = {
'language': language ?? _v._tmdb.defaultLanguage,
'watch_region': watchRegion,
};

return _v._query(
'$_endPoint/tv',
optionalQueries:
params.entries.where((element) => element.value != null).map((e) => '${e.key}=${e.value}').toList(),
);
}
}
2 changes: 1 addition & 1 deletion lib/versions/v4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class V4 extends Version {
);
}
return response.data!;
} on DioError catch (e) {
} on DioException catch (e) {
throw TMDBDioError(
e.message!,
orginal: e,
Expand Down
Loading

0 comments on commit 25daab2

Please sign in to comment.