Skip to content

Commit

Permalink
Merge #105
Browse files Browse the repository at this point in the history
105: feat: fixed for the issue (#9) 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 Jan 1, 2023
2 parents 2976cc4 + 57ff33c commit d00eab9
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Supported `mutes API methods`. ([#10](https://github.com/mastodon-dart/mastodon-api/issues/10))
- `GET /api/v1/mutes`
- Supported `favourites API methods`. ([#9](https://github.com/mastodon-dart/mastodon-api/issues/9))
- `GET /api/v1/favourites`

## v0.3.0

Expand Down
41 changes: 41 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,32 @@ abstract class AccountsV1Service {
Future<MastodonResponse<List<Account>>> lookupMutedAccounts({
int? limit,
});

/// Statuses the user has favourited.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 20 statuses.
/// Max 40 statuses.
///
/// ## Endpoint Url
///
/// - GET /api/v1/favourites HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:favourites
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/favourites/#get
Future<MastodonResponse<List<Status>>> lookupFavouritedStatuses({
int? limit,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1720,4 +1746,19 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Account.fromJson,
);

@override
Future<MastodonResponse<List<Status>>> lookupFavouritedStatuses({
int? limit,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/favourites',
queryParameters: {
'limit': limit,
},
),
dataBuilder: Status.fromJson,
);
}
69 changes: 69 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 @@ -2357,4 +2357,73 @@ void main() {
);
});
});

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

final response = await accountsService.lookupFavouritedStatuses(
limit: 40,
);

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

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

expectUnauthorizedException(
() async => await accountsService.lookupFavouritedStatuses(
limit: 40,
),
);
});

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

expectRateLimitExceededException(
() async => await accountsService.lookupFavouritedStatuses(
limit: 40,
),
);
});
});
}
151 changes: 151 additions & 0 deletions test/src/service/v1/accounts/data/lookup_favourited_statuses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[
{
"id": "109582726254665165",
"created_at": "2022-12-27T00:08:24.813Z",
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
"spoiler_text": "",
"visibility": "public",
"language": "ja",
"uri": "https://mastodon.world/users/shinyakato/statuses/109582726254665165",
"url": "https://mastodon.world/@shinyakato/109582726254665165",
"replies_count": 0,
"reblogs_count": 0,
"favourites_count": 0,
"edited_at": null,
"favourited": false,
"reblogged": false,
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "\u003cp\u003e\u003cspan class=\"h-card\"\u003e\u003ca href=\"https://mastodon.world/@shinyakato\" class=\"u-url mention\"\u003e@\u003cspan\u003eshinyakato\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e test\u003c/p\u003e",
"filtered": [],
"reblog": null,
"application": null,
"account": {
"id": "109510913996812000",
"username": "shinyakato",
"acct": "shinyakato",
"display_name": "Shinya Kato",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2022-12-14T00:00:00.000Z",
"note": "\u003cp\u003e👋 Coding 10+ years┆OSS Developer┆Hacker\u003cbr /\u003e👨‍💻 Author of twitter_api_v2, mastodon_api, many Dart/Flutter packages \u003cbr /\u003e🏠 shinyakato.dev\u003cbr /\u003e🇯🇵 He/Him/His\u003c/p\u003e",
"url": "https://mastodon.world/@shinyakato",
"avatar": "https://mastodon.world/avatars/original/missing.png",
"avatar_static": "https://mastodon.world/avatars/original/missing.png",
"header": "https://mastodon.world/headers/original/missing.png",
"header_static": "https://mastodon.world/headers/original/missing.png",
"followers_count": 4,
"following_count": 5,
"statuses_count": 2,
"last_status_at": "2022-12-27",
"noindex": false,
"emojis": [],
"fields": [
{
"name": "Twitter",
"value": "\u003ca href=\"https://twitter.com/kato__shinya\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003etwitter.com/kato__shinya\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "GitHub",
"value": "\u003ca href=\"https://github.com/myConsciousness\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/myConsciousness\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "Homepage",
"value": "\u003ca href=\"https://shinyakato.dev\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003eshinyakato.dev\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
}
]
},
"media_attachments": [],
"mentions": [
{
"id": "109510913996812000",
"username": "shinyakato",
"url": "https://mastodon.world/@shinyakato",
"acct": "shinyakato"
}
],
"tags": [],
"emojis": [],
"card": null,
"poll": null
},
{
"id": "109582718980699690",
"created_at": "2022-12-27T00:06:33.822Z",
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
"spoiler_text": "",
"visibility": "public",
"language": "ja",
"uri": "https://mastodon.world/users/shinyakato/statuses/109582718980699690",
"url": "https://mastodon.world/@shinyakato/109582718980699690",
"replies_count": 0,
"reblogs_count": 0,
"favourites_count": 0,
"edited_at": null,
"favourited": false,
"reblogged": false,
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "\u003cp\u003etest\u003c/p\u003e",
"filtered": [],
"reblog": null,
"application": null,
"account": {
"id": "109510913996812000",
"username": "shinyakato",
"acct": "shinyakato",
"display_name": "Shinya Kato",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2022-12-14T00:00:00.000Z",
"note": "\u003cp\u003e👋 Coding 10+ years┆OSS Developer┆Hacker\u003cbr /\u003e👨‍💻 Author of twitter_api_v2, mastodon_api, many Dart/Flutter packages \u003cbr /\u003e🏠 shinyakato.dev\u003cbr /\u003e🇯🇵 He/Him/His\u003c/p\u003e",
"url": "https://mastodon.world/@shinyakato",
"avatar": "https://mastodon.world/avatars/original/missing.png",
"avatar_static": "https://mastodon.world/avatars/original/missing.png",
"header": "https://mastodon.world/headers/original/missing.png",
"header_static": "https://mastodon.world/headers/original/missing.png",
"followers_count": 4,
"following_count": 5,
"statuses_count": 2,
"last_status_at": "2022-12-27",
"noindex": false,
"emojis": [],
"fields": [
{
"name": "Twitter",
"value": "\u003ca href=\"https://twitter.com/kato__shinya\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003etwitter.com/kato__shinya\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "GitHub",
"value": "\u003ca href=\"https://github.com/myConsciousness\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/myConsciousness\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
},
{
"name": "Homepage",
"value": "\u003ca href=\"https://shinyakato.dev\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003eshinyakato.dev\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": null
}
]
},
"media_attachments": [],
"mentions": [],
"tags": [],
"emojis": [],
"card": null,
"poll": null
}
]

0 comments on commit d00eab9

Please sign in to comment.