Skip to content

Commit

Permalink
Merge #106
Browse files Browse the repository at this point in the history
106: feat: fixed for the issue (#11) 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 d00eab9 + bd49e5a commit b714e29
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- `GET /api/v1/mutes`
- Supported `favourites API methods`. ([#9](https://github.com/mastodon-dart/mastodon-api/issues/9))
- `GET /api/v1/favourites`
- Supported `blocks API methods`. ([#11](https://github.com/mastodon-dart/mastodon-api/issues/11))
- `GET /api/v1/blocks`

## 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 @@ -1140,6 +1140,32 @@ abstract class AccountsV1Service {
Future<MastodonResponse<List<Status>>> lookupFavouritedStatuses({
int? limit,
});

/// View your blocks.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 40 accounts.
/// Max 80 accounts.
///
/// ## Endpoint Url
///
/// - GET /api/v1/blocks HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:blocks
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/blocks/#get
Future<MastodonResponse<List<Account>>> lookupBlockedAccounts({
int? limit,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1761,4 +1787,19 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Status.fromJson,
);

@override
Future<MastodonResponse<List<Account>>> lookupBlockedAccounts({
int? limit,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/blocks',
queryParameters: {
'limit': limit,
},
),
dataBuilder: Account.fromJson,
);
}
138 changes: 138 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 @@ -2426,4 +2426,142 @@ 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,
),
);
});
});

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

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

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

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

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

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

expectRateLimitExceededException(
() async => await accountsService.lookupBlockedAccounts(
limit: 40,
),
);
});
});
}
60 changes: 60 additions & 0 deletions test/src/service/v1/accounts/data/lookup_blocked_accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"id": "109479832628602326",
"username": "natesilva",
"acct": "natesilva@mstdn.social",
"display_name": "Nate Silva",
"locked": false,
"bot": false,
"discoverable": true,
"group": false,
"created_at": "2022-12-08T00:00:00.000Z",
"note": "\u003cp\u003eThis is where I post about \u003ca href=\"https://mstdn.social/tags/family\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e#\u003cspan\u003efamily\u003c/span\u003e\u003c/a\u003e, local events, and personal interests.\u003c/p\u003e\u003cp\u003eFor posts about \u003ca href=\"https://mstdn.social/tags/tech\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e#\u003cspan\u003etech\u003c/span\u003e\u003c/a\u003e, see \u003cspan class=\"h-card\"\u003e\u003ca href=\"https://hachyderm.io/@ns\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e@\u003cspan\u003ens\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e.\u003c/p\u003e",
"url": "https://mstdn.social/@natesilva",
"avatar": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/avatars/109/479/832/628/602/326/original/29f6b9990745b78a.jpeg",
"avatar_static": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/avatars/109/479/832/628/602/326/original/29f6b9990745b78a.jpeg",
"header": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/headers/109/479/832/628/602/326/original/e79b5d098b98559d.jpeg",
"header_static": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/headers/109/479/832/628/602/326/original/e79b5d098b98559d.jpeg",
"followers_count": 0,
"following_count": 30,
"statuses_count": 0,
"last_status_at": null,
"emojis": [],
"fields": [
{
"name": "tech posts",
"value": "\u003ca href=\"https://hachyderm.io/@ns\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003ehachyderm.io/@ns\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": "2022-12-08T20:01:14.455+00:00"
}
]
},
{
"id": "109479832628602326",
"username": "natesilva",
"acct": "natesilva@mstdn.social",
"display_name": "Nate Silva",
"locked": false,
"bot": false,
"discoverable": true,
"group": false,
"created_at": "2022-12-08T00:00:00.000Z",
"note": "\u003cp\u003eThis is where I post about \u003ca href=\"https://mstdn.social/tags/family\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e#\u003cspan\u003efamily\u003c/span\u003e\u003c/a\u003e, local events, and personal interests.\u003c/p\u003e\u003cp\u003eFor posts about \u003ca href=\"https://mstdn.social/tags/tech\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e#\u003cspan\u003etech\u003c/span\u003e\u003c/a\u003e, see \u003cspan class=\"h-card\"\u003e\u003ca href=\"https://hachyderm.io/@ns\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e@\u003cspan\u003ens\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e.\u003c/p\u003e",
"url": "https://mstdn.social/@natesilva",
"avatar": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/avatars/109/479/832/628/602/326/original/29f6b9990745b78a.jpeg",
"avatar_static": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/avatars/109/479/832/628/602/326/original/29f6b9990745b78a.jpeg",
"header": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/headers/109/479/832/628/602/326/original/e79b5d098b98559d.jpeg",
"header_static": "https://s3.eu-central-2.wasabisys.com/mastodonworld/cache/accounts/headers/109/479/832/628/602/326/original/e79b5d098b98559d.jpeg",
"followers_count": 0,
"following_count": 30,
"statuses_count": 0,
"last_status_at": null,
"emojis": [],
"fields": [
{
"name": "tech posts",
"value": "\u003ca href=\"https://hachyderm.io/@ns\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003ehachyderm.io/@ns\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e",
"verified_at": "2022-12-08T20:01:14.455+00:00"
}
]
}
]

0 comments on commit b714e29

Please sign in to comment.