Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixed for the issue (#37) #140

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Note

## v0.5.3

- Supported `directory API methods`. ([#37](https://github.com/mastodon-dart/mastodon-api/issues/37))
- `GET /api/v1/directory`

## v0.5.2

- Internal processing when searching for data from multiple IDs has been corrected. ([#136](https://github.com/mastodon-dart/mastodon-api/issues/136))
Expand Down
1 change: 1 addition & 0 deletions lib/mastodon_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export 'package:mastodon_api/src/service/v1/accounts/account_profile_meta_param.
export 'package:mastodon_api/src/service/v1/accounts/accounts_v1_service.dart';
export 'package:mastodon_api/src/service/v1/accounts/post_privacy.dart';
export 'package:mastodon_api/src/service/v1/apps/apps_v1_service.dart';
export 'package:mastodon_api/src/service/v1/instance/instance_account_order.dart';
export 'package:mastodon_api/src/service/v1/instance/instance_v1_service.dart';
export 'package:mastodon_api/src/service/v1/notifications/notifications_v1_service.dart';
export 'package:mastodon_api/src/service/v1/statuses/status_poll_param.dart';
Expand Down
15 changes: 15 additions & 0 deletions lib/src/service/v1/instance/instance_account_order.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

import '../../../core/serializable.dart';

enum InstanceAccountOrder implements Serializable {
active('active'),
newbie('new');

@override
final String value;

const InstanceAccountOrder(this.value);
}
55 changes: 55 additions & 0 deletions lib/src/service/v1/instance/instance_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import '../../../core/client/client_context.dart';
import '../../../core/client/user_context.dart';
import '../../base_service.dart';
import '../../entities/account.dart';
import '../../entities/announcement.dart';
import '../../entities/blocked_domain.dart';
import '../../entities/emoji.dart';
Expand All @@ -18,6 +19,7 @@ import '../../entities/status.dart';
import '../../entities/tag.dart';
import '../../entities/trends_link.dart';
import '../../response/mastodon_response.dart';
import 'instance_account_order.dart';

abstract class InstanceV1Service {
/// Returns the new instance of [InstanceV1Service].
Expand Down Expand Up @@ -313,6 +315,38 @@ abstract class InstanceV1Service {
///
/// - https://docs.joinmastodon.org/methods/custom_emojis/#get
Future<MastodonResponse<List<Emoji>>> lookupAvailableEmoji();

/// List accounts visible in the directory.
///
/// ## Parameters
///
/// - [offset]: Skip the first n results.
///
/// - [limit]: How many accounts to load. Defaults to 40 accounts.
/// Max 80 accounts.
///
/// - [order]: Use active to sort by most recently posted statuses (default)
/// or new to sort by most recently created profiles.
///
/// - [onlyLocal]: If true, returns only local accounts.
///
/// ## Endpoint Url
///
/// - GET /api/v1/directory HTTP/1.1
///
/// ## Authentication Methods
///
/// - Anonymous
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/directory/#get
Future<MastodonResponse<List<Account>>> lookupAccounts({
int? offset,
int? limit,
InstanceAccountOrder? order,
bool? onlyLocal,
});
}

class _InstanceV1Service extends BaseService implements InstanceV1Service {
Expand Down Expand Up @@ -496,4 +530,25 @@ class _InstanceV1Service extends BaseService implements InstanceV1Service {
),
dataBuilder: Emoji.fromJson,
);

@override
Future<MastodonResponse<List<Account>>> lookupAccounts({
int? offset,
int? limit,
InstanceAccountOrder? order,
bool? onlyLocal,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.anonymousOnly,
'/api/v1/directory',
queryParameters: {
'offset': offset,
'limit': limit,
'order': order,
'local': onlyLocal,
},
),
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.5.2
version: 0.5.3
repository: https://github.com/mastodon-dart/mastodon-api
issue_tracker: https://github.com/mastodon-dart/mastodon-api/issues

Expand Down