Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sendgrid/twilio_email.py: 64%
9 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1"""
2This library allows you to quickly and easily use the Twilio Email Web API v3 via Python.
4For more information on this library, see the README on GitHub.
5 http://github.com/sendgrid/sendgrid-python
6For more information on the Twilio SendGrid v3 API, see the v3 docs:
7 http://sendgrid.com/docs/API_Reference/api_v3.html
8For the user guide, code examples, and more, visit the main docs page:
9 http://sendgrid.com/docs/index.html
11This file provides the Twilio Email API Client.
12"""
13import os
14from base64 import b64encode
16from .base_interface import BaseInterface
19class TwilioEmailAPIClient(BaseInterface):
20 """The Twilio Email API Client.
22 Use this object to interact with the v3 API. For example:
23 mail_client = sendgrid.TwilioEmailAPIClient(os.environ.get('TWILIO_API_KEY'),
24 os.environ.get('TWILIO_API_SECRET'))
25 ...
26 mail = Mail(from_email, subject, to_email, content)
27 response = mail_client.send(mail)
29 For examples and detailed use instructions, see
30 https://github.com/sendgrid/sendgrid-python
31 """
33 def __init__(
34 self,
35 username=None,
36 password=None,
37 host='https://email.twilio.com',
38 impersonate_subuser=None):
39 """
40 Construct the Twilio Email v3 API object.
41 Note that the underlying client is being set up during initialization,
42 therefore changing attributes in runtime will not affect HTTP client
43 behaviour.
45 :param username: Twilio Email API key SID or Account SID to use. If not
46 provided, value will be read from the environment
47 variable "TWILIO_API_KEY" or "TWILIO_ACCOUNT_SID"
48 :type username: string
49 :param password: Twilio Email API key secret or Account Auth Token to
50 use. If not provided, value will be read from the
51 environment variable "TWILIO_API_SECRET" or
52 "TWILIO_AUTH_TOKEN"
53 :type password: string
54 :param impersonate_subuser: the subuser to impersonate. Will be passed
55 by "On-Behalf-Of" header by underlying
56 client. See
57 https://sendgrid.com/docs/User_Guide/Settings/subusers.html
58 for more details
59 :type impersonate_subuser: string
60 :param host: base URL for API calls
61 :type host: string
62 """
63 self.username = username or \
64 os.environ.get('TWILIO_API_KEY') or \
65 os.environ.get('TWILIO_ACCOUNT_SID')
67 self.password = password or \
68 os.environ.get('TWILIO_API_SECRET') or \
69 os.environ.get('TWILIO_AUTH_TOKEN')
71 auth = 'Basic ' + b64encode('{}:{}'.format(self.username, self.password).encode()).decode()
73 super(TwilioEmailAPIClient, self).__init__(auth, host, impersonate_subuser)