Skip to content

Commit

Permalink
Merge #649
Browse files Browse the repository at this point in the history
649: feat: fixed for the issue (#646) 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 <[email protected]>
  • Loading branch information
bors[bot] and myConsciousness authored Feb 2, 2023
2 parents 9b49b57 + ff26e68 commit 47dde6b
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 2 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

## v4.9.1

- Added `verifiedType` in `UserField`. ([#646](https://github.com/twitter-dart/twitter-api-v2/issues/646))

## v4.9.0

- The return type of `TwitterResponse<bool, void>` has been modified to assign an object corresponding to each endpoint. ([#644](https://github.com/twitter-dart/twitter-api-v2/issues/644))
Expand Down
1 change: 1 addition & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Future<void> main() async {
userFields: [
v2.UserField.location,
v2.UserField.verified,
v2.UserField.verifiedType,
v2.UserField.entities,
v2.UserField.publicMetrics,
],
Expand Down
5 changes: 5 additions & 0 deletions lib/src/service/users/user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import '../common/data.dart';
import 'public_user_metrics.dart';
import 'user_entities.dart';
import 'user_verified_type.dart';
import 'user_withheld.dart';

part 'user_data.freezed.dart';
Expand Down Expand Up @@ -91,6 +92,10 @@ class UserData with _$UserData implements Data {
/// interest is authentic.
@JsonKey(name: 'verified') bool? isVerified,

/// The Twitter Blue verified type of the user,
/// eg: blue, government, business or none.
UserVerifiedType? verifiedType,

/// Unique identifier of this user's pinned Tweet.
///
/// ## How It Can Be Used
Expand Down
33 changes: 32 additions & 1 deletion lib/src/service/users/user_data.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ mixin _$UserData {
@JsonKey(name: 'verified')
bool? get isVerified => throw _privateConstructorUsedError;

/// The Twitter Blue verified type of the user,
/// eg: blue, government, business or none.
UserVerifiedType? get verifiedType => throw _privateConstructorUsedError;

/// Unique identifier of this user's pinned Tweet.
///
/// ## How It Can Be Used
Expand Down Expand Up @@ -140,6 +144,7 @@ abstract class $UserDataCopyWith<$Res> {
String? location,
@JsonKey(name: 'protected') bool? isProtected,
@JsonKey(name: 'verified') bool? isVerified,
UserVerifiedType? verifiedType,
String? pinnedTweetId,
UserEntities? entities,
PublicUserMetrics? publicMetrics,
Expand Down Expand Up @@ -173,6 +178,7 @@ class _$UserDataCopyWithImpl<$Res, $Val extends UserData>
Object? location = freezed,
Object? isProtected = freezed,
Object? isVerified = freezed,
Object? verifiedType = freezed,
Object? pinnedTweetId = freezed,
Object? entities = freezed,
Object? publicMetrics = freezed,
Expand Down Expand Up @@ -216,6 +222,10 @@ class _$UserDataCopyWithImpl<$Res, $Val extends UserData>
? _value.isVerified
: isVerified // ignore: cast_nullable_to_non_nullable
as bool?,
verifiedType: freezed == verifiedType
? _value.verifiedType
: verifiedType // ignore: cast_nullable_to_non_nullable
as UserVerifiedType?,
pinnedTweetId: freezed == pinnedTweetId
? _value.pinnedTweetId
: pinnedTweetId // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -293,6 +303,7 @@ abstract class _$$_UserDataCopyWith<$Res> implements $UserDataCopyWith<$Res> {
String? location,
@JsonKey(name: 'protected') bool? isProtected,
@JsonKey(name: 'verified') bool? isVerified,
UserVerifiedType? verifiedType,
String? pinnedTweetId,
UserEntities? entities,
PublicUserMetrics? publicMetrics,
Expand Down Expand Up @@ -327,6 +338,7 @@ class __$$_UserDataCopyWithImpl<$Res>
Object? location = freezed,
Object? isProtected = freezed,
Object? isVerified = freezed,
Object? verifiedType = freezed,
Object? pinnedTweetId = freezed,
Object? entities = freezed,
Object? publicMetrics = freezed,
Expand Down Expand Up @@ -370,6 +382,10 @@ class __$$_UserDataCopyWithImpl<$Res>
? _value.isVerified
: isVerified // ignore: cast_nullable_to_non_nullable
as bool?,
verifiedType: freezed == verifiedType
? _value.verifiedType
: verifiedType // ignore: cast_nullable_to_non_nullable
as UserVerifiedType?,
pinnedTweetId: freezed == pinnedTweetId
? _value.pinnedTweetId
: pinnedTweetId // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -408,6 +424,7 @@ class _$_UserData implements _UserData {
this.location,
@JsonKey(name: 'protected') this.isProtected,
@JsonKey(name: 'verified') this.isVerified,
this.verifiedType,
this.pinnedTweetId,
this.entities,
this.publicMetrics,
Expand Down Expand Up @@ -486,6 +503,11 @@ class _$_UserData implements _UserData {
@JsonKey(name: 'verified')
final bool? isVerified;

/// The Twitter Blue verified type of the user,
/// eg: blue, government, business or none.
@override
final UserVerifiedType? verifiedType;

/// Unique identifier of this user's pinned Tweet.
///
/// ## How It Can Be Used
Expand Down Expand Up @@ -532,7 +554,7 @@ class _$_UserData implements _UserData {

@override
String toString() {
return 'UserData(id: $id, name: $name, username: $username, description: $description, url: $url, profileImageUrl: $profileImageUrl, location: $location, isProtected: $isProtected, isVerified: $isVerified, pinnedTweetId: $pinnedTweetId, entities: $entities, publicMetrics: $publicMetrics, createdAt: $createdAt, withheld: $withheld)';
return 'UserData(id: $id, name: $name, username: $username, description: $description, url: $url, profileImageUrl: $profileImageUrl, location: $location, isProtected: $isProtected, isVerified: $isVerified, verifiedType: $verifiedType, pinnedTweetId: $pinnedTweetId, entities: $entities, publicMetrics: $publicMetrics, createdAt: $createdAt, withheld: $withheld)';
}

@override
Expand All @@ -555,6 +577,8 @@ class _$_UserData implements _UserData {
other.isProtected == isProtected) &&
(identical(other.isVerified, isVerified) ||
other.isVerified == isVerified) &&
(identical(other.verifiedType, verifiedType) ||
other.verifiedType == verifiedType) &&
(identical(other.pinnedTweetId, pinnedTweetId) ||
other.pinnedTweetId == pinnedTweetId) &&
(identical(other.entities, entities) ||
Expand All @@ -580,6 +604,7 @@ class _$_UserData implements _UserData {
location,
isProtected,
isVerified,
verifiedType,
pinnedTweetId,
entities,
publicMetrics,
Expand Down Expand Up @@ -611,6 +636,7 @@ abstract class _UserData implements UserData {
final String? location,
@JsonKey(name: 'protected') final bool? isProtected,
@JsonKey(name: 'verified') final bool? isVerified,
final UserVerifiedType? verifiedType,
final String? pinnedTweetId,
final UserEntities? entities,
final PublicUserMetrics? publicMetrics,
Expand Down Expand Up @@ -690,6 +716,11 @@ abstract class _UserData implements UserData {
bool? get isVerified;
@override

/// The Twitter Blue verified type of the user,
/// eg: blue, government, business or none.
UserVerifiedType? get verifiedType;
@override

/// Unique identifier of this user's pinned Tweet.
///
/// ## How It Can Be Used
Expand Down
12 changes: 12 additions & 0 deletions lib/src/service/users/user_data.g.dart

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

3 changes: 3 additions & 0 deletions lib/src/service/users/user_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ enum UserField implements Serializable {
/// `verified`
verified('verified'),

/// `verified_type`
verifiedType('verified_type'),

/// `public_metrics`
publicMetrics('public_metrics'),

Expand Down
28 changes: 28 additions & 0 deletions lib/src/service/users/user_verified_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 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 '../../core/serializable.dart';

enum UserVerifiedType implements Serializable {
blue,
government,
business,
none;

@override
String get value => name;

static UserVerifiedType valueOf(final String value) {
for (final element in values) {
if (element.value == value) {
return element;
}
}

throw UnsupportedError('Unsupported value [$value].');
}

const UserVerifiedType();
}
1 change: 1 addition & 0 deletions lib/twitter_api_v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export 'package:twitter_api_v2/src/service/users/user_expansion.dart';
export 'package:twitter_api_v2/src/service/users/user_field.dart';
export 'package:twitter_api_v2/src/service/users/user_meta.dart';
export 'package:twitter_api_v2/src/service/users/user_url_entity.dart';
export 'package:twitter_api_v2/src/service/users/user_verified_type.dart';
export 'package:twitter_api_v2/src/service/users/user_withheld.dart';
export 'package:twitter_api_v2/src/service/users/users_service.dart';
export 'package:twitter_api_v2/src/twitter_api.dart';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: twitter_api_v2
description: The most famous and powerful Dart/Flutter library for Twitter API v2.0.
version: 4.9.0
version: 4.9.1
repository: https://github.com/twitter-dart/twitter-api-v2
issue_tracker: https://github.com/twitter-dart/twitter-api-v2/issues
homepage: https://github.com/twitter-dart
Expand Down
2 changes: 2 additions & 0 deletions test/src/service/users/user_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
expect(UserField.pinnedTweetId.name, 'pinnedTweetId');
expect(UserField.protected.name, 'protected');
expect(UserField.verified.name, 'verified');
expect(UserField.verifiedType.name, 'verifiedType');
expect(UserField.publicMetrics.name, 'publicMetrics');
expect(UserField.entities.name, 'entities');
expect(UserField.createdAt.name, 'createdAt');
Expand All @@ -37,6 +38,7 @@ void main() {
expect(UserField.pinnedTweetId.value, 'pinned_tweet_id');
expect(UserField.protected.value, 'protected');
expect(UserField.verified.value, 'verified');
expect(UserField.verifiedType.value, 'verified_type');
expect(UserField.publicMetrics.value, 'public_metrics');
expect(UserField.entities.value, 'entities');
expect(UserField.createdAt.value, 'created_at');
Expand Down
36 changes: 36 additions & 0 deletions test/src/service/users/user_verified_type_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2023 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:test/test.dart';

// 🌎 Project imports:
import 'package:twitter_api_v2/src/service/users/user_verified_type.dart';

void main() {
test('.name', () {
expect(UserVerifiedType.blue.name, 'blue');
expect(UserVerifiedType.government.name, 'government');
expect(UserVerifiedType.business.name, 'business');
expect(UserVerifiedType.none.name, 'none');
});

test('.value', () {
expect(UserVerifiedType.blue.value, 'blue');
expect(UserVerifiedType.government.value, 'government');
expect(UserVerifiedType.business.value, 'business');
expect(UserVerifiedType.none.value, 'none');
});

group('.valueOf', () {
test('normal case', () {
expect(UserVerifiedType.valueOf('business'), UserVerifiedType.business);
});

test('when value is unsupported', () {
expect(() => UserVerifiedType.valueOf('test'),
throwsA(isA<UnsupportedError>()));
});
});
}

0 comments on commit 47dde6b

Please sign in to comment.