diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 75c1218..a36fa66 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -2,6 +2,8 @@ README.md analysis_options.yaml doc/ChannelInfo.md +doc/Comment.md +doc/CommentsPage.md doc/ExceptionError.md doc/Regions.md doc/Stream.md @@ -21,6 +23,8 @@ lib/src/auth/bearer_auth.dart lib/src/auth/oauth.dart lib/src/date_serializer.dart lib/src/model/channel_info.dart +lib/src/model/comment.dart +lib/src/model/comments_page.dart lib/src/model/date.dart lib/src/model/exception_error.dart lib/src/model/regions.dart @@ -31,3 +35,5 @@ lib/src/model/subtitle.dart lib/src/model/video_info.dart lib/src/serializers.dart pubspec.yaml +test/comment_test.dart +test/comments_page_test.dart diff --git a/README.md b/README.md index 798f577..0ae6f47 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ Class | Method | HTTP request | Description [*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**channelInfoName**](doc/UnauthenticatedApi.md#channelinfoname) | **GET** /c/{name} | Gets Channel Information [*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**channelInfoUsername**](doc/UnauthenticatedApi.md#channelinfousername) | **GET** /user/{username} | Gets Channel Information [*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**channelNextPage**](doc/UnauthenticatedApi.md#channelnextpage) | **GET** /nextpage/channel/{channelId} | Gets more channel videos +[*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**comments**](doc/UnauthenticatedApi.md#comments) | **GET** /comments/{videoId} | Gets Comments +[*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**commentsNextPage**](doc/UnauthenticatedApi.md#commentsnextpage) | **GET** /nextpage/comments/{videoId} | Gets more comments [*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**streamInfo**](doc/UnauthenticatedApi.md#streaminfo) | **GET** /streams/{videoId} | Gets Video Information [*UnauthenticatedApi*](doc/UnauthenticatedApi.md) | [**trending**](doc/UnauthenticatedApi.md#trending) | **GET** /trending | Gets all Trending Videos @@ -76,6 +78,8 @@ Class | Method | HTTP request | Description ## Documentation For Models - [ChannelInfo](doc/ChannelInfo.md) + - [Comment](doc/Comment.md) + - [CommentsPage](doc/CommentsPage.md) - [ExceptionError](doc/ExceptionError.md) - [Regions](doc/Regions.md) - [Stream](doc/Stream.md) diff --git a/doc/Comment.md b/doc/Comment.md new file mode 100644 index 0000000..60f8acd --- /dev/null +++ b/doc/Comment.md @@ -0,0 +1,25 @@ +# piped_api.model.Comment + +## Load the model package +```dart +import 'package:piped_api/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**author** | **String** | The name of the author of the comment. | [optional] +**thumbnail** | **String** | The thumbnail/avatar of the author of the comment. | [optional] +**commentId** | **String** | The ID of the comment. | [optional] +**commentText** | **String** | The text of the comment. | [optional] +**commentedTime** | **String** | The relative time the comment was made. | [optional] +**commentorUrl** | **String** | The relative URL of the author of the comment. | [optional] +**repliesPage** | **String** | The parameter used as the nextpage to fetch replies for this comment. | [optional] +**likeCount** | **int** | The number of likes the comment has. | [optional] +**hearted** | **bool** | Whether the comment was hearted by the video's uploader. | [optional] +**pinned** | **bool** | Whether the comment was pinned by the video's uploader. | [optional] +**verified** | **bool** | Whether the author of the comment is verified. | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/doc/CommentsPage.md b/doc/CommentsPage.md new file mode 100644 index 0000000..b2458cb --- /dev/null +++ b/doc/CommentsPage.md @@ -0,0 +1,17 @@ +# piped_api.model.CommentsPage + +## Load the model package +```dart +import 'package:piped_api/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**comments** | [**BuiltList<Comment>**](Comment.md) | | [optional] +**nextpage** | **String** | The parameter used to get the next page of comments. | [optional] +**disabled** | **bool** | Whether or not comments are disabled on the video. | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/doc/UnauthenticatedApi.md b/doc/UnauthenticatedApi.md index 3e70c8e..fa52b31 100644 --- a/doc/UnauthenticatedApi.md +++ b/doc/UnauthenticatedApi.md @@ -13,6 +13,8 @@ Method | HTTP request | Description [**channelInfoName**](UnauthenticatedApi.md#channelinfoname) | **GET** /c/{name} | Gets Channel Information [**channelInfoUsername**](UnauthenticatedApi.md#channelinfousername) | **GET** /user/{username} | Gets Channel Information [**channelNextPage**](UnauthenticatedApi.md#channelnextpage) | **GET** /nextpage/channel/{channelId} | Gets more channel videos +[**comments**](UnauthenticatedApi.md#comments) | **GET** /comments/{videoId} | Gets Comments +[**commentsNextPage**](UnauthenticatedApi.md#commentsnextpage) | **GET** /nextpage/comments/{videoId} | Gets more comments [**streamInfo**](UnauthenticatedApi.md#streaminfo) | **GET** /streams/{videoId} | Gets Video Information [**trending**](UnauthenticatedApi.md#trending) | **GET** /trending | Gets all Trending Videos @@ -191,6 +193,94 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **comments** +> CommentsPage comments(videoId) + +Gets Comments + +Gets the comments for a video. + +### Example +```dart +import 'package:piped_api/api.dart'; + +final api = PipedApi().getUnauthenticatedApi(); +final String videoId = dQw4w9WgXcQ; // String | The video ID of the YouTube video you want to get comments from. + +try { + final response = api.comments(videoId); + print(response); +} catch on DioError (e) { + print('Exception when calling UnauthenticatedApi->comments: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **videoId** | **String**| The video ID of the YouTube video you want to get comments from. | + +### Return type + +[**CommentsPage**](CommentsPage.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **commentsNextPage** +> CommentsPage commentsNextPage(videoId, nextpage) + +Gets more comments + +Gets more comments. + +### Example +```dart +import 'package:piped_api/api.dart'; + +final api = PipedApi().getUnauthenticatedApi(); +final String videoId = dQw4w9WgXcQ; // String | The video ID of the YouTube video you want to get more comments from. +final String nextpage = nextpage_example; // String | The next page token to get more comments from. + +try { + final response = api.commentsNextPage(videoId, nextpage); + print(response); +} catch on DioError (e) { + print('Exception when calling UnauthenticatedApi->commentsNextPage: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **videoId** | **String**| The video ID of the YouTube video you want to get more comments from. | + **nextpage** | **String**| The next page token to get more comments from. | + +### Return type + +[**CommentsPage**](CommentsPage.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **streamInfo** > VideoInfo streamInfo(videoId) diff --git a/lib/piped_api.dart b/lib/piped_api.dart index a7cdb99..c487b1d 100644 --- a/lib/piped_api.dart +++ b/lib/piped_api.dart @@ -12,6 +12,8 @@ export 'package:piped_api/src/model/date.dart'; export 'package:piped_api/src/api/unauthenticated_api.dart'; export 'package:piped_api/src/model/channel_info.dart'; +export 'package:piped_api/src/model/comment.dart'; +export 'package:piped_api/src/model/comments_page.dart'; export 'package:piped_api/src/model/exception_error.dart'; export 'package:piped_api/src/model/regions.dart'; export 'package:piped_api/src/model/stream.dart'; diff --git a/lib/src/api/unauthenticated_api.dart b/lib/src/api/unauthenticated_api.dart index 5fd6943..4f32fbc 100644 --- a/lib/src/api/unauthenticated_api.dart +++ b/lib/src/api/unauthenticated_api.dart @@ -10,6 +10,7 @@ import 'package:dio/dio.dart'; import 'package:built_collection/built_collection.dart'; import 'package:piped_api/src/api_util.dart'; import 'package:piped_api/src/model/channel_info.dart'; +import 'package:piped_api/src/model/comments_page.dart'; import 'package:piped_api/src/model/exception_error.dart'; import 'package:piped_api/src/model/regions.dart'; import 'package:piped_api/src/model/stream_item.dart'; @@ -327,6 +328,161 @@ class UnauthenticatedApi { ); } + /// Gets Comments + /// Gets the comments for a video. + /// + /// Parameters: + /// * [videoId] - The video ID of the YouTube video you want to get comments from. + /// * [cancelToken] - A [CancelToken] that can be used to cancel the operation + /// * [headers] - Can be used to add additional headers to the request + /// * [extras] - Can be used to add flags to the request + /// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response + /// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress + /// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress + /// + /// Returns a [Future] containing a [Response] with a [CommentsPage] as data + /// Throws [DioError] if API call or serialization fails + Future> comments({ + required String videoId, + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/comments/{videoId}'.replaceAll('{' r'videoId' '}', videoId.toString()); + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _response = await _dio.request( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + CommentsPage _responseData; + + try { + const _responseType = FullType(CommentsPage); + _responseData = _serializers.deserialize( + _response.data!, + specifiedType: _responseType, + ) as CommentsPage; + + } catch (error, stackTrace) { + throw DioError( + requestOptions: _response.requestOptions, + response: _response, + type: DioErrorType.other, + error: error, + )..stackTrace = stackTrace; + } + + return Response( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + + /// Gets more comments + /// Gets more comments. + /// + /// Parameters: + /// * [videoId] - The video ID of the YouTube video you want to get more comments from. + /// * [nextpage] - The next page token to get more comments from. + /// * [cancelToken] - A [CancelToken] that can be used to cancel the operation + /// * [headers] - Can be used to add additional headers to the request + /// * [extras] - Can be used to add flags to the request + /// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response + /// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress + /// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress + /// + /// Returns a [Future] containing a [Response] with a [CommentsPage] as data + /// Throws [DioError] if API call or serialization fails + Future> commentsNextPage({ + required String videoId, + required String nextpage, + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/nextpage/comments/{videoId}'.replaceAll('{' r'videoId' '}', videoId.toString()); + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _queryParameters = { + r'nextpage': encodeQueryParameter(_serializers, nextpage, const FullType(String)), + }; + + final _response = await _dio.request( + _path, + options: _options, + queryParameters: _queryParameters, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + CommentsPage _responseData; + + try { + const _responseType = FullType(CommentsPage); + _responseData = _serializers.deserialize( + _response.data!, + specifiedType: _responseType, + ) as CommentsPage; + + } catch (error, stackTrace) { + throw DioError( + requestOptions: _response.requestOptions, + response: _response, + type: DioErrorType.other, + error: error, + )..stackTrace = stackTrace; + } + + return Response( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + /// Gets Video Information /// Gets all available Stream information about a video. /// diff --git a/lib/src/model/comment.dart b/lib/src/model/comment.dart new file mode 100644 index 0000000..55d853c --- /dev/null +++ b/lib/src/model/comment.dart @@ -0,0 +1,232 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'comment.g.dart'; + +/// Comment +/// +/// Properties: +/// * [author] - The name of the author of the comment. +/// * [thumbnail] - The thumbnail/avatar of the author of the comment. +/// * [commentId] - The ID of the comment. +/// * [commentText] - The text of the comment. +/// * [commentedTime] - The relative time the comment was made. +/// * [commentorUrl] - The relative URL of the author of the comment. +/// * [repliesPage] - The parameter used as the nextpage to fetch replies for this comment. +/// * [likeCount] - The number of likes the comment has. +/// * [hearted] - Whether the comment was hearted by the video's uploader. +/// * [pinned] - Whether the comment was pinned by the video's uploader. +/// * [verified] - Whether the author of the comment is verified. +abstract class Comment implements Built { + /// The name of the author of the comment. + @BuiltValueField(wireName: r'author') + String? get author; + + /// The thumbnail/avatar of the author of the comment. + @BuiltValueField(wireName: r'thumbnail') + String? get thumbnail; + + /// The ID of the comment. + @BuiltValueField(wireName: r'commentId') + String? get commentId; + + /// The text of the comment. + @BuiltValueField(wireName: r'commentText') + String? get commentText; + + /// The relative time the comment was made. + @BuiltValueField(wireName: r'commentedTime') + String? get commentedTime; + + /// The relative URL of the author of the comment. + @BuiltValueField(wireName: r'commentorUrl') + String? get commentorUrl; + + /// The parameter used as the nextpage to fetch replies for this comment. + @BuiltValueField(wireName: r'repliesPage') + String? get repliesPage; + + /// The number of likes the comment has. + @BuiltValueField(wireName: r'likeCount') + int? get likeCount; + + /// Whether the comment was hearted by the video's uploader. + @BuiltValueField(wireName: r'hearted') + bool? get hearted; + + /// Whether the comment was pinned by the video's uploader. + @BuiltValueField(wireName: r'pinned') + bool? get pinned; + + /// Whether the author of the comment is verified. + @BuiltValueField(wireName: r'verified') + bool? get verified; + + Comment._(); + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CommentBuilder b) => b; + + factory Comment([void updates(CommentBuilder b)]) = _$Comment; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CommentSerializer(); +} + +class _$CommentSerializer implements StructuredSerializer { + @override + final Iterable types = const [Comment, _$Comment]; + + @override + final String wireName = r'Comment'; + + @override + Iterable serialize(Serializers serializers, Comment object, + {FullType specifiedType = FullType.unspecified}) { + final result = []; + if (object.author != null) { + result + ..add(r'author') + ..add(serializers.serialize(object.author, + specifiedType: const FullType(String))); + } + if (object.thumbnail != null) { + result + ..add(r'thumbnail') + ..add(serializers.serialize(object.thumbnail, + specifiedType: const FullType(String))); + } + if (object.commentId != null) { + result + ..add(r'commentId') + ..add(serializers.serialize(object.commentId, + specifiedType: const FullType(String))); + } + if (object.commentText != null) { + result + ..add(r'commentText') + ..add(serializers.serialize(object.commentText, + specifiedType: const FullType(String))); + } + if (object.commentedTime != null) { + result + ..add(r'commentedTime') + ..add(serializers.serialize(object.commentedTime, + specifiedType: const FullType(String))); + } + if (object.commentorUrl != null) { + result + ..add(r'commentorUrl') + ..add(serializers.serialize(object.commentorUrl, + specifiedType: const FullType(String))); + } + if (object.repliesPage != null) { + result + ..add(r'repliesPage') + ..add(serializers.serialize(object.repliesPage, + specifiedType: const FullType(String))); + } + if (object.likeCount != null) { + result + ..add(r'likeCount') + ..add(serializers.serialize(object.likeCount, + specifiedType: const FullType(int))); + } + if (object.hearted != null) { + result + ..add(r'hearted') + ..add(serializers.serialize(object.hearted, + specifiedType: const FullType(bool))); + } + if (object.pinned != null) { + result + ..add(r'pinned') + ..add(serializers.serialize(object.pinned, + specifiedType: const FullType(bool))); + } + if (object.verified != null) { + result + ..add(r'verified') + ..add(serializers.serialize(object.verified, + specifiedType: const FullType(bool))); + } + return result; + } + + @override + Comment deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = CommentBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final Object? value = iterator.current; + + switch (key) { + case r'author': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.author = valueDes; + break; + case r'thumbnail': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.thumbnail = valueDes; + break; + case r'commentId': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.commentId = valueDes; + break; + case r'commentText': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.commentText = valueDes; + break; + case r'commentedTime': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.commentedTime = valueDes; + break; + case r'commentorUrl': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.commentorUrl = valueDes; + break; + case r'repliesPage': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + result.repliesPage = valueDes; + break; + case r'likeCount': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + result.likeCount = valueDes; + break; + case r'hearted': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + result.hearted = valueDes; + break; + case r'pinned': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + result.pinned = valueDes; + break; + case r'verified': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + result.verified = valueDes; + break; + } + } + return result.build(); + } +} + diff --git a/lib/src/model/comment.g.dart b/lib/src/model/comment.g.dart new file mode 100644 index 0000000..62a4058 --- /dev/null +++ b/lib/src/model/comment.g.dart @@ -0,0 +1,218 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'comment.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +class _$Comment extends Comment { + @override + final String? author; + @override + final String? thumbnail; + @override + final String? commentId; + @override + final String? commentText; + @override + final String? commentedTime; + @override + final String? commentorUrl; + @override + final String? repliesPage; + @override + final int? likeCount; + @override + final bool? hearted; + @override + final bool? pinned; + @override + final bool? verified; + + factory _$Comment([void Function(CommentBuilder)? updates]) => + (new CommentBuilder()..update(updates)).build(); + + _$Comment._( + {this.author, + this.thumbnail, + this.commentId, + this.commentText, + this.commentedTime, + this.commentorUrl, + this.repliesPage, + this.likeCount, + this.hearted, + this.pinned, + this.verified}) + : super._(); + + @override + Comment rebuild(void Function(CommentBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CommentBuilder toBuilder() => new CommentBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Comment && + author == other.author && + thumbnail == other.thumbnail && + commentId == other.commentId && + commentText == other.commentText && + commentedTime == other.commentedTime && + commentorUrl == other.commentorUrl && + repliesPage == other.repliesPage && + likeCount == other.likeCount && + hearted == other.hearted && + pinned == other.pinned && + verified == other.verified; + } + + @override + int get hashCode { + return $jf($jc( + $jc( + $jc( + $jc( + $jc( + $jc( + $jc( + $jc( + $jc( + $jc($jc(0, author.hashCode), + thumbnail.hashCode), + commentId.hashCode), + commentText.hashCode), + commentedTime.hashCode), + commentorUrl.hashCode), + repliesPage.hashCode), + likeCount.hashCode), + hearted.hashCode), + pinned.hashCode), + verified.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('Comment') + ..add('author', author) + ..add('thumbnail', thumbnail) + ..add('commentId', commentId) + ..add('commentText', commentText) + ..add('commentedTime', commentedTime) + ..add('commentorUrl', commentorUrl) + ..add('repliesPage', repliesPage) + ..add('likeCount', likeCount) + ..add('hearted', hearted) + ..add('pinned', pinned) + ..add('verified', verified)) + .toString(); + } +} + +class CommentBuilder implements Builder { + _$Comment? _$v; + + String? _author; + String? get author => _$this._author; + set author(String? author) => _$this._author = author; + + String? _thumbnail; + String? get thumbnail => _$this._thumbnail; + set thumbnail(String? thumbnail) => _$this._thumbnail = thumbnail; + + String? _commentId; + String? get commentId => _$this._commentId; + set commentId(String? commentId) => _$this._commentId = commentId; + + String? _commentText; + String? get commentText => _$this._commentText; + set commentText(String? commentText) => _$this._commentText = commentText; + + String? _commentedTime; + String? get commentedTime => _$this._commentedTime; + set commentedTime(String? commentedTime) => + _$this._commentedTime = commentedTime; + + String? _commentorUrl; + String? get commentorUrl => _$this._commentorUrl; + set commentorUrl(String? commentorUrl) => _$this._commentorUrl = commentorUrl; + + String? _repliesPage; + String? get repliesPage => _$this._repliesPage; + set repliesPage(String? repliesPage) => _$this._repliesPage = repliesPage; + + int? _likeCount; + int? get likeCount => _$this._likeCount; + set likeCount(int? likeCount) => _$this._likeCount = likeCount; + + bool? _hearted; + bool? get hearted => _$this._hearted; + set hearted(bool? hearted) => _$this._hearted = hearted; + + bool? _pinned; + bool? get pinned => _$this._pinned; + set pinned(bool? pinned) => _$this._pinned = pinned; + + bool? _verified; + bool? get verified => _$this._verified; + set verified(bool? verified) => _$this._verified = verified; + + CommentBuilder() { + Comment._defaults(this); + } + + CommentBuilder get _$this { + final $v = _$v; + if ($v != null) { + _author = $v.author; + _thumbnail = $v.thumbnail; + _commentId = $v.commentId; + _commentText = $v.commentText; + _commentedTime = $v.commentedTime; + _commentorUrl = $v.commentorUrl; + _repliesPage = $v.repliesPage; + _likeCount = $v.likeCount; + _hearted = $v.hearted; + _pinned = $v.pinned; + _verified = $v.verified; + _$v = null; + } + return this; + } + + @override + void replace(Comment other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Comment; + } + + @override + void update(void Function(CommentBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + _$Comment build() { + final _$result = _$v ?? + new _$Comment._( + author: author, + thumbnail: thumbnail, + commentId: commentId, + commentText: commentText, + commentedTime: commentedTime, + commentorUrl: commentorUrl, + repliesPage: repliesPage, + likeCount: likeCount, + hearted: hearted, + pinned: pinned, + verified: verified); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,deprecated_member_use_from_same_package,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/lib/src/model/comments_page.dart b/lib/src/model/comments_page.dart new file mode 100644 index 0000000..5b75f16 --- /dev/null +++ b/lib/src/model/comments_page.dart @@ -0,0 +1,106 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'package:built_collection/built_collection.dart'; +import 'package:piped_api/src/model/comment.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'comments_page.g.dart'; + +/// CommentsPage +/// +/// Properties: +/// * [comments] +/// * [nextpage] - The parameter used to get the next page of comments. +/// * [disabled] - Whether or not comments are disabled on the video. +abstract class CommentsPage implements Built { + @BuiltValueField(wireName: r'comments') + BuiltList? get comments; + + /// The parameter used to get the next page of comments. + @BuiltValueField(wireName: r'nextpage') + String? get nextpage; + + /// Whether or not comments are disabled on the video. + @BuiltValueField(wireName: r'disabled') + bool? get disabled; + + CommentsPage._(); + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CommentsPageBuilder b) => b; + + factory CommentsPage([void updates(CommentsPageBuilder b)]) = _$CommentsPage; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CommentsPageSerializer(); +} + +class _$CommentsPageSerializer implements StructuredSerializer { + @override + final Iterable types = const [CommentsPage, _$CommentsPage]; + + @override + final String wireName = r'CommentsPage'; + + @override + Iterable serialize(Serializers serializers, CommentsPage object, + {FullType specifiedType = FullType.unspecified}) { + final result = []; + if (object.comments != null) { + result + ..add(r'comments') + ..add(serializers.serialize(object.comments, + specifiedType: const FullType(BuiltList, [FullType(Comment)]))); + } + if (object.nextpage != null) { + result + ..add(r'nextpage') + ..add(serializers.serialize(object.nextpage, + specifiedType: const FullType.nullable(String))); + } + if (object.disabled != null) { + result + ..add(r'disabled') + ..add(serializers.serialize(object.disabled, + specifiedType: const FullType(bool))); + } + return result; + } + + @override + CommentsPage deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = CommentsPageBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final Object? value = iterator.current; + + switch (key) { + case r'comments': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(BuiltList, [FullType(Comment)])) as BuiltList; + result.comments.replace(valueDes); + break; + case r'nextpage': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType.nullable(String)) as String?; + if (valueDes == null) continue; + result.nextpage = valueDes; + break; + case r'disabled': + final valueDes = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + result.disabled = valueDes; + break; + } + } + return result.build(); + } +} + diff --git a/lib/src/model/comments_page.g.dart b/lib/src/model/comments_page.g.dart new file mode 100644 index 0000000..af3910d --- /dev/null +++ b/lib/src/model/comments_page.g.dart @@ -0,0 +1,122 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'comments_page.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +class _$CommentsPage extends CommentsPage { + @override + final BuiltList? comments; + @override + final String? nextpage; + @override + final bool? disabled; + + factory _$CommentsPage([void Function(CommentsPageBuilder)? updates]) => + (new CommentsPageBuilder()..update(updates)).build(); + + _$CommentsPage._({this.comments, this.nextpage, this.disabled}) : super._(); + + @override + CommentsPage rebuild(void Function(CommentsPageBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CommentsPageBuilder toBuilder() => new CommentsPageBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is CommentsPage && + comments == other.comments && + nextpage == other.nextpage && + disabled == other.disabled; + } + + @override + int get hashCode { + return $jf($jc( + $jc($jc(0, comments.hashCode), nextpage.hashCode), disabled.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('CommentsPage') + ..add('comments', comments) + ..add('nextpage', nextpage) + ..add('disabled', disabled)) + .toString(); + } +} + +class CommentsPageBuilder + implements Builder { + _$CommentsPage? _$v; + + ListBuilder? _comments; + ListBuilder get comments => + _$this._comments ??= new ListBuilder(); + set comments(ListBuilder? comments) => _$this._comments = comments; + + String? _nextpage; + String? get nextpage => _$this._nextpage; + set nextpage(String? nextpage) => _$this._nextpage = nextpage; + + bool? _disabled; + bool? get disabled => _$this._disabled; + set disabled(bool? disabled) => _$this._disabled = disabled; + + CommentsPageBuilder() { + CommentsPage._defaults(this); + } + + CommentsPageBuilder get _$this { + final $v = _$v; + if ($v != null) { + _comments = $v.comments?.toBuilder(); + _nextpage = $v.nextpage; + _disabled = $v.disabled; + _$v = null; + } + return this; + } + + @override + void replace(CommentsPage other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$CommentsPage; + } + + @override + void update(void Function(CommentsPageBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + _$CommentsPage build() { + _$CommentsPage _$result; + try { + _$result = _$v ?? + new _$CommentsPage._( + comments: _comments?.build(), + nextpage: nextpage, + disabled: disabled); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'comments'; + _comments?.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + 'CommentsPage', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,deprecated_member_use_from_same_package,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/lib/src/serializers.dart b/lib/src/serializers.dart index 3520fd6..9942fa5 100644 --- a/lib/src/serializers.dart +++ b/lib/src/serializers.dart @@ -13,6 +13,8 @@ import 'package:piped_api/src/date_serializer.dart'; import 'package:piped_api/src/model/date.dart'; import 'package:piped_api/src/model/channel_info.dart'; +import 'package:piped_api/src/model/comment.dart'; +import 'package:piped_api/src/model/comments_page.dart'; import 'package:piped_api/src/model/exception_error.dart'; import 'package:piped_api/src/model/regions.dart'; import 'package:piped_api/src/model/stream.dart'; @@ -25,6 +27,8 @@ part 'serializers.g.dart'; @SerializersFor([ ChannelInfo, + Comment, + CommentsPage, ExceptionError, Regions, Stream, diff --git a/lib/src/serializers.g.dart b/lib/src/serializers.g.dart index 9d75aa3..50ebd96 100644 --- a/lib/src/serializers.g.dart +++ b/lib/src/serializers.g.dart @@ -8,6 +8,8 @@ part of 'serializers.dart'; Serializers _$serializers = (new Serializers().toBuilder() ..add(ChannelInfo.serializer) + ..add(Comment.serializer) + ..add(CommentsPage.serializer) ..add(ExceptionError.serializer) ..add(Regions.serializer) ..add(Stream.serializer) @@ -16,6 +18,9 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(StreamsPage.serializer) ..add(Subtitle.serializer) ..add(VideoInfo.serializer) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(Comment)]), + () => new ListBuilder()) ..addBuilderFactory( const FullType(BuiltList, const [const FullType(Stream)]), () => new ListBuilder()) diff --git a/test/comment_test.dart b/test/comment_test.dart new file mode 100644 index 0000000..3b6c7e9 --- /dev/null +++ b/test/comment_test.dart @@ -0,0 +1,77 @@ +import 'package:test/test.dart'; +import 'package:piped_api/piped_api.dart'; + +// tests for Comment +void main() { + final instance = CommentBuilder(); + // TODO add properties to the builder and call build() + + group(Comment, () { + // The name of the author of the comment. + // String author + test('to test the property `author`', () async { + // TODO + }); + + // The thumbnail/avatar of the author of the comment. + // String thumbnail + test('to test the property `thumbnail`', () async { + // TODO + }); + + // The ID of the comment. + // String commentId + test('to test the property `commentId`', () async { + // TODO + }); + + // The text of the comment. + // String commentText + test('to test the property `commentText`', () async { + // TODO + }); + + // The relative time the comment was made. + // String commentedTime + test('to test the property `commentedTime`', () async { + // TODO + }); + + // The relative URL of the author of the comment. + // String commentorUrl + test('to test the property `commentorUrl`', () async { + // TODO + }); + + // The parameter used as the nextpage to fetch replies for this comment. + // String repliesPage + test('to test the property `repliesPage`', () async { + // TODO + }); + + // The number of likes the comment has. + // int likeCount + test('to test the property `likeCount`', () async { + // TODO + }); + + // Whether the comment was hearted by the video's uploader. + // bool hearted + test('to test the property `hearted`', () async { + // TODO + }); + + // Whether the comment was pinned by the video's uploader. + // bool pinned + test('to test the property `pinned`', () async { + // TODO + }); + + // Whether the author of the comment is verified. + // bool verified + test('to test the property `verified`', () async { + // TODO + }); + + }); +} diff --git a/test/comments_page_test.dart b/test/comments_page_test.dart new file mode 100644 index 0000000..8c6046c --- /dev/null +++ b/test/comments_page_test.dart @@ -0,0 +1,28 @@ +import 'package:test/test.dart'; +import 'package:piped_api/piped_api.dart'; + +// tests for CommentsPage +void main() { + final instance = CommentsPageBuilder(); + // TODO add properties to the builder and call build() + + group(CommentsPage, () { + // BuiltList comments + test('to test the property `comments`', () async { + // TODO + }); + + // The parameter used to get the next page of comments. + // String nextpage + test('to test the property `nextpage`', () async { + // TODO + }); + + // Whether or not comments are disabled on the video. + // bool disabled + test('to test the property `disabled`', () async { + // TODO + }); + + }); +}