Skip to content

Commit

Permalink
Merge #103
Browse files Browse the repository at this point in the history
103: feat: fixed for the issue (#17) 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 30, 2022
2 parents 31e514e + a7346b8 commit ae4ec2b
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Note

## v0.2.3
## v0.3.0

- Supported `suggestions API methods`. ([#21](https://github.com/mastodon-dart/mastodon-api/issues/21))
- `GET /api/v2/suggestions`
Expand All @@ -23,6 +23,8 @@
- `ofRegularIntervals`
- `ofExponentialBackOff`
- `ofExponentialBackOffAndJitter`
- Supported `endorsements API methods`. ([#17](https://github.com/mastodon-dart/mastodon-api/issues/17))
- `GET /api/v1/endorsements`

## v0.2.2

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 @@ -1061,6 +1061,32 @@ abstract class AccountsV1Service {
List<String>? statusIds,
List<String>? ruleIds,
});

/// Accounts that the user is currently featuring on their profile.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 40 accounts.
/// Max 80 accounts.
///
/// ## Endpoint Url
///
/// - GET /api/v1/endorsements HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/endorsements/#get
Future<MastodonResponse<List<Account>>> lookupFeaturedProfiles({
int? limit,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1637,4 +1663,19 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Report.fromJson,
);

@override
Future<MastodonResponse<List<Account>>> lookupFeaturedProfiles({
int? limit,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/endorsements',
queryParameters: {
'limit': limit,
},
),
dataBuilder: Account.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.3
version: 0.3.0
repository: https://github.com/mastodon-dart/mastodon-api
issue_tracker: https://github.com/mastodon-dart/mastodon-api/issues

Expand Down
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 @@ -2219,4 +2219,73 @@ void main() {
);
});
});

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

final response = await accountsService.lookupFeaturedProfiles(
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/endorsements',
'test/src/service/v1/accounts/data/lookup_featured_profiles.json',
{
'limit': '40',
},
statusCode: 401,
),
);

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

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

expectRateLimitExceededException(
() async => await accountsService.lookupFeaturedProfiles(
limit: 40,
),
);
});
});
}
51 changes: 51 additions & 0 deletions test/src/service/v1/accounts/data/lookup_featured_profiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": "952529",
"username": "alayna",
"acct": "alayna@desvox.es",
"display_name": "Alayna Desirae",
"locked": true,
"bot": false,
"created_at": "2019-10-26T23:12:06.570Z",
"note": "experiencing ________ difficulties<br>22y/o INFP in Oklahoma",
"url": "https://desvox.es/users/alayna",
"avatar": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"header": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"followers_count": 0,
"following_count": 0,
"statuses_count": 955,
"last_status_at": "2019-11-23T07:05:50.682Z",
"emojis": [],
"fields": []
},
{
"id": "832844",
"username": "a9",
"acct": "a9@broadcast.wolfgirl.engineering",
"display_name": "vivienne :collar: ",
"locked": true,
"bot": false,
"created_at": "2019-06-12T18:55:12.053Z",
"note": "borderline nsfw, considered a schedule I drug by nixon<br>waiting for the year of the illumos desktop",
"url": "https://broadcast.wolfgirl.engineering/users/a9",
"avatar": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"header": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"followers_count": 43,
"following_count": 67,
"statuses_count": 5906,
"last_status_at": "2019-11-23T05:23:47.911Z",
"emojis": [
{
"shortcode": "collar",
"url": "https://files.mastodon.social/custom_emojis/images/000/106/920/original/80953b9cd96ec4dc.png",
"static_url": "https://files.mastodon.social/custom_emojis/images/000/106/920/static/80953b9cd96ec4dc.png",
"visible_in_picker": true
}
],
"fields": []
}
]

0 comments on commit ae4ec2b

Please sign in to comment.