Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit f42454b

Browse files
committed
update email examples to reflect newer api
1 parent e6d9692 commit f42454b

File tree

2 files changed

+59
-45
lines changed

2 files changed

+59
-45
lines changed

examples/example_show_account_email.py

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
"""Cloudflare API code - example"""
3+
4+
import os
5+
import sys
6+
import json
7+
sys.path.insert(0, os.path.abspath('..'))
8+
9+
import CloudFlare
10+
11+
def main():
12+
"""Cloudflare API code - example"""
13+
14+
try:
15+
zone_name = sys.argv[1]
16+
except IndexError:
17+
exit('usage: example_page_rules.py zone')
18+
19+
cf = CloudFlare.CloudFlare()
20+
21+
# grab the zone identifier
22+
try:
23+
params = {'name': zone_name}
24+
zones = cf.zones.get(params=params)
25+
except CloudFlare.exceptions.CloudFlareAPIError as e:
26+
exit('/zones %d %s - api call failed' % (e, e))
27+
except Exception as e:
28+
exit('/zones.get - %s - api call failed' % (e))
29+
30+
if len(zones) == 0:
31+
exit('/zones.get - %s - zone not found' % (zone_name))
32+
33+
if len(zones) != 1:
34+
exit('/zones.get - %s - api call returned %d items' % (zone_name, len(zones)))
35+
36+
zone_id = zones[0]['id']
37+
38+
routing = cf.zones.email.routing(zone_id)
39+
print('%s: %s enabled=%s synced=%s status=%s' % (
40+
routing['tag'],
41+
routing['name'],
42+
routing['enabled'],
43+
routing['synced'],
44+
routing['status']
45+
))
46+
47+
rules = cf.zones.email.routing.rules(zone_id)
48+
for r in rules:
49+
print('%s: matches=%s actions=%s enabled=%s' % (
50+
r['tag'],
51+
r['matchers'],
52+
r['actions'],
53+
r['enabled']
54+
))
55+
56+
exit(0)
57+
58+
if __name__ == '__main__':
59+
main()

0 commit comments

Comments
 (0)