Skip to content

response

DeleteResponse dataclass

Delete response object returned from the Nylas API.

Attributes:

Name Type Description
request_id str

The request ID returned from the API.

headers Optional[CaseInsensitiveDict]

The headers returned from the API.

Source code in nylas/models/response.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@dataclass
class DeleteResponse:
    """
    Delete response object returned from the Nylas API.

    Attributes:
        request_id: The request ID returned from the API.
        headers: The headers returned from the API.
    """

    request_id: str
    headers: Optional[CaseInsensitiveDict] = None

    @classmethod
    def from_dict(cls, resp: dict, headers: Optional[CaseInsensitiveDict] = None):
        """
        Convert a dictionary to a response object.

        Args:
            resp: The dictionary to convert.
            headers: The headers returned from the API.
        """
        return cls(request_id=resp["request_id"], headers=headers)

from_dict(resp, headers=None) classmethod

Convert a dictionary to a response object.

Parameters:

Name Type Description Default
resp dict

The dictionary to convert.

required
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
146
147
148
149
150
151
152
153
154
155
@classmethod
def from_dict(cls, resp: dict, headers: Optional[CaseInsensitiveDict] = None):
    """
    Convert a dictionary to a response object.

    Args:
        resp: The dictionary to convert.
        headers: The headers returned from the API.
    """
    return cls(request_id=resp["request_id"], headers=headers)

ListResponse

Bases: tuple, Generic[T]

List response object returned from the Nylas API.

Attributes:

Name Type Description
data List[T]

The list of requested data objects.

request_id str

The request ID.

next_cursor Optional[str]

The cursor to use to get the next page of data.

headers Optional[CaseInsensitiveDict]

The headers returned from the API.

Source code in nylas/models/response.py
 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
129
130
class ListResponse(tuple, Generic[T]):
    """
    List response object returned from the Nylas API.

    Attributes:
        data: The list of requested data objects.
        request_id: The request ID.
        next_cursor: The cursor to use to get the next page of data.
        headers: The headers returned from the API.
    """

    data: List[T]
    request_id: str
    next_cursor: Optional[str] = None
    headers: Optional[CaseInsensitiveDict] = None

    def __new__(
        cls,
        data: List[T],
        request_id: str,
        next_cursor: Optional[str] = None,
        headers: Optional[CaseInsensitiveDict] = None
    ):
        """
        Initialize the response object.

        Args:
            data: The list of requested data objects.
            request_id: The request ID.
            next_cursor: The cursor to use to get the next page of data.
            headers: The headers returned from the API.
        """
        # Initialize the tuple for destructuring support
        instance = super().__new__(cls, (data, request_id, next_cursor, headers))

        instance.data = data
        instance.request_id = request_id
        instance.next_cursor = next_cursor
        instance.headers = headers

        return instance

    @classmethod
    def from_dict(cls, resp: dict, generic_type, headers: Optional[CaseInsensitiveDict] = None):
        """
        Convert a dictionary to a response object.

        Args:
            resp: The dictionary to convert.
            generic_type: The type to deserialize the data objects into.
            headers: The headers returned from the API.
        """

        raw_data = resp.get("data", [])
        if isinstance(raw_data, dict):
            next_cursor = resp.get("next_cursor", raw_data.get("next_cursor"))
            data = raw_data.get("items", [])
        else:
            next_cursor = resp.get("next_cursor")
            data = raw_data

        converted_data = []
        for item in data:
            converted_data.append(generic_type.from_dict(item, infer_missing=True))

        return cls(
            data=converted_data,
            request_id=resp["request_id"],
            next_cursor=next_cursor,
            headers=headers,
        )

__new__(data, request_id, next_cursor=None, headers=None)

Initialize the response object.

Parameters:

Name Type Description Default
data List[T]

The list of requested data objects.

required
request_id str

The request ID.

required
next_cursor Optional[str]

The cursor to use to get the next page of data.

None
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
 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
def __new__(
    cls,
    data: List[T],
    request_id: str,
    next_cursor: Optional[str] = None,
    headers: Optional[CaseInsensitiveDict] = None
):
    """
    Initialize the response object.

    Args:
        data: The list of requested data objects.
        request_id: The request ID.
        next_cursor: The cursor to use to get the next page of data.
        headers: The headers returned from the API.
    """
    # Initialize the tuple for destructuring support
    instance = super().__new__(cls, (data, request_id, next_cursor, headers))

    instance.data = data
    instance.request_id = request_id
    instance.next_cursor = next_cursor
    instance.headers = headers

    return instance

from_dict(resp, generic_type, headers=None) classmethod

Convert a dictionary to a response object.

Parameters:

Name Type Description Default
resp dict

The dictionary to convert.

required
generic_type

The type to deserialize the data objects into.

required
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
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
129
130
@classmethod
def from_dict(cls, resp: dict, generic_type, headers: Optional[CaseInsensitiveDict] = None):
    """
    Convert a dictionary to a response object.

    Args:
        resp: The dictionary to convert.
        generic_type: The type to deserialize the data objects into.
        headers: The headers returned from the API.
    """

    raw_data = resp.get("data", [])
    if isinstance(raw_data, dict):
        next_cursor = resp.get("next_cursor", raw_data.get("next_cursor"))
        data = raw_data.get("items", [])
    else:
        next_cursor = resp.get("next_cursor")
        data = raw_data

    converted_data = []
    for item in data:
        converted_data.append(generic_type.from_dict(item, infer_missing=True))

    return cls(
        data=converted_data,
        request_id=resp["request_id"],
        next_cursor=next_cursor,
        headers=headers,
    )

RequestIdOnlyResponse dataclass

Response object returned from the Nylas API that only contains a request ID.

Attributes:

Name Type Description
request_id str

The request ID returned from the API.

headers Optional[CaseInsensitiveDict]

The headers returned from the API.

Source code in nylas/models/response.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@dataclass
class RequestIdOnlyResponse:
    """
    Response object returned from the Nylas API that only contains a request ID.

    Attributes:
        request_id: The request ID returned from the API.
        headers: The headers returned from the API.
    """

    request_id: str
    headers: Optional[CaseInsensitiveDict] = None

    @classmethod
    def from_dict(cls, resp: dict, headers: Optional[CaseInsensitiveDict] = None):
        """
        Convert a dictionary to a response object.

        Args:
            resp: The dictionary to convert.
            headers: The headers returned from the API.
        """
        return cls(request_id=resp["request_id"], headers=headers)

from_dict(resp, headers=None) classmethod

Convert a dictionary to a response object.

Parameters:

Name Type Description Default
resp dict

The dictionary to convert.

required
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
171
172
173
174
175
176
177
178
179
180
@classmethod
def from_dict(cls, resp: dict, headers: Optional[CaseInsensitiveDict] = None):
    """
    Convert a dictionary to a response object.

    Args:
        resp: The dictionary to convert.
        headers: The headers returned from the API.
    """
    return cls(request_id=resp["request_id"], headers=headers)

Response

Bases: tuple, Generic[T]

Response object returned from the Nylas API.

Attributes:

Name Type Description
data T

The requested data object.

request_id str

The request ID.

Source code in nylas/models/response.py
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
class Response(tuple, Generic[T]):
    """
    Response object returned from the Nylas API.

    Attributes:
        data: The requested data object.
        request_id: The request ID.
    """

    data: T
    request_id: str
    headers: Optional[CaseInsensitiveDict] = None

    def __new__(cls, data: T, request_id: str, headers: Optional[CaseInsensitiveDict] = None):
        """
        Initialize the response object.

        Args:
            data: The requested data object.
            request_id: The request ID.
            headers: The headers returned from the API.
        """
        # Initialize the tuple for destructuring support
        instance = super().__new__(cls, (data, request_id, headers))

        instance.data = data
        instance.request_id = request_id
        instance.headers = headers

        return instance

    @classmethod
    def from_dict(cls, resp: dict, generic_type, headers: Optional[CaseInsensitiveDict] = None):
        """
        Convert a dictionary to a response object.

        Args:
            resp: The dictionary to convert.
            generic_type: The type to deserialize the data object into.
            headers: The headers returned from the API.
        """

        return cls(
            data=generic_type.from_dict(resp["data"]),
            request_id=resp["request_id"],
            headers=headers,
        )

__new__(data, request_id, headers=None)

Initialize the response object.

Parameters:

Name Type Description Default
data T

The requested data object.

required
request_id str

The request ID.

required
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __new__(cls, data: T, request_id: str, headers: Optional[CaseInsensitiveDict] = None):
    """
    Initialize the response object.

    Args:
        data: The requested data object.
        request_id: The request ID.
        headers: The headers returned from the API.
    """
    # Initialize the tuple for destructuring support
    instance = super().__new__(cls, (data, request_id, headers))

    instance.data = data
    instance.request_id = request_id
    instance.headers = headers

    return instance

from_dict(resp, generic_type, headers=None) classmethod

Convert a dictionary to a response object.

Parameters:

Name Type Description Default
resp dict

The dictionary to convert.

required
generic_type

The type to deserialize the data object into.

required
headers Optional[CaseInsensitiveDict]

The headers returned from the API.

None
Source code in nylas/models/response.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@classmethod
def from_dict(cls, resp: dict, generic_type, headers: Optional[CaseInsensitiveDict] = None):
    """
    Convert a dictionary to a response object.

    Args:
        resp: The dictionary to convert.
        generic_type: The type to deserialize the data object into.
        headers: The headers returned from the API.
    """

    return cls(
        data=generic_type.from_dict(resp["data"]),
        request_id=resp["request_id"],
        headers=headers,
    )