You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 29, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.rst
+58-5Lines changed: 58 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,9 @@ Feature Roadmap
57
57
58
58
* to support cert token
59
59
* to support sync API client
60
-
* to get to 100% test coverage
60
+
61
+
These are some alternative use cases that are not in the top of my priority now as I have not received
62
+
any request for. If you are interested, you may want to submit a pull request to contribute some of these features.
61
63
62
64
63
65
Requirements
@@ -85,20 +87,46 @@ Usage
85
87
86
88
asyncdefget_zone():
87
89
asyncwith Cloudflare() as cf:
88
-
result=await cf.zones.get()
90
+
response=await cf.zones.get()
89
91
90
-
Full configuration can be done using `Config()` class.
92
+
Unlike the offical ``python-cloudflare`` library, ``aiocloudflare`` does not parse and handle http responses.
93
+
94
+
So the awaited response object will have to be handled just as any http request, response pattern. the ``Response`` object is the same as ``httpx``'s ``Response``.
95
+
96
+
.. code:: Python
97
+
98
+
from aiocloudflare import Cloudflare
99
+
100
+
asyncdefget_zone():
101
+
asyncwith Cloudflare() as cf:
102
+
response =await cf.zones.get()
103
+
104
+
# check status code
105
+
if response.status_code ==200:
106
+
107
+
# get json data
108
+
resp_json = response.json()
109
+
110
+
# Cloudflare API typically store results in a ``result`` key.
111
+
return resp_json["result"]
112
+
113
+
else:
114
+
# to get texture data from response
115
+
print(response.text)
116
+
117
+
118
+
Full configuration can be done using ``Config()`` class.
config = Config(email="[email protected]", token="<secret>")# for demo only, do not hardcode secrets
97
125
asyncdefget_zone():
98
126
asyncwith Cloudflare(config=config) as cf:
99
127
result =await cf.zones.get()
100
128
101
-
Configuration can also be stored in a ``.env`` file for a "global configuration without needing to create a ``Config()`` class. Keys available are:
129
+
Configuration can also be stored in a ``.env`` file for a "global" configuration without needing to create a ``Config()`` class. Keys available are:
102
130
103
131
.. code:: console
104
132
@@ -110,6 +138,31 @@ Configuration can also be stored in a ``.env`` file for a "global configuration
110
138
CF_PROFILE=""
111
139
USER_AGENT=""
112
140
141
+
Advance Usage
142
+
_____________
143
+
144
+
You may wish to wrap ``Cloudflare()`` into you own class for customised settings or requirements. To do that, just provide a ``__aenter__()`` and ``__aexit__()`` method to your class like so.
145
+
146
+
.. code:: Python
147
+
148
+
classMyCfClient:
149
+
def__init__(self):
150
+
self._config = Config(email="[email protected]", token="<secret>") # for demo only, do not hardcode secrets
0 commit comments