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