Skip to content

Commit

Permalink
Merge #227
Browse files Browse the repository at this point in the history
227: refactor!: fixed for the issue (#226) r=myConsciousness a=myConsciousness

# 1. Description

<!-- Provide a description of what this PR is doing.
If you're modifying existing behavior, describe the existing behavior, how this PR is changing it,
and what motivated the change. If this is a breaking change, specify explicitly which APIs have been
changed. -->

## 1.1. Checklist

<!-- Before you create this PR confirm that it meets all requirements listed below by checking the
relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. -->

- [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc).
- [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs.
- [x] I have updated/added tests for ALL new/updated/fixed functionality.
- [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`.
- [x] I have updated/added relevant examples in `examples`.

## 1.2. Breaking Change

<!-- Does your PR require users to manually update their apps to accommodate your change?

If the PR is a breaking change this should be indicated with suffix "!"  (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details.
-->

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

## 1.3. Related Issues

<!-- Provide a list of issues related to this PR from the [issue database].
Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !-->

<!-- Links -->

[issue database]: https://github.com/twitter-dart/twitter-api-v2/issues
[contributor guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/CONTRIBUTING.md
[style guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <kato.shinya.dev@gmail.com>
  • Loading branch information
bors[bot] and myConsciousness authored Jun 8, 2022
2 parents a1ad8ab + fdfa5af commit 3109a27
Show file tree
Hide file tree
Showing 41 changed files with 333 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Note

## v2.6.0

- Added `FilteredStreamResponse` as the return type of `Filtered Stream` endpoint. And now we can see the IDs and tags of the rules matched in the streaming from the `FilteredStreamResponse.matchingRules` field. The `FilteredStreamResponse` extends `TwitterResponse`, so there are no destructive changes. ([#226](https://github.com/twitter-dart/twitter-api-v2/issues/226))

## v2.5.0

- Added `spaceFields` argument. ([#184](https://github.com/twitter-dart/twitter-api-v2/issues/184))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ void main() async {
final filteredStream = await twitter.tweetsService.connectFilteredStream();
await for (final response in filteredStream.handleError(print)) {
print(response);
print(response.data);
print(response.matchingRules);
}
} on v2.TwitterException catch (e) {
print(e.response.headers);
Expand Down
3 changes: 2 additions & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void main() async {

final filteredStream = await twitter.tweetsService.connectFilteredStream();
await for (final response in filteredStream.handleError(print)) {
print(response);
print(response.data);
print(response.matchingRules);
}
} on v2.TwitterException catch (e) {
print(e.response.headers);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/service/base_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import 'package:http/http.dart' as http;
import '../client/client_context.dart';
import '../client/user_context.dart';
import '../twitter_exception.dart';
import 'includes.dart';
import 'serializable.dart';
import 'common/includes.dart';
import 'common/serializable.dart';
import 'twitter_response.dart';

abstract class Service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import 'package:freezed_annotation/freezed_annotation.dart';

// Project imports:
import 'media/media_data.dart';
import 'places/place_data.dart';
import 'polls/poll_data.dart';
import 'tweets/tweet_data.dart';
import 'users/user_data.dart';
import '../media/media_data.dart';
import '../places/place_data.dart';
import '../polls/poll_data.dart';
import '../tweets/tweet_data.dart';
import '../users/user_data.dart';

part 'includes.freezed.dart';
part 'includes.g.dart';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions lib/src/service/filtered_stream_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// Project imports:
import 'tweets/matching_rule.dart';
import 'tweets/tweet_data.dart';
import 'twitter_response.dart';

class FilteredStreamResponse extends TwitterResponse<TweetData, void> {
/// Returns the new instance of [FilteredStreamResponse].
FilteredStreamResponse({
required super.data,
super.includes,
required this.matchingRules,
});

/// The matching rules
final List<MatchingRule> matchingRules;

@override
String toString() =>
'FilteredStreamResponse(data: $data, includes: $includes, meta: null, '
'matchingRules: $matchingRules)';
}
2 changes: 1 addition & 1 deletion lib/src/service/lists/list_expansion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

/// Represents an extensible field about List.
enum ListExpansion implements Serializable {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/places/place_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

enum PlaceField implements Serializable {
/// `contained_within`
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/polls/poll_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

enum PollField implements Serializable {
/// `id`
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/spaces/space_expansion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

/// Represents an extensible field about Space.
enum SpaceExpansion implements Serializable {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/spaces/space_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

enum SpaceField implements Serializable {
/// `id`
Expand Down
20 changes: 20 additions & 0 deletions lib/src/service/tweets/matching_rule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// Package imports:
import 'package:freezed_annotation/freezed_annotation.dart';

part 'matching_rule.freezed.dart';
part 'matching_rule.g.dart';

@freezed
class MatchingRule with _$MatchingRule {
const factory MatchingRule({
required String id,
required String tag,
}) = _MatchingRule;

factory MatchingRule.fromJson(Map<String, Object?> json) =>
_$MatchingRuleFromJson(json);
}
165 changes: 165 additions & 0 deletions lib/src/service/tweets/matching_rule.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target

part of 'matching_rule.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

MatchingRule _$MatchingRuleFromJson(Map<String, dynamic> json) {
return _MatchingRule.fromJson(json);
}

/// @nodoc
mixin _$MatchingRule {
String get id => throw _privateConstructorUsedError;
String get tag => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$MatchingRuleCopyWith<MatchingRule> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $MatchingRuleCopyWith<$Res> {
factory $MatchingRuleCopyWith(
MatchingRule value, $Res Function(MatchingRule) then) =
_$MatchingRuleCopyWithImpl<$Res>;
$Res call({String id, String tag});
}

/// @nodoc
class _$MatchingRuleCopyWithImpl<$Res> implements $MatchingRuleCopyWith<$Res> {
_$MatchingRuleCopyWithImpl(this._value, this._then);

final MatchingRule _value;
// ignore: unused_field
final $Res Function(MatchingRule) _then;

@override
$Res call({
Object? id = freezed,
Object? tag = freezed,
}) {
return _then(_value.copyWith(
id: id == freezed
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
tag: tag == freezed
? _value.tag
: tag // ignore: cast_nullable_to_non_nullable
as String,
));
}
}

/// @nodoc
abstract class _$$_MatchingRuleCopyWith<$Res>
implements $MatchingRuleCopyWith<$Res> {
factory _$$_MatchingRuleCopyWith(
_$_MatchingRule value, $Res Function(_$_MatchingRule) then) =
__$$_MatchingRuleCopyWithImpl<$Res>;
@override
$Res call({String id, String tag});
}

/// @nodoc
class __$$_MatchingRuleCopyWithImpl<$Res>
extends _$MatchingRuleCopyWithImpl<$Res>
implements _$$_MatchingRuleCopyWith<$Res> {
__$$_MatchingRuleCopyWithImpl(
_$_MatchingRule _value, $Res Function(_$_MatchingRule) _then)
: super(_value, (v) => _then(v as _$_MatchingRule));

@override
_$_MatchingRule get _value => super._value as _$_MatchingRule;

@override
$Res call({
Object? id = freezed,
Object? tag = freezed,
}) {
return _then(_$_MatchingRule(
id: id == freezed
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
tag: tag == freezed
? _value.tag
: tag // ignore: cast_nullable_to_non_nullable
as String,
));
}
}

/// @nodoc
@JsonSerializable()
class _$_MatchingRule implements _MatchingRule {
const _$_MatchingRule({required this.id, required this.tag});

factory _$_MatchingRule.fromJson(Map<String, dynamic> json) =>
_$$_MatchingRuleFromJson(json);

@override
final String id;
@override
final String tag;

@override
String toString() {
return 'MatchingRule(id: $id, tag: $tag)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_MatchingRule &&
const DeepCollectionEquality().equals(other.id, id) &&
const DeepCollectionEquality().equals(other.tag, tag));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(id),
const DeepCollectionEquality().hash(tag));

@JsonKey(ignore: true)
@override
_$$_MatchingRuleCopyWith<_$_MatchingRule> get copyWith =>
__$$_MatchingRuleCopyWithImpl<_$_MatchingRule>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_MatchingRuleToJson(this);
}
}

abstract class _MatchingRule implements MatchingRule {
const factory _MatchingRule(
{required final String id, required final String tag}) = _$_MatchingRule;

factory _MatchingRule.fromJson(Map<String, dynamic> json) =
_$_MatchingRule.fromJson;

@override
String get id => throw _privateConstructorUsedError;
@override
String get tag => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true)
_$$_MatchingRuleCopyWith<_$_MatchingRule> get copyWith =>
throw _privateConstructorUsedError;
}
27 changes: 27 additions & 0 deletions lib/src/service/tweets/matching_rule.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/src/service/tweets/tweet_entities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import 'package:freezed_annotation/freezed_annotation.dart';

// Project imports:
import '../mention.dart';
import '../tag.dart';
import '../url.dart';
import '../common/mention.dart';
import '../common/tag.dart';
import '../common/url.dart';
import 'tweet_annotation.dart';

part 'tweet_entities.freezed.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/tweets/tweet_expansion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

/// Represents an extensible field about Tweet.
enum TweetExpansion implements Serializable {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/tweets/tweet_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// modification, are permitted provided the conditions.

// Project imports:
import '../serializable.dart';
import '../common/serializable.dart';

enum TweetField implements Serializable {
/// `attachments`
Expand Down
Loading

0 comments on commit 3109a27

Please sign in to comment.