-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
mastodon_api.dart
77 lines (68 loc) 路 2 KB
/
mastodon_api.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.
// 馃寧 Project imports:
import 'core/client/client_context.dart';
import 'core/config/retry_config.dart';
import 'service/mastodon_v1_service.dart';
import 'service/mastodon_v2_service.dart';
import 'service/oembed/oembed_service.dart';
abstract class MastodonApi {
/// Returns the new instance of [MastodonApi].
factory MastodonApi({
required String instance,
String bearerToken = '',
Duration timeout = const Duration(seconds: 10),
RetryConfig? retryConfig,
}) =>
_MastodonApi(
instance: instance,
bearerToken: bearerToken,
timeout: timeout,
retryConfig: retryConfig,
);
/// Returns the v1 service.
MastodonV1Service get v1;
/// Returns the v2 service.
MastodonV2Service get v2;
/// Returns the OEmbed service.
OEmbedService get oembed;
}
class _MastodonApi implements MastodonApi {
/// Returns the new instance of [_MastodonApi].
_MastodonApi({
required String instance,
required String bearerToken,
required Duration timeout,
RetryConfig? retryConfig,
}) : v1 = MastodonV1Service(
instance: instance,
context: ClientContext(
bearerToken: bearerToken,
timeout: timeout,
retryConfig: retryConfig,
),
),
v2 = MastodonV2Service(
instance: instance,
context: ClientContext(
bearerToken: bearerToken,
timeout: timeout,
retryConfig: retryConfig,
),
),
oembed = OEmbedService(
instance: instance,
context: ClientContext(
bearerToken: bearerToken,
timeout: timeout,
retryConfig: retryConfig,
),
);
@override
final MastodonV1Service v1;
@override
final MastodonV2Service v2;
@override
final OEmbedService oembed;
}