Skip to content

Commit f72f0ae

Browse files
authored
Document response classes (#175)
1 parent 3948881 commit f72f0ae

File tree

4 files changed

+64
-13
lines changed

4 files changed

+64
-13
lines changed

docs/sphinx/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
]
3737

3838
pygments_style = "sphinx"
39+
pygments_dark_style = "monokai"
3940

4041
templates_path = []
4142
exclude_patterns = []
@@ -44,5 +45,5 @@
4445

4546
intersphinx_mapping = {
4647
"python": ("https://docs.python.org/3", None),
47-
"requests": ("https://docs.python-requests.org/en/master", None),
48+
"requests": ("https://docs.python-requests.org/en/latest", None),
4849
}

docs/sphinx/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ API Reference
66

77
installation
88
nodes
9+
responses
910
exceptions
1011
logging
1112
transport

docs/sphinx/responses.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Responses
2+
=========
3+
4+
.. py:currentmodule:: elastic_transport
5+
6+
7+
Response headers
8+
----------------
9+
10+
.. autoclass:: elastic_transport::HttpHeaders
11+
:members: freeze
12+
13+
Metadata
14+
--------
15+
16+
.. autoclass:: ApiResponseMeta
17+
:members:
18+
19+
Response classes
20+
----------------
21+
22+
.. autoclass:: ApiResponse
23+
:members:
24+
25+
.. autoclass:: BinaryApiResponse
26+
:members:
27+
:show-inheritance:
28+
29+
.. autoclass:: HeadApiResponse
30+
:members:
31+
:show-inheritance:
32+
33+
.. autoclass:: ListApiResponse
34+
:members:
35+
:show-inheritance:
36+
37+
.. autoclass:: ObjectApiResponse
38+
:members:
39+
:show-inheritance:
40+
41+
.. autoclass:: TextApiResponse
42+
:members:
43+
:show-inheritance:

elastic_transport/_models.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ def __str__(self) -> str:
6868

6969

7070
class HttpHeaders(MutableMapping[str, str]):
71-
"""HTTP headers"""
71+
"""HTTP headers
72+
73+
Behaves like a Python dictionary. Can be used like this::
74+
75+
headers = HttpHeaders()
76+
headers["foo"] = "bar"
77+
headers["foo"] = "baz"
78+
print(headers["foo"]) # prints "baz"
79+
"""
7280

7381
__slots__ = ("_internal", "_frozen")
7482

@@ -180,26 +188,24 @@ def hide_auth(val: str) -> str:
180188

181189
@dataclass
182190
class ApiResponseMeta:
183-
"""Metadata that is returned from Transport.perform_request()"""
191+
"""Metadata that is returned from Transport.perform_request()
192+
193+
:ivar int status: HTTP status code
194+
:ivar str http_version: HTTP version being used
195+
:ivar HttpHeaders headers: HTTP headers
196+
:ivar float duration: Number of seconds from start of request to start of response
197+
:ivar NodeConfig node: Node which handled the request
198+
:ivar typing.Optional[str] mimetype: Mimetype to be used by the serializer to decode the raw response bytes.
199+
"""
184200

185-
#: HTTP status code
186201
status: int
187-
188-
#: HTTP version being used
189202
http_version: str
190-
191-
#: HTTP headers
192203
headers: HttpHeaders
193-
194-
#: Number of seconds from start of request to start of response
195204
duration: float
196-
197-
#: Node which handled the request
198205
node: "NodeConfig"
199206

200207
@property
201208
def mimetype(self) -> Optional[str]:
202-
"""Mimetype to be used by the serializer to decode the raw response bytes."""
203209
try:
204210
content_type = self.headers["content-type"]
205211
return content_type.partition(";")[0] or None

0 commit comments

Comments
 (0)