Skip to content

Commit

Permalink
Merge #82
Browse files Browse the repository at this point in the history
82: fix: fixed for the issue (#20) 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/mastodon-dart/mastodon-api/issues
[contributor guide]: https://github.com/mastodon-dart/mastodon-api/blob/main/CONTRIBUTING.md
[style guide]: https://github.com/mastodon-dart/mastodon-api/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <contact@shinyakato.dev>
  • Loading branch information
bors[bot] and myConsciousness committed Dec 26, 2022
2 parents e585f30 + ab19a92 commit 4b2fc1b
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- `POST /api/v1/featured_tags`
- `DELETE /api/v1/featured_tags/:id`
- `GET /api/v1/featured_tags/suggestions`
- Supported `followed_tags API methods`. ([#20](https://github.com/mastodon-dart/mastodon-api/issues/20))
- `GET /api/v1/followed_tags`

## v0.2.1

Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/entities/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Tag with _$Tag {
@JsonKey(name: 'history') List<UsageStatistics>? histories,

/// Whether the current token’s authorized user is following this tag.
bool? isFollowing,
@JsonKey(name: 'following') bool? isFollowing,
}) = _Tag;

factory Tag.fromJson(Map<String, Object?> json) => _$TagFromJson(json);
Expand Down
11 changes: 7 additions & 4 deletions lib/src/service/entities/tag.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mixin _$Tag {
List<UsageStatistics>? get histories => throw _privateConstructorUsedError;

/// Whether the current token’s authorized user is following this tag.
@JsonKey(name: 'following')
bool? get isFollowing => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -47,7 +48,7 @@ abstract class $TagCopyWith<$Res> {
{String name,
String url,
@JsonKey(name: 'history') List<UsageStatistics>? histories,
bool? isFollowing});
@JsonKey(name: 'following') bool? isFollowing});
}

/// @nodoc
Expand Down Expand Up @@ -98,7 +99,7 @@ abstract class _$$_TagCopyWith<$Res> implements $TagCopyWith<$Res> {
{String name,
String url,
@JsonKey(name: 'history') List<UsageStatistics>? histories,
bool? isFollowing});
@JsonKey(name: 'following') bool? isFollowing});
}

/// @nodoc
Expand Down Expand Up @@ -144,7 +145,7 @@ class _$_Tag implements _Tag {
{required this.name,
required this.url,
@JsonKey(name: 'history') final List<UsageStatistics>? histories,
this.isFollowing})
@JsonKey(name: 'following') this.isFollowing})
: _histories = histories;

factory _$_Tag.fromJson(Map<String, dynamic> json) => _$$_TagFromJson(json);
Expand Down Expand Up @@ -172,6 +173,7 @@ class _$_Tag implements _Tag {

/// Whether the current token’s authorized user is following this tag.
@override
@JsonKey(name: 'following')
final bool? isFollowing;

@override
Expand Down Expand Up @@ -216,7 +218,7 @@ abstract class _Tag implements Tag {
{required final String name,
required final String url,
@JsonKey(name: 'history') final List<UsageStatistics>? histories,
final bool? isFollowing}) = _$_Tag;
@JsonKey(name: 'following') final bool? isFollowing}) = _$_Tag;

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

Expand All @@ -236,6 +238,7 @@ abstract class _Tag implements Tag {
@override

/// Whether the current token’s authorized user is following this tag.
@JsonKey(name: 'following')
bool? get isFollowing;
@override
@JsonKey(ignore: true)
Expand Down
9 changes: 3 additions & 6 deletions lib/src/service/entities/tag.g.dart

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

39 changes: 39 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,30 @@ abstract class AccountsV1Service {
///
/// - https://docs.joinmastodon.org/methods/featured_tags/#suggestions
Future<MastodonResponse<List<Tag>>> lookupSuggestedTags();

/// View all followed tags.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 100 tags.
/// Max 200 tags.
///
/// ## Endpoint Url
///
/// - GET /api/v1/followed_tags HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:follows
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/followed_tags/#get
Future<MastodonResponse<List<Tag>>> lookupFollowedTags({int? limit});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1369,4 +1393,19 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Tag.fromJson,
);

@override
Future<MastodonResponse<List<Tag>>> lookupFollowedTags({
int? limit,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/followed_tags',
queryParameters: {
'limit': limit,
},
),
dataBuilder: Tag.fromJson,
);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mastodon_api
description: The easiest and powerful Dart/Flutter library for Mastodon API.
version: 0.2.1
version: 0.2.2
repository: https://github.com/mastodon-dart/mastodon-api
issue_tracker: https://github.com/mastodon-dart/mastodon-api/issues

Expand Down
63 changes: 63 additions & 0 deletions test/src/service/v1/accounts/accounts_v1_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1855,4 +1855,67 @@ void main() {
);
});
});

group('.lookupFollowedTags', () {
test('normal case', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/followed_tags',
'test/src/service/v1/accounts/data/lookup_followed_tags.json',
{
'limit': '10',
},
),
);

final response = await accountsService.lookupFollowedTags(limit: 10);

expect(response, isA<MastodonResponse>());
expect(response.rateLimit, isA<RateLimit>());
expect(response.data, isA<List<Tag>>());
});

test('when unauthorized', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/followed_tags',
'test/src/service/v1/accounts/data/lookup_followed_tags.json',
{
'limit': '10',
},
statusCode: 401,
),
);

expectUnauthorizedException(
() async => await accountsService.lookupFollowedTags(limit: 10),
);
});

test('when rate limit exceeded', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/followed_tags',
'test/src/service/v1/accounts/data/lookup_followed_tags.json',
{
'limit': '10',
},
statusCode: 429,
),
);

expectRateLimitExceededException(
() async => await accountsService.lookupFollowedTags(limit: 10),
);
});
});
}
44 changes: 44 additions & 0 deletions test/src/service/v1/accounts/data/lookup_followed_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"name": "Test",
"url": "http://mastodon.example/tags/test",
"history": [
{
"day": "1668556800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668470400",
"accounts": "0",
"uses": "0"
},
{
"day": "1668384000",
"accounts": "0",
"uses": "0"
},
{
"day": "1668297600",
"accounts": "1",
"uses": "1"
},
{
"day": "1668211200",
"accounts": "0",
"uses": "0"
},
{
"day": "1668124800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668038400",
"accounts": "0",
"uses": "0"
}
],
"following": true
}
]

0 comments on commit 4b2fc1b

Please sign in to comment.