From 9a233d633d3b0cbd3e6cc8369a53607b7913532c Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Sat, 1 Sep 2018 18:42:44 -0700 Subject: [PATCH] 0.4.0 Release (#101) * Added preview property to Submission; prepped for 0.4.0 release * Updated Travis and dart_coveralls config --- .travis.yml | 28 +-- CHANGELOG.md | 312 +++++++++++++++------------- lib/src/models/submission_impl.dart | 59 +++++- lib/src/models/subreddit.dart | 3 +- pubspec.yaml | 17 +- {tools => tool}/travis.sh | 16 +- 6 files changed, 256 insertions(+), 179 deletions(-) rename {tools => tool}/travis.sh (73%) diff --git a/.travis.yml b/.travis.yml index 5e11ac24..84028b28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ -language: dart -sudo: false - -os: - - linux - -dart: - - dev - -script: - - ./tools/travis.sh - - dart test/test_all.dart - - dartfmt -n --set-exit-if-changed . - - dartanalyzer --strong --fatal-warnings --fatal-lints lib/ test/ +language: dart +sudo: false + +os: + - linux + +dart: + - dev + +script: + - ./tool/travis.sh + - dart test/test_all.dart + - dartfmt -n --set-exit-if-changed . + - dartanalyzer --strong --fatal-warnings --fatal-lints lib/ test/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 7892e64d..c9dfd088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,148 +1,164 @@ -Change Log -================================= -## Version 0.3.4 (2018/06/12) -### Deprecation Notice: -`Reddit.createInstance` has been deprecated and will be removed in the 0.4.0 release. Please use one of the following static methods instead: - -* `createReadOnlyInstance` -* `createScriptInstance` -* `createUntrustedReadOnlyInstance` -* `createWebFlowInstance` -* `restoreAuthenticatedInstance` - -### Other changes: -* Added the following static methods to `Reddit`: - * `createWebFlowInstance` -* Added live tests to exercise the web implicit grant flow authentication mode. - - -## Version 0.3.3 (2018/06/08) -* Added the following static methods to `Reddit`: - * `createReadOnlyInstance` - * `createScriptInstance` - * `createUntrustedReadOnlyInstance` - - This should make creating `Reddit` instances simpler and easier to debug. -* Added live tests to exercise the read-only and script authentication modes. - -## Version 0.3.2 (2018/05/07) -Bug fixes: - * Fixed additional Dart 2 runtime type errors. - -## Version 0.3.1 (2018/05/06) -Bug fixes: - * Fixed exception thrown from `WebAuthenticator` when running in Dart 2. - -## Version 0.3.0 (2018/05/05) -### Major breaking changes: -Dropped support for Dart 1.x. Flutter has moved to enable Dart 2 by default -which required some changes in DRAW that are not compatible with Dart 1.x. -Some of these changes required some method signatures to be modified, but -this shouldn't require any changes for users. - -If running in a command-line script, that script must be run using a dev SDK -while passing the `--preview-dart-2` flag. - -If used in a Flutter application, `--preview-dart-2` is enabled by default as -of the Flutter Beta 2 release. - -### Functionality: -* Basic `Multireddit` functionality: - * Added `Multireddit.parse(reddit, data)` constructor that will create an instance of - a `Multireddit`, given the correct `Map` of `data`. - * Added `add(subreddit)` method to add the corresponding `subreddit` to the - instance of `Multireddit`. `subreddit` can be of type `Subreddit` or `String`. - * Added `delete()` method to delete the multireddit. - * Added `copy()` and `copy(multiName)`, this will create a copy of the `Multireddit` for - for the currently authenticated user and return an instance of the new `Multireddit` - encapsulated as a `Future`. When `multiName` is provided it will set the display name - of the new `Multireddit` to `multiName`. - * Added getters for the following properties: `keyColor`, `iconName`, `subreddits`, `author` - `displayName`, `visibility`, `weightingScheme`, `canEdit`, `over18`. -* Comment and Submission moderation. -* Miscellaneous bug fixes. - -## Version 0.2.1 (2018/04/17) -* Added `Reddit.comment`, which allows for the creation of `CommentRef` objects - from a comment ID or url. -* Added `CommentRef.populate` and `Comment.refresh`. -* Added `likes` getter to `Submission`. -* Miscellaneous fixes for minor bugs related to `CommentForest`. - -## Version 0.2.0 (2018/04/13) -Breaking changes: -* `Subreddit.submissions` has been removed as the Reddit API endpoint no longer - exists. See [this - post](https://www.reddit.com/r/changelog/comments/7tus5f/update_to_search_api/) - for context. - -Miscellaneous: -* Added initial support for Fuchsia. draw.ini configurations are not yet - supported on this platform. -* Loosened some version restrictions for pub packages. - -## Version 0.1.6 (2018/04/08) -* Added the property `Reddit.front`, which exposes methods to retrieve content - from the Reddit front page. - -## Version 0.1.5 (2018/04/03) -* Added `Reddit.restoreAuthenticatedInstance`, which can be used to create a - Reddit instance from previously cached credentials. -* Documentation improvements. -* Various bug fixes. - -## Version 0.1.4 (2018/03/31) -* Added `SubredditModeration`, a class which implements moderator functionality for `Subreddit`s. -* Fixed issue #46 which was causing `WebAuthenticator.url` to hit an assertion when `compactLogin` was set -to `true`. - -## Version 0.1.3 (2018/03/22) -* Added additional convenience accessors to various classes, including `Comment`, `Redditor`, `Submission`, -and `Subreddit`. -* Added classes `SubredditFilters` and `SubredditQuarantine`. - -## Version 0.1.2 (2018/03/04) -Breaking changes: -* Removed `property` method. Properties of initialized objects that do not yet have convenience -accessors can be accessed through the `data` property -* Removed `fullname`, `id`, and `data` fields from lazily initialized objects -* Removed `refresh()` from lazily initialized objects - -Miscellaneous: -* Improved documentation -* Various internal refactoring - -## Version 0.1.1 (2018/03/03) -Minor bug fix: -* Fixed issue where `DRAWConfigContext` would throw an exception on Android and iOS. - -## Version 0.1.0 (2018/03/03) -Breaking changes: -* Created separate classes for lazily initialized and initialized instances -* Deprecated the `property` method. Will be completely removed in the near future - -Major changes and bug fixes: -* Added `Inbox` and `Message` functionality -* Added convenience accessors for common properties. Properties without an accessor can be accessed - through the `data` map in each object -* Additional fixes to `DRAWConfigContext` -* Rolled `package:quiver` forward to version `0.28.0` to match that used by `flutter_test` - -## Version 0.0.3 (2018/01/22) -Minor changes and bug fixes: -* Fixed bug that caused authentication to fail when using `draw.ini` with the `ScriptAuthenticator` -* Refactored `DRAWConfigContext` - -## Version 0.0.2 (2017/12/15) -Minor updates: -* Added `CHANGELOG.md` -* Formatted sample code in `README.md` -* Renamed `.analysis_options` to `analysis_options.yaml` -* Documentation added for classes and methods that had none -* Commented out currently unimplemented functionality to clean up generated - documents - -## Version 0.0.1 (2017/12/08) -Initial release with basic functionality, including: -* OAuth2 support for login -* `Comment`, `Redditor`, and `Subreddit` interfaces +Change Log +================================= +## Version 0.4.0 (2018/09/01) +### Major breaking changes: +`Reddit.createInstance` has been removed. Please use one of the following static methods instead: + +* `createReadOnlyInstance` +* `createScriptInstance` +* `createUntrustedReadOnlyInstance` +* `createWebFlowInstance` +* `restoreAuthenticatedInstance` + +## Other changes: +* Bumped SDK constraints to reflect official Dart 2.0 release. +* Added `SubmissionPreview` and `PreviewImage` which represent preview images for a `Submission`. +* Added `preview` to `Submission`, which returns a `List`. +* Fixed various bugs discovered while improving code coverage. + +## Version 0.3.4 (2018/06/12) +### Deprecation Notice: +`Reddit.createInstance` has been deprecated and will be removed in the 0.4.0 release. Please use one of the following static methods instead: + +* `createReadOnlyInstance` +* `createScriptInstance` +* `createUntrustedReadOnlyInstance` +* `createWebFlowInstance` +* `restoreAuthenticatedInstance` + +### Other changes: +* Added the following static methods to `Reddit`: + * `createWebFlowInstance` +* Added live tests to exercise the web implicit grant flow authentication mode. + + +## Version 0.3.3 (2018/06/08) +* Added the following static methods to `Reddit`: + * `createReadOnlyInstance` + * `createScriptInstance` + * `createUntrustedReadOnlyInstance` + + This should make creating `Reddit` instances simpler and easier to debug. +* Added live tests to exercise the read-only and script authentication modes. + +## Version 0.3.2 (2018/05/07) +Bug fixes: + * Fixed additional Dart 2 runtime type errors. + +## Version 0.3.1 (2018/05/06) +Bug fixes: + * Fixed exception thrown from `WebAuthenticator` when running in Dart 2. + +## Version 0.3.0 (2018/05/05) +### Major breaking changes: +Dropped support for Dart 1.x. Flutter has moved to enable Dart 2 by default +which required some changes in DRAW that are not compatible with Dart 1.x. +Some of these changes required some method signatures to be modified, but +this shouldn't require any changes for users. + +If running in a command-line script, that script must be run using a dev SDK +while passing the `--preview-dart-2` flag. + +If used in a Flutter application, `--preview-dart-2` is enabled by default as +of the Flutter Beta 2 release. + +### Functionality: +* Basic `Multireddit` functionality: + * Added `Multireddit.parse(reddit, data)` constructor that will create an instance of + a `Multireddit`, given the correct `Map` of `data`. + * Added `add(subreddit)` method to add the corresponding `subreddit` to the + instance of `Multireddit`. `subreddit` can be of type `Subreddit` or `String`. + * Added `delete()` method to delete the multireddit. + * Added `copy()` and `copy(multiName)`, this will create a copy of the `Multireddit` for + for the currently authenticated user and return an instance of the new `Multireddit` + encapsulated as a `Future`. When `multiName` is provided it will set the display name + of the new `Multireddit` to `multiName`. + * Added getters for the following properties: `keyColor`, `iconName`, `subreddits`, `author` + `displayName`, `visibility`, `weightingScheme`, `canEdit`, `over18`. +* Comment and Submission moderation. +* Miscellaneous bug fixes. + +## Version 0.2.1 (2018/04/17) +* Added `Reddit.comment`, which allows for the creation of `CommentRef` objects + from a comment ID or url. +* Added `CommentRef.populate` and `Comment.refresh`. +* Added `likes` getter to `Submission`. +* Miscellaneous fixes for minor bugs related to `CommentForest`. + +## Version 0.2.0 (2018/04/13) +Breaking changes: +* `Subreddit.submissions` has been removed as the Reddit API endpoint no longer + exists. See [this + post](https://www.reddit.com/r/changelog/comments/7tus5f/update_to_search_api/) + for context. + +Miscellaneous: +* Added initial support for Fuchsia. draw.ini configurations are not yet + supported on this platform. +* Loosened some version restrictions for pub packages. + +## Version 0.1.6 (2018/04/08) +* Added the property `Reddit.front`, which exposes methods to retrieve content + from the Reddit front page. + +## Version 0.1.5 (2018/04/03) +* Added `Reddit.restoreAuthenticatedInstance`, which can be used to create a + Reddit instance from previously cached credentials. +* Documentation improvements. +* Various bug fixes. + +## Version 0.1.4 (2018/03/31) +* Added `SubredditModeration`, a class which implements moderator functionality for `Subreddit`s. +* Fixed issue #46 which was causing `WebAuthenticator.url` to hit an assertion when `compactLogin` was set +to `true`. + +## Version 0.1.3 (2018/03/22) +* Added additional convenience accessors to various classes, including `Comment`, `Redditor`, `Submission`, +and `Subreddit`. +* Added classes `SubredditFilters` and `SubredditQuarantine`. + +## Version 0.1.2 (2018/03/04) +Breaking changes: +* Removed `property` method. Properties of initialized objects that do not yet have convenience +accessors can be accessed through the `data` property +* Removed `fullname`, `id`, and `data` fields from lazily initialized objects +* Removed `refresh()` from lazily initialized objects + +Miscellaneous: +* Improved documentation +* Various internal refactoring + +## Version 0.1.1 (2018/03/03) +Minor bug fix: +* Fixed issue where `DRAWConfigContext` would throw an exception on Android and iOS. + +## Version 0.1.0 (2018/03/03) +Breaking changes: +* Created separate classes for lazily initialized and initialized instances +* Deprecated the `property` method. Will be completely removed in the near future + +Major changes and bug fixes: +* Added `Inbox` and `Message` functionality +* Added convenience accessors for common properties. Properties without an accessor can be accessed + through the `data` map in each object +* Additional fixes to `DRAWConfigContext` +* Rolled `package:quiver` forward to version `0.28.0` to match that used by `flutter_test` + +## Version 0.0.3 (2018/01/22) +Minor changes and bug fixes: +* Fixed bug that caused authentication to fail when using `draw.ini` with the `ScriptAuthenticator` +* Refactored `DRAWConfigContext` + +## Version 0.0.2 (2017/12/15) +Minor updates: +* Added `CHANGELOG.md` +* Formatted sample code in `README.md` +* Renamed `.analysis_options` to `analysis_options.yaml` +* Documentation added for classes and methods that had none +* Commented out currently unimplemented functionality to clean up generated + documents + +## Version 0.0.1 (2017/12/08) +Initial release with basic functionality, including: +* OAuth2 support for login +* `Comment`, `Redditor`, and `Subreddit` interfaces diff --git a/lib/src/models/submission_impl.dart b/lib/src/models/submission_impl.dart index 1ef15090..65799e61 100644 --- a/lib/src/models/submission_impl.dart +++ b/lib/src/models/submission_impl.dart @@ -39,8 +39,8 @@ Comment getCommentByIdInternal(SubmissionRef s, String id) { void insertCommentById(SubmissionRef s, /*Comment, MoreComments*/ c) { assert((c is Comment) || (c is MoreComments)); - _logger.info('insertCommentById: Comment(id:${c.fullname}) Submission(id:${s - ._id},hash:${s.hashCode})'); + _logger.info( + 'insertCommentById: Comment(id:${c.fullname}) Submission(id:${s._id},hash:${s.hashCode})'); s._commentsById[c.fullname] = c; if ((c is Comment) && (c.replies != null)) { for (final reply in c.replies.toList()) { @@ -199,6 +199,22 @@ class Submission extends SubmissionRef /// Is this [Submission] restricted to [Redditor]s 18+. bool get over18 => data['over_18']; + /// The preview images for this [Submission]. + /// + /// Returns an empty list if the [Submission] does not have a preview image. + List get preview { + final previews = []; + if (!data.containsKey('preview')) { + return previews; + } + assert(data['preview'].containsKey('images')); + final raw = data['preview']['images'].cast>(); + for (final i in raw) { + previews.add(SubmissionPreview._fromMap(i)); + } + return previews; + } + /// Is this [Submission] pinned. bool get pinned => data['pinned']; @@ -399,6 +415,45 @@ class SubmissionRef extends UserContent { } } +/// A representation of a submission's preview. +class SubmissionPreview { + /// The preview ID. + String get id => _id; + + /// A list of preview images scaled to various resolutions. + List get resolutions => _resolutions; + + /// The original source of the preview image. + PreviewImage get source => _source; + + PreviewImage _source; + List _resolutions; + String _id; + + SubmissionPreview._fromMap(Map map) { + final sourceMap = map['source']; + final resolutionsList = map['resolutions'].cast>(); + assert(sourceMap != null); + assert(resolutionsList != null); + + _source = PreviewImage._fromMap(sourceMap); + _resolutions = List(); + resolutionsList.forEach((e) => _resolutions.add(PreviewImage._fromMap(e))); + _id = map['id']; + } +} + +class PreviewImage { + final Uri url; + final int width; + final int height; + + PreviewImage._fromMap(Map map) + : url = Uri.parse(map['url']), + width = map['width'], + height = map['height']; +} + String commentSortTypeToString(CommentSortType t) { switch (t) { case CommentSortType.confidence: diff --git a/lib/src/models/subreddit.dart b/lib/src/models/subreddit.dart index 7778c9ee..30a4fb13 100644 --- a/lib/src/models/subreddit.dart +++ b/lib/src/models/subreddit.dart @@ -606,8 +606,7 @@ class SubredditTraffic { uniques = rawTraffic[1]; String toString() { - return '${periodStart - .toUtc()} => unique visits: $uniques, page views: $pageviews' + return '${periodStart.toUtc()} => unique visits: $uniques, page views: $pageviews' ' subscriptions: $subscriptions'; } } diff --git a/pubspec.yaml b/pubspec.yaml index d284e108..df6c1fc2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,19 +7,26 @@ authors: - Kartik Chopra environment: - sdk: ">=2.0.0-dev <3.0.0" + sdk: ">=2.0.0 <3.0.0" dependencies: collection: '^1.14.3' - color: '^2.0.2' + color: 'any' http: '^0.11.3+14' ini: '^1.1.0' - logging: '0.11.3+1' + logging: '^0.11.3+1' oauth2: '^1.1.0' path: '^1.4.2' quiver: '>=0.26.2 <1.0.0' dev_dependencies: - mockito: '^2.2.1' + mockito: '^3.0.0' reply: '^0.1.2-dev' - test: '^0.12.5' + test: '^1.3.0' + +# TODO(bkonyi): remove these. +# Temporary until package SDK restrictions are updated. +dependency_overrides: + color: '2.0.2' + ini: '1.1.0' + reply: '0.1.2-dev' \ No newline at end of file diff --git a/tools/travis.sh b/tool/travis.sh similarity index 73% rename from tools/travis.sh rename to tool/travis.sh index 8e6b617f..146aa573 100755 --- a/tools/travis.sh +++ b/tool/travis.sh @@ -5,14 +5,14 @@ set -e # Install dart_coveralls; gather and send coverage data. if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "dev" ]; then - # pub global activate dart_coveralls - git clone https://github.com/bkonyi/dart-coveralls.git - cd dart-coveralls - pub get - cd .. + pub global activate dart_coveralls + # git clone https://github.com/bkonyi/dart-coveralls.git + # cd dart-coveralls + # pub get + # cd .. echo "Running coverage..." - # dart_coveralls report - dart dart-coveralls/bin/dart_coveralls.dart report \ + #dart dart-coveralls/bin/dart_coveralls.dart report \ + dart_coveralls report \ --retry 2 \ --exclude-test-files \ --throw-on-error \ @@ -20,7 +20,7 @@ if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "dev" ]; then --preview-dart-2 \ test/test_all.dart echo "Coverage complete." - rm -rf dart-coveralls + # rm -rf dart-coveralls else if [ -z ${COVERALLS_TOKEN+x} ]; then echo "COVERALLS_TOKEN is unset"; fi if [ -z ${TRAVIS_DART_VERSION+x} ]; then