@@ -3,57 +3,65 @@ library emailjs;
33import 'dart:convert' ;
44import 'package:http/http.dart' as http;
55
6+ import 'src/models/emailjs_response_status.dart' ;
67import 'src/utils/validate_params.dart' ;
78import 'src/api/send_json.dart' ;
9+ import 'src/types/options.dart' ;
810
911class EmailJS {
1012 /// Public Key specified in the [init] method
1113 static String _publicKey = '' ;
1214
15+ /// Private Key specified in the [init] method
16+ static String ? _privateKey;
17+
1318 /// API host specified in the [init] method
14- static String _origin = 'api.emailjs.com' ;
19+ static String _host = 'api.emailjs.com' ;
1520
1621 /// HTTP Client specified in the [init] method
1722 static http.Client _httpClient = http.Client ();
1823
1924 /// Global configuration for EmailJS
2025 ///
21- /// Sets globally the [publicKey] for the application
26+ /// Sets globally the EmailJS [options]
2227 static void init (
23- String publicKey , [
24- String ? origin ,
28+ Options options , [
29+ String ? host ,
2530 http.Client ? httpClient,
2631 ]) {
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' ;
2935 EmailJS ._httpClient = httpClient ?? http.Client ();
3036 }
3137
3238 /// Sends the email through the [serviceID] using the ready-made [templateID] .
3339 ///
3440 /// 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 (
3743 String serviceID,
3844 String templateID, [
3945 Map <String , dynamic >? templatePrams,
40- String ? publicKey ,
46+ Options ? options ,
4147 ]) async {
42- final pubKey = publicKey ?? EmailJS ._publicKey;
48+ final pubKey = options? .publicKey ?? EmailJS ._publicKey;
49+ final prKey = options? .privateKey ?? EmailJS ._privateKey;
4350
4451 validateParams (pubKey, serviceID, templateID);
4552
4653 final Map <String , dynamic > params = {
4754 'lib_version' : '0.0.3' ,
4855 'user_id' : pubKey,
56+ 'accessToken' : prKey,
4957 'service_id' : serviceID,
5058 'template_id' : templateID,
5159 'template_params' : templatePrams,
5260 };
5361
5462 return await sendJSON (
5563 EmailJS ._httpClient,
56- Uri .https (EmailJS ._origin , 'api/v1.0/email/send' ),
64+ Uri .https (EmailJS ._host , 'api/v1.0/email/send' ),
5765 json.encode (params),
5866 );
5967 }
0 commit comments