On a previous post we've talked abut our new REST API and the benefits it provides to our power users. If that was not enough for your satisfaction, we are releasing REST Clients for Python and Ruby to help you use our service without having to worry about anything.
Having Invalid Signature problems? Your OAuth Library doesn't comply the OAuth standards? Don't worry, we've already faced all this problems and we have the solution for them. Our client respects the full standard and you won't have to deal with OAuth problems AT ALL.
The installation is a simple and quick process, as our libraries are published at Python Package Index and Rubygems.
- Python:
$ sudo pip install requests netdnarws
- Ruby:
$ gem install netdnarws
Our goal was to make using this client straightforward and intuitive. It is a simple 3 step process that will unleash the full power of our CDN with minimal effort and zero guess work on your end. Just import the library, initialize your CDN object, and begin making requests. Below are two basic CRUD examples for managing pull zones – one for python and one for ruby:
- Python:
# import module
from netdnarws import NetDNA
# initialize object with your account credentials
api = NetDNA("my_alias", "my_key", "my_secret")
# create pull zone
response = api.post("/zones/pull.json", data={'name':'example-zone',
'url':'http://www.google.com'})
# ... response contains ...
# {u'code': 201,
# u'data': {u'pullzone': {u'backend_compress': u'0',
# u'cache_valid': u'1d',
# u'id': u'55422',
# u'name': u'zome-sone',
# u'tmp_url': u'zome-sone.rwstest.netdna-cdn.com',
# u'url': u'http://www.google.com',
# ...
# u'valid_referers': None}}}
# capture zone id for reading/updating/deleting
zone_id = response['data']['pullzone']['id']
# read pull zone
response = api.get("/zones/pull.json/%d" % zone_id)
# ... response contains ...
# {u'code': 200,
# u'data': {u'pullzone': {u'backend_compress': u'0',
# u'cache_valid': u'1d',
# u'id': u'55422',
# u'name': u'zome-sone',
# u'tmp_url': u'zome-sone.rwstest.netdna-cdn.com',
# u'url': u'http://www.google.com',
# ...
# u'valid_referers': None}}}
# update pull zone - origin url
response = api.put("/zones/pull.json/%d" % zone_id, data={'url':'http://www.yahoo.com'})
# ... response contains ...
# {u'code': 200,
# u'data': {u'pullzone': {u'backend_compress': u'0',
# u'cache_valid': u'1d',
# u'id': u'55422',
# u'name': u'zome-sone',
# u'tmp_url': u'zome-sone.rwstest.netdna-cdn.com',
# u'url': u'http://www.yahoo.com',
# ...
# u'valid_referers': None}}}
# delete pull zone
response = api.delete("/zones/pull.json/%d" % zone_id)
# ... respose contains ...
# {u'code': 200}
- Ruby:
require 'netdnarws'
api = NetDNARWS::NetDNA.new("my_alias", "my_key", "my_secret")
response = api.post("/zones/pull.json", :data => {'name' => 'example-zone',
'url' =>'http://www.google.com'})
# ... response contains ...
# {"code" => 201,
# "data" => {"pullzone" => {"backend_compress" => "0",
# "cache_valid" => "1d",
# "id" => "55422",
# "name" => "zome-sone",
# "tmp_url" => "zome-sone.rwstest.netdna-cdn.com",
# "url" => "http://www.google.com",
# ...
# "valid_referers" => nil}}}
zone_id = response['data']['pullzone']['id']
# read pull zone
response = api.get("/zones/pull.json/#{zone_id}")
# ... response contains ...
# {"code" => 200,
# "data" => {"pullzone" => {"backend_compress" => "0",
# "cache_valid" => "1d",
# "id" => "55422",
# "name" => "zome-sone",
# "tmp_url" => "zome-sone.rwstest.netdna-cdn.com",
# "url" => "http://www.google.com",
# ...
# "valid_referers" => nil}}}
# update pull zone - origin url
response = api.put("/zones/pull.json/#{zone_id}", :data => {'url' => 'http://www.yahoo.com'})
# ... response contains ...
# {"code" => 200,
# "data" => {"pullzone" => {"backend_compress" => "0",
# "cache_valid" => "1d",
# "id" => "55422",
# "name" => "zome-sone",
# "tmp_url" => "zome-sone.rwstest.netdna-cdn.com",
# "url" => "http://www.yahoo.com",
# ...
# "valid_referers" => nil}}}
# delete pull zone
response = api.delete("/zones/pull.json/#{zone_id}")
# ... respose contains ...
# {"code" => 200}
This software is Open Source and published in our Public GitHub Repository. If you wish to contribute, feel free to report us any issues or send us pull requests.