Last active
August 29, 2015 14:23
-
-
Save r0yfire/928a1cd3a318c0e2374c to your computer and use it in GitHub Desktop.
Example for creating a Cymon API library in python
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
from copy import copy | |
import json | |
import logging | |
import requests | |
class Cymon(object): | |
def __init__(self, auth_token, endpoint='https://cymon.io/api/nexus/v1'): | |
self.endpoint = endpoint | |
self.session = requests.Session() | |
self.session.headers = { | |
'content-type': 'application/json', | |
'accept': 'application/json', | |
'Authorization': 'Token %s' %auth_token | |
} | |
def get(self, method, params=None): | |
r = self.session.get(self.endpoint + method, params=params) | |
r.raise_for_status() | |
return r | |
def post(self, method, params, headers=None): | |
r = self.session.post(self.endpoint + method, data=json.dumps(params), headers=headers) | |
r.raise_for_status() | |
return r | |
def ip_lookup(self, ip_addr): | |
r = self.get('/ip/' + ip_addr) | |
return json.loads(r.text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment