|
| 1 | +MaxCDN is Hiring! |
| 2 | +================= |
| 3 | + |
| 4 | +Do you like building cool stuff? Do APIs keep you up at night? We're |
| 5 | +looking for our next superstar hacker and you could be it. Interested? |
| 6 | +Check out our job posting on |
| 7 | +`stackoverflow <http://careers.stackoverflow.com/jobs/37078/senior-web-engineer-for-fun-growing-la-startup-maxcdn&a=JdFbT4OY>`_. |
| 8 | + |
| 9 | +MaxCDN REST Web Services Python Client |
| 10 | +====================================== |
| 11 | + |
| 12 | + |
| 13 | +Installation |
| 14 | +------------ |
| 15 | + |
| 16 | +:: |
| 17 | + |
| 18 | + pip install maxcdn |
| 19 | + |
| 20 | +Usage |
| 21 | +----- |
| 22 | + |
| 23 | +:: |
| 24 | + |
| 25 | + from maxcdn import MaxCDN |
| 26 | + |
| 27 | + api = MaxCDN("myalias", "consumer_key", "consumer_secret") |
| 28 | + |
| 29 | + # Get Account Info |
| 30 | + api.get("/account.json") |
| 31 | + |
| 32 | + # Create Pull Zone |
| 33 | + api.post("/zones/pull.json", {'name': 'mypullzone', 'url': 'http://yourorigin.com', 'compress': '1'}) |
| 34 | + |
| 35 | + # Update Pull Zone |
| 36 | + api.put("/zones/pull.json/12345", {'url': 'http://neworigin.com'}) |
| 37 | + |
| 38 | + # Purge All Cache |
| 39 | + api.delete("/zones/pull.json/12345/cache") |
| 40 | + |
| 41 | + # Purge File |
| 42 | + api.delete("/zones/pull.json/77573/cache", data={'file': '/my-file.png'}) |
| 43 | + |
| 44 | +Methods |
| 45 | +------- |
| 46 | + |
| 47 | +It has support for ``GET``, ``POST``, ``PUT`` and ``DELETE`` OAuth |
| 48 | +signed requests. |
| 49 | + |
| 50 | +We now have a shortcut for Purge Calls! |
| 51 | +--------------------------------------- |
| 52 | + |
| 53 | +:: |
| 54 | + |
| 55 | + zone_id = 12345 |
| 56 | + |
| 57 | + # Purge Zone |
| 58 | + api.purge(zone_id) |
| 59 | + |
| 60 | + # Purge File |
| 61 | + api.purge(zone_id, '/some_file') |
| 62 | + |
| 63 | + # Purge Files |
| 64 | + api.purge(zone_id, ['/some_file', '/another_file']) |
| 65 | + |
| 66 | +Every request can take an optional debug parameter. \`\`\`python |
| 67 | +api.get("/account.json", debug=True) # Will output # Making GET request |
| 68 | +to http://rws.netdna.com/myalias/account.json #{... API Returned Stuff |
| 69 | +...} |
| 70 | + |
| 71 | +Every request can also take an optional debug\_json parameter if you |
| 72 | +don't like the exception based errors. api.get('/account.json', |
| 73 | +debug\_json=True) \`\`\` |
| 74 | + |
| 75 | +For more information about what optional parameters this methods accept |
| 76 | +you should check out `@kennethreitz <http://github.com/kennethreitz>`_ |
| 77 | +library `Requests <https://github.com/kennethreitz/requests>`_. |
| 78 | + |
| 79 | +Initialization |
| 80 | +-------------- |
| 81 | + |
| 82 | +For applications that don't require user authentication, you can use the |
| 83 | +default initialization as the example above. |
| 84 | + |
| 85 | +For applications that require user authentication, you can initialize |
| 86 | +the API as follows. |
| 87 | + |
| 88 | +:: |
| 89 | + |
| 90 | + api = MaxCDN("myalias", "consumer_key", "consumer_secret", |
| 91 | + token="user_token", token_secret="user_token_secret") |
| 92 | + |
| 93 | +You can also send the optional parameter header\_auth, which takes a |
| 94 | +boolean to send the OAuth header in the body or URLEncoded. |
| 95 | + |
| 96 | +Development |
| 97 | +----------- |
| 98 | + |
| 99 | +:: |
| 100 | + |
| 101 | + git clone https://github.com/maxcdn/python-maxcdn.git |
| 102 | + cd python-maxcdn |
| 103 | + |
| 104 | + make # setup and test |
| 105 | + make setup # installation w/ deps |
| 106 | + make test # test w/ primary python |
| 107 | + make int # integration tests w/ primary python |
| 108 | + make test/all # test w/ python2 python3.2 python3.3 python3.4 |
| 109 | + make int # integration tests |
| 110 | + make int/all # integration w/ python2 python3.2 python3.3 python3.4 |
| 111 | + make nose # verbose test output w/ nosetests |
| 112 | + |
| 113 | +Examples |
| 114 | +-------- |
| 115 | + |
| 116 | +Running examples: |
| 117 | + |
| 118 | +:: |
| 119 | + |
| 120 | + git clone https://github.com/maxcdn/python-maxcdn.git |
| 121 | + cd python-maxcdn |
| 122 | + make setup |
| 123 | + |
| 124 | + export PYTHONPATH=./build:./maxcdn:$PYTHONPATH |
| 125 | + |
| 126 | + ./examples/simple.py |
| 127 | + ./examples/report.py # [hourly|daily|monthly] |
| 128 | + ./examples/purge.py # [zoneid] |
| 129 | + |
0 commit comments