@@ -25,10 +25,13 @@ def __init__(self, auth, host, impersonate_subuser, region='global'):
25
25
"""
26
26
from . import __version__
27
27
self .auth = auth
28
- self .host = host
29
28
self .impersonate_subuser = impersonate_subuser
30
29
self .version = __version__
31
30
self .useragent = 'sendgrid/{};python' .format (self .version )
31
+ if region is None :
32
+ self .host = host
33
+ else :
34
+ self .set_data_residency (region = region )
32
35
33
36
self .client = python_http_client .Client (
34
37
host = self .host ,
@@ -64,30 +67,29 @@ def send(self, message):
64
67
65
68
return self .client .mail .send .post (request_body = message )
66
69
67
- def set_host (self ,host ):
70
+ def set_host (self , host ):
68
71
self .host = host
69
72
self .client = python_http_client .Client (
70
73
host = self .host ,
71
74
request_headers = self ._default_headers ,
72
75
version = 3 )
73
76
74
- def set_data_residency (self ,region ):
77
+ def set_data_residency (self , region ):
75
78
"""
76
- * Client libraries contain setters for specifying region/edge.
77
- * This allows support global and eu regions only. This set will likely expand in the future.
78
- * Global should be the default
79
- * Global region means the message should be sent through:
80
- * HTTP: api.sendgrid.com
81
- * EU region means the message should be sent through:
82
- * HTTP: api.eu.sendgrid.com
79
+ Client libraries contain setters for specifying region/edge.
80
+ This supports global and eu regions only. This set will likely expand in the future.
81
+ Global is the default residency (or region)
82
+ Global region means the message will be sent through https://api.sendgrid.com
83
+ EU region means the message will be sent through https://api.eu.sendgrid.com
83
84
:param region:
84
85
:return:
85
86
"""
86
87
if region in region_host_dict .keys ():
87
88
self .host = region_host_dict [region ]
88
- self .client = python_http_client .Client (
89
- host = self .host ,
90
- request_headers = self ._default_headers ,
91
- version = 3 )
89
+ if self ._default_headers is not None :
90
+ self .client = python_http_client .Client (
91
+ host = self .host ,
92
+ request_headers = self ._default_headers ,
93
+ version = 3 )
92
94
else :
93
95
raise ValueError ("region can only be \" eu\" or \" global\" " )
0 commit comments