Do you like building cool stuff? Do APIs keep you up at night? We're looking for our next superstar hacker and you could be it. Interested? Check out our job posting on stackoverflow.
pip install maxcdn
frommaxcdnimportMaxCDNapi=MaxCDN("myalias", "consumer_key", "consumer_secret")
# Get Account Infoapi.get("/account.json")
# Create Pull Zoneapi.post("/zones/pull.json", {'name': 'mypullzone', 'url': 'http://yourorigin.com', 'compress': '1'})
# Update Pull Zoneapi.put("/zones/pull.json/12345", {'url': 'http://neworigin.com'})
# Purge All Cacheapi.delete("/zones/pull.json/12345/cache")
# Purge Fileapi.delete("/zones/pull.json/77573/cache", data={'file': '/my-file.png'})It has support for GET, POST, PUT and DELETE OAuth signed requests.
zone_id=12345# Purge Zoneapi.purge(zone_id)
# Purge Fileapi.purge(zone_id, '/some_file')
# Purge Filesapi.purge(zone_id, ['/some_file', '/another_file'])Every request can take an optional debug parameter.
api.get("/account.json", debug=True)
# Will output# Making GET request to http://rws.netdna.com/myalias/account.json#{... API Returned Stuff ...}Everyrequestcanalsotakeanoptionaldebug_jsonparameterifyoudon'tliketheexceptionbasederrors.
api.get('/account.json', debug_json=True)For more information about what optional parameters this methods accept you should check out @kennethreitz library Requests.
For applications that don't require user authentication, you can use the default initialization as the example above.
For applications that require user authentication, you can initialize the API as follows.
api=MaxCDN("myalias", "consumer_key", "consumer_secret",
token="user_token", token_secret="user_token_secret")You can also send the optional parameter header_auth, which takes a boolean to send the OAuth header in the body or URLEncoded.
git clone https://github.com/maxcdn/python-maxcdn.git
cd python-maxcdn
make # setup and test
make setup # installation w/ deps
make test # test w/ primary python
make int # integration tests w/ primary python
make test/all # test w/ python2 python3.2 python3.3 python3.4
make int # integration tests
make int/all # integration w/ python2 python3.2 python3.3 python3.4
make nose # verbose test output w/ nosetests
Running examples:
git clone https://github.com/maxcdn/python-maxcdn.git
cd python-maxcdn
make setup
export PYTHONPATH=./build:./maxcdn:$PYTHONPATH
./examples/simple.py
./examples/report.py # [hourly|daily|monthly]
./examples/purge.py # [zoneid]