aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/mailersend/inbound_routing/__init__.py
blob: 61a16f4edb9d4b38735ed8477662cb23606c72d3 (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
"""
Handles /inbound endpoint
Doc: https://developers.mailersend.com/api/v1/inbound.html
"""

import requests
from mailersend.base import base


class NewInbound(base.NewAPIClient):
    """
    Instantiates the /inbound endpoint object
    """

    pass

    def get_inbound_routes(self):
        """
        Get a list of all inbound routes

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

    def get_inbound_by_id(self, inbound_id):
        """
        Get info on an inbound route by its ID

        @params:
          inbound_id (str): An inbound route ID

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

    def update_inbound_route(self, inbound_id, options):
        """
        Update an inbound route

        @params:
          inbound_id (str): An inbound route ID
          key (str): The key param to change
          value (object): The value to update key with

        Returns the JSON response of MailerSend API
        """

        request = requests.put(
            f"{self.api_base}/inbound/{inbound_id}",
            headers=self.headers_default,
            json=options,
        )
        return f"{request.status_code}\n{request.text}"

    def delete_inbound_route(self, inbound_id):
        """
        Returns the status code of delete inbound route operation

        @params:
          inbound_id (str): An inbound route ID
        """

        request = requests.delete(
            f"{self.api_base}/inbound/{inbound_id}",
            headers=self.headers_default,
        )
        return request.status_code

    def set_name(self, name, options):
        """
        Appends the 'name' param of inbound route options
        """
        options["name"] = name

    def set_domain_enabled(self, enabled, options):
        """
        Appends the 'domain_enabled' param of inbound route options
        """
        options["domain_enabled"] = enabled

    def set_inbound_domain(self, domain, options):
        """
        Appends the 'inbound_domain' param of inbound route options
        """
        options["inbound_domain"] = domain

    def set_catch_filter(self, content_json, options):
        """
        Appends the 'catch_filter' param of inbound route options
        """
        options["catch_filter"] = content_json

    def set_match_filter(self, content_json, options):
        """
        Appends the 'match_filter' param of inbound route options
        """
        options["match_filter"] = content_json

    def set_forwards(self, content_json, options):
        """
        Appends the 'forwards' param of inbound route options
        """
        options["forwards"] = content_json

    def add_inbound_route(self, domain_id, options):
        """
        Add a new inbound route

        @params:
          domain_id (str): For which domain will inbound route be created
          options (str): Creation options as defined in https://developers.mailersend.com/api/v1/inbound.html#add-an-inbound-route

        """

        options["domain_id"] = domain_id

        request = requests.post(
            f"{self.api_base}/inbound",
            headers=self.headers_default,
            json=options,
        )
        return f"{request.text}\n{request.status_code}"