Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add some formating to the README to differentiate between sections
* Add example code for how to create a zone configuration
- Loading branch information
Showing
3 changed files
with
170 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
import httplib, urllib, json | ||
|
||
class Provision(object): | ||
def __init__(self, auth_token, sandbox=False): | ||
self.auth_token = str(auth_token).upper() | ||
self.sandbox = sandbox | ||
|
||
def query(self, command, args={}): | ||
if self.sandbox: | ||
conn = httplib.HTTPConnection('sandbox.dns.com') | ||
else: | ||
conn = httplib.HTTPSConnection('app.dns.com') | ||
|
||
# attach user authentication information if not already attached | ||
if 'AUTH_TOKEN' not in args: | ||
args['AUTH_TOKEN' ] = self.auth_token | ||
|
||
# create query string | ||
query_string = '/api/%s/?%s' % (command, urllib.urlencode(args)) | ||
conn.request('GET', query_string) | ||
|
||
# read response | ||
resp = conn.getresponse() | ||
json_string = resp.read() | ||
# print json_string | ||
return json.loads(json_string) | ||
|
||
def __init__(self, auth_token, sandbox=False, server=None): | ||
self.auth_token = str(auth_token).upper() | ||
self.sandbox = sandbox | ||
self.server = server | ||
|
||
|
||
def query(self, command, args={}): | ||
if self.server: | ||
conn = httplib.HTTPConnection(self.server) | ||
else: | ||
if self.sandbox: | ||
conn = httplib.HTTPConnection('sandbox.dns.com') | ||
else: | ||
conn = httplib.HTTPSConnection('app.dns.com') | ||
|
||
# attach user authentication information if not already attached | ||
if 'AUTH_TOKEN' not in args: | ||
args['AUTH_TOKEN' ] = self.auth_token | ||
|
||
# create query string | ||
query_string = '/api/%s/?%s' % (command, urllib.urlencode(args)) | ||
conn.request('GET', query_string) | ||
|
||
# read response | ||
resp = conn.getresponse() | ||
json_string = resp.read() | ||
# print json_string | ||
return json.loads(json_string) | ||
|
||
|
||
if __name__ == "__main__": | ||
dnsObj = Provision( | ||
auth_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
sandbox = False | ||
) | ||
result = dnsObj.query('getDomains') | ||
|
||
if not result['meta']['success']: | ||
raise Exception('Error: %s' % result['meta']['error']) | ||
|
||
import pprint | ||
print pprint.pprint(result) | ||
|
||
dnsObj = Provision( | ||
auth_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
sandbox = False | ||
) | ||
result = dnsObj.query('getDomains') | ||
|
||
if not result['meta']['success']: | ||
raise Exception('Error: %s' % result['meta']['error']) | ||
|
||
import pprint | ||
print pprint.pprint(result) |