|
1 | 1 | library emailjs; |
2 | 2 |
|
3 | | -import 'dart:convert'; |
4 | | -import 'package:http/http.dart' as http; |
5 | | - |
6 | | -import 'src/models/emailjs_response_status.dart'; |
7 | | -import 'src/utils/validate_params.dart'; |
8 | | -import 'src/api/send_json.dart'; |
9 | | -import 'src/models/options.dart'; |
10 | | - |
11 | 3 | export 'src/models/emailjs_response_status.dart'; |
| 4 | +export 'src/models/storage_provider.dart'; |
12 | 5 | export 'src/models/options.dart'; |
13 | | - |
14 | | -class EmailJS { |
15 | | - /// Public Key specified in the [init] method |
16 | | - static String _publicKey = ''; |
17 | | - |
18 | | - /// Private Key specified in the [init] method |
19 | | - static String? _privateKey; |
20 | | - |
21 | | - /// API host specified in the [init] method |
22 | | - static String _host = 'api.emailjs.com'; |
23 | | - |
24 | | - /// HTTP Client specified in the [init] method |
25 | | - static http.Client? _httpClient; |
26 | | - |
27 | | - /// Global configuration for EmailJS |
28 | | - /// |
29 | | - /// Sets globally the EmailJS [options] |
30 | | - static void init( |
31 | | - Options options, [ |
32 | | - String? host, |
33 | | - http.Client? customHttpClient, |
34 | | - ]) { |
35 | | - EmailJS._publicKey = options.publicKey; |
36 | | - EmailJS._privateKey = options.privateKey; |
37 | | - EmailJS._host = host ?? 'api.emailjs.com'; |
38 | | - EmailJS._httpClient = customHttpClient; |
39 | | - } |
40 | | - |
41 | | - /// Sends the email through the [serviceID] using the ready-made [templateID]. |
42 | | - /// |
43 | | - /// It's possible to pass [templatePrams] dynamic variables, |
44 | | - /// and set the [options] for this call. |
45 | | - static Future<EmailJSResponseStatus> send( |
46 | | - String serviceID, |
47 | | - String templateID, [ |
48 | | - Map<String, dynamic>? templatePrams, |
49 | | - Options? options, |
50 | | - ]) async { |
51 | | - final pubKey = options?.publicKey ?? EmailJS._publicKey; |
52 | | - final prKey = options?.privateKey ?? EmailJS._privateKey; |
53 | | - |
54 | | - validateParams(pubKey, serviceID, templateID); |
55 | | - |
56 | | - final Map<String, dynamic> params = { |
57 | | - 'lib_version': '1.3.0', |
58 | | - 'user_id': pubKey, |
59 | | - 'accessToken': prKey, |
60 | | - 'service_id': serviceID, |
61 | | - 'template_id': templateID, |
62 | | - 'template_params': templatePrams, |
63 | | - }; |
64 | | - |
65 | | - return await sendJSON( |
66 | | - Uri.https(EmailJS._host, 'api/v1.0/email/send'), |
67 | | - json.encode(params), |
68 | | - EmailJS._httpClient, |
69 | | - ); |
70 | | - } |
71 | | -} |
| 6 | +export 'src/models/block_list.dart'; |
| 7 | +export 'src/models/limit_rate.dart'; |
| 8 | +export 'src/methods/init.dart'; |
| 9 | +export 'src/methods/send.dart'; |
0 commit comments