Skip to content

Commit

Permalink
Merge #631
Browse files Browse the repository at this point in the history
631: feat: fixed for the issue (#590) 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 Jan 5, 2023
2 parents a713193 + 7dba807 commit 613215b
Show file tree
Hide file tree
Showing 17 changed files with 1,188 additions and 10 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.8.1

- Supported `GET users/profile_banner`. ([#590](https://github.com/twitter-dart/twitter-api-v2/issues/590))

## v4.8.0

- Supported `POST account/update_profile_image`. ([#617](https://github.com/twitter-dart/twitter-api-v2/issues/617))
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,14 @@ Future<void> main() async {
> **Note**</br>
> Twitter API v1.1 endpoint is used because Twitter Official does not yet release the endpoints to manage user profile for Twitter API v2.0. Therefore, this service may be changed in the future.
| Endpoint | Method Name |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| [POST /1.1/account/update_profile.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile) | [updateProfile](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfile.html) |
| [POST /1.1/account/update_profile_image.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image) | [updateProfileImage](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfileImage.html) |
| [POST /1.1/account/update_profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner) | [updateProfileBanner](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfileBanner.html) |
| [POST /1.1/account/remove_profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-remove_profile_banner) | [destroyProfileBanner](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/destroyProfileBanner.html) |
| Endpoint | Method Name |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| [POST /1.1/account/update_profile.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile) | [updateProfile](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfile.html) |
| [POST /1.1/account/update_profile_image.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image) | [updateProfileImage](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfileImage.html) |
| [POST /1.1/account/update_profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner) | [updateProfileBanner](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/updateProfileBanner.html) |
| [POST /1.1/account/remove_profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-remove_profile_banner) | [destroyProfileBanner](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/destroyProfileBanner.html) |
| [GET users/profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-users-profile_banner) | [lookupProfileBannerById](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/lookupProfileBannerById.html) |
| [GET users/profile_banner.json](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-users-profile_banner) | [lookupProfileBannerByName](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/UsersService/lookupProfileBannerByName.html) |

#### 1.3.2.6. Report Spam

Expand Down
16 changes: 16 additions & 0 deletions lib/src/core/adaptor/profile_banner_object_adaptor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 'object_adaptor.dart';

class ProfileBannerObjectAdaptor implements ObjectAdaptor {
/// Returns the new instance of [ProfileBannerObjectAdaptor].
const ProfileBannerObjectAdaptor();

@override
Map<String, dynamic> execute(final Map<String, dynamic> source) => {
'data': source['sizes'],
};
}
7 changes: 7 additions & 0 deletions lib/src/service/base_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ abstract class BaseService implements _Service {
);
}

if (response.statusCode == 404) {
throw DataNotFoundException(
'No data exists in response.',
response,
);
}

if (response.statusCode == 429) {
throw RateLimitExceededException(
'Rate limit exceeded.',
Expand Down
28 changes: 28 additions & 0 deletions lib/src/service/users/profile_banner_variant.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.

// ignore_for_file: invalid_annotation_target

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

part 'profile_banner_variant.freezed.dart';
part 'profile_banner_variant.g.dart';

@freezed
class ProfileBannerVariant with _$ProfileBannerVariant {
const factory ProfileBannerVariant({
/// The height of this image.
@JsonKey(name: 'h') required int height,

/// The height of this image.
@JsonKey(name: 'w') required int width,

/// The url of this image.
required String url,
}) = _ProfileBannerVariant;

factory ProfileBannerVariant.fromJson(Map<String, Object?> json) =>
_$ProfileBannerVariantFromJson(json);
}
219 changes: 219 additions & 0 deletions lib/src/service/users/profile_banner_variant.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// 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, unnecessary_question_mark

part of 'profile_banner_variant.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');

ProfileBannerVariant _$ProfileBannerVariantFromJson(Map<String, dynamic> json) {
return _ProfileBannerVariant.fromJson(json);
}

/// @nodoc
mixin _$ProfileBannerVariant {
/// The height of this image.
@JsonKey(name: 'h')
int get height => throw _privateConstructorUsedError;

/// The height of this image.
@JsonKey(name: 'w')
int get width => throw _privateConstructorUsedError;

/// The url of this image.
String get url => throw _privateConstructorUsedError;

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

/// @nodoc
abstract class $ProfileBannerVariantCopyWith<$Res> {
factory $ProfileBannerVariantCopyWith(ProfileBannerVariant value,
$Res Function(ProfileBannerVariant) then) =
_$ProfileBannerVariantCopyWithImpl<$Res, ProfileBannerVariant>;
@useResult
$Res call(
{@JsonKey(name: 'h') int height,
@JsonKey(name: 'w') int width,
String url});
}

/// @nodoc
class _$ProfileBannerVariantCopyWithImpl<$Res,
$Val extends ProfileBannerVariant>
implements $ProfileBannerVariantCopyWith<$Res> {
_$ProfileBannerVariantCopyWithImpl(this._value, this._then);

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

@pragma('vm:prefer-inline')
@override
$Res call({
Object? height = null,
Object? width = null,
Object? url = null,
}) {
return _then(_value.copyWith(
height: null == height
? _value.height
: height // ignore: cast_nullable_to_non_nullable
as int,
width: null == width
? _value.width
: width // ignore: cast_nullable_to_non_nullable
as int,
url: null == url
? _value.url
: url // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}

/// @nodoc
abstract class _$$_ProfileBannerVariantCopyWith<$Res>
implements $ProfileBannerVariantCopyWith<$Res> {
factory _$$_ProfileBannerVariantCopyWith(_$_ProfileBannerVariant value,
$Res Function(_$_ProfileBannerVariant) then) =
__$$_ProfileBannerVariantCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(name: 'h') int height,
@JsonKey(name: 'w') int width,
String url});
}

/// @nodoc
class __$$_ProfileBannerVariantCopyWithImpl<$Res>
extends _$ProfileBannerVariantCopyWithImpl<$Res, _$_ProfileBannerVariant>
implements _$$_ProfileBannerVariantCopyWith<$Res> {
__$$_ProfileBannerVariantCopyWithImpl(_$_ProfileBannerVariant _value,
$Res Function(_$_ProfileBannerVariant) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? height = null,
Object? width = null,
Object? url = null,
}) {
return _then(_$_ProfileBannerVariant(
height: null == height
? _value.height
: height // ignore: cast_nullable_to_non_nullable
as int,
width: null == width
? _value.width
: width // ignore: cast_nullable_to_non_nullable
as int,
url: null == url
? _value.url
: url // ignore: cast_nullable_to_non_nullable
as String,
));
}
}

/// @nodoc
@JsonSerializable()
class _$_ProfileBannerVariant implements _ProfileBannerVariant {
const _$_ProfileBannerVariant(
{@JsonKey(name: 'h') required this.height,
@JsonKey(name: 'w') required this.width,
required this.url});

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

/// The height of this image.
@override
@JsonKey(name: 'h')
final int height;

/// The height of this image.
@override
@JsonKey(name: 'w')
final int width;

/// The url of this image.
@override
final String url;

@override
String toString() {
return 'ProfileBannerVariant(height: $height, width: $width, url: $url)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_ProfileBannerVariant &&
(identical(other.height, height) || other.height == height) &&
(identical(other.width, width) || other.width == width) &&
(identical(other.url, url) || other.url == url));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, height, width, url);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_ProfileBannerVariantCopyWith<_$_ProfileBannerVariant> get copyWith =>
__$$_ProfileBannerVariantCopyWithImpl<_$_ProfileBannerVariant>(
this, _$identity);

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

abstract class _ProfileBannerVariant implements ProfileBannerVariant {
const factory _ProfileBannerVariant(
{@JsonKey(name: 'h') required final int height,
@JsonKey(name: 'w') required final int width,
required final String url}) = _$_ProfileBannerVariant;

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

@override

/// The height of this image.
@JsonKey(name: 'h')
int get height;
@override

/// The height of this image.
@JsonKey(name: 'w')
int get width;
@override

/// The url of this image.
String get url;
@override
@JsonKey(ignore: true)
_$$_ProfileBannerVariantCopyWith<_$_ProfileBannerVariant> get copyWith =>
throw _privateConstructorUsedError;
}
32 changes: 32 additions & 0 deletions lib/src/service/users/profile_banner_variant.g.dart

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

41 changes: 41 additions & 0 deletions lib/src/service/users/profile_banner_variants_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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:freezed_annotation/freezed_annotation.dart';

// 🌎 Project imports:
import '../common/data.dart';
import 'profile_banner_variant.dart';

part 'profile_banner_variants_data.freezed.dart';
part 'profile_banner_variants_data.g.dart';

@freezed
class ProfileBannerVariantsData
with _$ProfileBannerVariantsData
implements Data {
const factory ProfileBannerVariantsData({
/// The banner image for ipad.
required ProfileBannerVariant ipad,

/// The banner image for ipad retina.
required ProfileBannerVariant ipadRetina,

/// The banner image for web.
required ProfileBannerVariant web,

/// The banner image for web retina.
required ProfileBannerVariant webRetina,

/// The banner image for mobile.
required ProfileBannerVariant mobile,

/// The banner image for mobile retina.
required ProfileBannerVariant mobileRetina,
}) = _ProfileBannerVariantsData;

factory ProfileBannerVariantsData.fromJson(Map<String, Object?> json) =>
_$ProfileBannerVariantsDataFromJson(json);
}
Loading

0 comments on commit 613215b

Please sign in to comment.