aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/mailersend/domains/__init__.py
blob: 2645d4910f91ea0bc15dedb6fe45a713615ce4d1 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
Handles /domains endpoint
Doc: https://developers.mailersend.com/api/v1/domains.html
"""

import requests
from mailersend.base import base


class NewDomain(base.NewAPIClient):
    """
    Instantiates the /domains endpoint object
    """

    pass

    def get_domains(self):
        """
        Get a list of all domains

        Returns the JSON response of MailerSend API
        """
        request = requests.get(f"{self.api_base}/domains", headers=self.headers_default)
        return request.text

    def get_domain_by_id(self, domain_id):
        """
        Get info on a domain by its ID

        @params:
          domain_id (str): A domain ID

        Returns the JSON response of MailerSend API
        """
        request = requests.get(
            f"{self.api_base}/domains/{domain_id}", headers=self.headers_default
        )
        return request.text

    def add_domain(self, domain_data):
        """
        Add a domain

        @params:
          domain_data (dic): Contains key:value data needed for creating a new domain

        """

        request = requests.post(
            f"{self.api_base}/domains",
            headers=self.headers_default,
            json=domain_data,
        )
        return request.text

    def delete_domain(self, domain_id):
        """
        Delete a domain

        @params:
          domain_id (str): A domain ID

        Returns the JSON response of MailerSend API
        """
        request = requests.delete(
            f"{self.api_base}/domains/{domain_id}", headers=self.headers_default
        )
        return request.status_code

    def get_recipients_for_domain(self, domain_id):
        """
        List all recipients for a domain

        @params:
          domain_id (str): A domain ID

        Returns the JSON response of MailerSend API
        """
        request = requests.get(
            f"{self.api_base}/domains/{domain_id}/recipients",
            headers=self.headers_default,
        )
        return request.text

    def update_domain_setting(self, domain_id, domain_data):
        """
        Returns the JSON response of MailerSend API

        @params:
          domain_id (str): A domain ID
          domain_data (dict): A key:value list that contains parameters for updating domain name

        """
        request = requests.put(
            f"{self.api_base}/domains/{domain_id}/settings",
            headers=self.headers_default,
            json=domain_data,
        )
        return request.text

    def get_dns_records(self, domain_id):
        """
        Returns the JSON response of dns records

        @params:
          domain_id (str): A domain ID

        """

        request = requests.get(
            f"{self.api_base}/domains/{domain_id}/dns-records",
            headers=self.headers_default,
        )
        return request.text

    def verify_domain(self, domain_id):
        """
        Returns the JSON response of verified domain

        @params:
          domain_id (str): A domain ID

        """

        request = requests.get(
            f"{self.api_base}/domains/{domain_id}/verify", headers=self.headers_default
        )
        return request.text