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 (#12) #124

Merged
merged 4 commits into from
Feb 5, 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

- Added `domain_blocks API methods`. ([#12](https://github.com/mastodon-dart/mastodon-api/issues/12))
- `GET /api/v1/domain_blocks`
- `POST /api/v1/domain_blocks`
- `DELETE /api/v1/domain_blocks`

## v0.4.0

- Added endpoints in `StatusesV1Service`. ([#23](https://github.com/mastodon-dart/mastodon-api/issues/23))
Expand Down
16 changes: 11 additions & 5 deletions lib/src/core/client/client_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ abstract class ClientContext {

Future<http.Response> delete(
UserContext userContext,
Uri uri,
);
Uri uri, {
dynamic body,
});

Future<http.Response> put(
UserContext userContext,
Expand Down Expand Up @@ -172,11 +173,16 @@ class _ClientContext implements ClientContext {
@override
Future<http.Response> delete(
UserContext userContext,
Uri uri,
) async =>
Uri uri, {
dynamic body,
}) async =>
await _challengeWithRetryIfNecessary(
_clientResolver.execute(userContext),
(client) async => await client.delete(uri, timeout: timeout),
(client) async => await client.delete(
uri,
body: body,
timeout: timeout,
),
);

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/src/core/service_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ class ServiceHelper implements Service {
Future<http.Response> delete(
UserContext userContext,
final String unencodedPath, {
dynamic body = const {},
http.Response Function(http.Response response)? validate,
}) async {
final response = await _context.delete(
userContext,
Uri.https(_authority, unencodedPath),
body: body,
);

return validate != null ? validate(response) : response;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/service/base_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ abstract class BaseService implements _Service {
Future<Response> delete(
UserContext userContext,
final String unencodedPath, {
dynamic body = const {},
bool checkUnprocessableEntity = false,
}) async =>
await _helper.delete(
userContext,
unencodedPath,
body: body,
validate: ((response) => checkResponse(
response,
checkUnprocessableEntity,
Expand Down
15 changes: 9 additions & 6 deletions lib/src/service/entities/notification.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ mixin _$Notification {
/// The account that performed the action that generated the notification.
Account get account => throw _privateConstructorUsedError;

/// Status that was the object of the notification. Attached when type of the
/// notification is favourite, reblog, status, mention, poll, or update.
/// Status that was the object of the notification. Attached when type of
/// the notification is favourite, reblog, status, mention, poll,
/// or update.
Status? get status =>
throw _privateConstructorUsedError; // Report that was the object of the notification.
// Attached when type of the notification is admin.report.
Expand Down Expand Up @@ -247,8 +248,9 @@ class _$_Notification implements _Notification {
@override
final Account account;

/// Status that was the object of the notification. Attached when type of the
/// notification is favourite, reblog, status, mention, poll, or update.
/// Status that was the object of the notification. Attached when type of
/// the notification is favourite, reblog, status, mention, poll,
/// or update.
@override
final Status? status;
// Report that was the object of the notification.
Expand Down Expand Up @@ -324,8 +326,9 @@ abstract class _Notification implements Notification {
Account get account;
@override

/// Status that was the object of the notification. Attached when type of the
/// notification is favourite, reblog, status, mention, poll, or update.
/// Status that was the object of the notification. Attached when type of
/// the notification is favourite, reblog, status, mention, poll,
/// or update.
Status? get status;
@override // Report that was the object of the notification.
// Attached when type of the notification is admin.report.
Expand Down
125 changes: 125 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,92 @@ abstract class AccountsV1Service {
Future<MastodonResponse<List<Status>>> lookupBookmarkedStatuses({
int? limit,
});

/// View domains the user has blocked.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 100 domain
/// blocks. Max 200 domain blocks.
///
/// ## Endpoint Url
///
/// - GET /api/v1/domain_blocks HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - follow
/// - read:blocks
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/domain_blocks/#get
Future<MastodonResponse<List<String>>> lookupBlockedDomains({
int? limit,
});

/// Block a domain to:
///
/// - hide all public posts from it
/// - hide all notifications from it
/// - remove all followers from it
/// - prevent following new users from it (but does not remove existing
/// follows)
///
/// ## Parameters
///
/// - [domainName]: Domain to block.
///
/// ## Endpoint Url
///
/// - POST /api/v1/domain_blocks HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - follow
/// - write:blocks
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/domain_blocks/#block
Future<MastodonResponse<bool>> createBlockedDomain({
required String domainName,
});

/// Remove a domain block, if it exists in the user’s array of
/// blocked domains.
///
/// ## Parameters
///
/// - [domainName]: Domain to block.
///
/// ## Endpoint Url
///
/// - DELETE /api/v1/domain_blocks HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - follow
/// - write:blocks
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/domain_blocks/#unblock
Future<MastodonResponse<bool>> destroyBlockedDomain({
required String domainName,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1854,4 +1940,43 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Status.fromJson,
);

@override
Future<MastodonResponse<List<String>>> lookupBlockedDomains({
int? limit,
}) async =>
super.transformMultiRawDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/domain_blocks',
queryParameters: {
'limit': limit,
},
),
);

@override
Future<MastodonResponse<bool>> createBlockedDomain({
required String domainName,
}) async =>
super.evaluateResponse(
await super.post(
UserContext.oauth2Only,
'/api/v1/domain_blocks',
body: {
'domain': domainName,
},
),
);

@override
Future<MastodonResponse<bool>> destroyBlockedDomain({
required String domainName,
}) async =>
super.evaluateResponse(
await super.delete(
UserContext.oauth2Only,
'/api/v1/domain_blocks',
),
);
}
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.4.0
version: 0.4.1
repository: https://github.com/mastodon-dart/mastodon-api
issue_tracker: https://github.com/mastodon-dart/mastodon-api/issues

Expand Down
1 change: 1 addition & 0 deletions test/mocks/client_context_stubs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ MockClientContext buildDeleteStub(
when(mockClientContext.delete(
UserContext.oauth2Only,
Uri.https(instance, unencodedPath),
body: anyNamed('body'),
)).thenAnswer(
(_) async => Response(
await File(resourcePath).readAsString(),
Expand Down
7 changes: 5 additions & 2 deletions test/mocks/mock.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ class MockClientContext extends _i1.Mock implements _i3.ClientContext {
@override
_i4.Future<_i2.Response> delete(
_i5.UserContext? userContext,
Uri? uri,
) =>
Uri? uri, {
dynamic body,
}) =>
(super.noSuchMethod(
Invocation.method(
#delete,
[
userContext,
uri,
],
{#body: body},
),
returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0(
this,
Expand All @@ -160,6 +162,7 @@ class MockClientContext extends _i1.Mock implements _i3.ClientContext {
userContext,
uri,
],
{#body: body},
),
)),
) as _i4.Future<_i2.Response>);
Expand Down