コード例 #1
0
class AuditLogClient(object):
    def __init__(self, url, key='', secret=''):
        self.url = url
        self.key = key
        self.secret = secret
        self.api = ApiClient(self.key, self.secret, self.url)

    def check(self, req):
        if req.ok():
            print 'Success!'
        else:
            print req.errors()

    def uniqueId(self, userid, eid):
        return str(userid) + '|' + str(eid)

    def log(self, userid, eid, jsonObject):
        req = self.api.post('/api/log', {
            'userid': userid,
            'eid': eid,
            'jsonObject': json.dumps(jsonObject)
        })
        self.check(req)

    def audit(self, userid, eid, jsonObject):
        ''' {"eid":"13123fsfdasfad2","userId":"131"},"matchVersion":4,"matches":true,"matchesWithLastVersion":true,"blockNo":-1}
            '''
        req = self.api.post('/api/audit', {
            'userid': userid,
            'eid': eid,
            'jsonObject': json.dumps(jsonObject)
        })
        self.check(req)

        return req.content
コード例 #2
0
class CreateBookTest(unittest.TestCase):
	def setUp(self):
		self.api = ApiClient('#your_api_key', '#your_api_secret', 'http://restful.jamiecressey.com:5000')
		self.title = str(int(time()))

	def test_createBook(self):
		_resp = self.api.post('/books/', {
			'title': self.title
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title}, _resp.content)

		_resp = self.api.get('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title}, _resp.content)

		_resp = self.api.put('/book/{0}/'.format(self.title), {
			'author': 'Jamie Cressey'
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'author': 'Jamie Cressey'}, _resp.content)

		_resp = self.api.put('/book/{0}/'.format(self.title), {
			'release_date': '01/01/2001'
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'release_date': '01/01/2001'}, _resp.content)

		_resp = self.api.get('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title, 'author': 'Jamie Cressey', 'release_date': '01/01/2001'}, _resp.content)

		_resp = self.api.delete('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'message': 'Book deleted'}, _resp.content)
コード例 #3
0
class CreateBookTest(unittest.TestCase):
    def setUp(self):
        self.api = ApiClient('#your_api_key', '#your_api_secret',
                             'http://restful.jamiecressey.com:5000')
        self.title = str(int(time()))

    def test_createBook(self):
        _resp = self.api.post('/books/', {'title': self.title})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'title': self.title}, _resp.content)

        _resp = self.api.get('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'title': self.title}, _resp.content)

        _resp = self.api.put('/book/{0}/'.format(self.title),
                             {'author': 'Jamie Cressey'})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'author': 'Jamie Cressey'},
                                      _resp.content)

        _resp = self.api.put('/book/{0}/'.format(self.title),
                             {'release_date': '01/01/2001'})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'release_date': '01/01/2001'},
                                      _resp.content)

        _resp = self.api.get('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset(
            {
                'title': self.title,
                'author': 'Jamie Cressey',
                'release_date': '01/01/2001'
            }, _resp.content)

        _resp = self.api.delete('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'message': 'Book deleted'},
                                      _resp.content)
コード例 #4
0
 def setUp(self):
     self.api = ApiClient('#your_api_key', '#your_api_secret',
                          'http://restful.jamiecressey.com:5000')
     self.title = str(int(time()))
コード例 #5
0
ファイル: com.py プロジェクト: renancunha/site-tracer
from datetime import datetime

ip_servidor = 'http://192.168.1.115:9000/api'
arquivo_backup = '/home/pi/ftp/files/curitibanos/backup.txt'
arquivo_inicia_calibracao = '/home/pi/ftp/files/curitibanos/inicia_calibracao.txt'
arquivo_envia_calibracao = '/home/pi/ftp/files/curitibanos/calibra.txt'
tempo_enviar = 5

if os.path.isfile(arquivo_envia_calibracao) == True:
    os.remove(arquivo_envia_calibracao)

if os.path.isfile(arquivo_inicia_calibracao) == True:
    os.remove(arquivo_inicia_calibracao)

_serial = serial.Serial('/dev/ttyACM0', 9600)
api = ApiClient('xxx', 'xxx', ip_servidor)

sensores = [
    'TempSolo_vaso_1', 'UmSolo_vaso_1', 'TempAmb_vaso_1', 'UmiAmb_vaso_1',
    'Peso_vaso_1'
]


def salvaLocal(_time, i, val):
    f = open(arquivo_backup, 'a')
    f.write(_time + ';' + str(i) + ';' + str(val) + '\n')
    f.close()


def enviaBackuspParaServidor():
    enviou = True
コード例 #6
0
ファイル: com.py プロジェクト: renancunha/sitecur
ip_servidor 				= 'http://192.168.1.115:9000/api'
arquivo_backup	 			= '/home/pi/ftp/files/curitibanos/backup.txt'
arquivo_inicia_calibracao 	= '/home/pi/ftp/files/curitibanos/inicia_calibracao.txt'
arquivo_envia_calibracao 	= '/home/pi/ftp/files/curitibanos/calibra.txt'
tempo_enviar 			  	= 5

if os.path.isfile(arquivo_envia_calibracao) == True:
		os.remove(arquivo_envia_calibracao)

if os.path.isfile(arquivo_inicia_calibracao) == True:
		os.remove(arquivo_inicia_calibracao)


_serial = serial.Serial('/dev/ttyACM0', 9600)
api = ApiClient('xxx', 'xxx', ip_servidor)

sensores = ['TempSolo_vaso_1', 'UmSolo_vaso_1', 'TempAmb_vaso_1', 'UmiAmb_vaso_1', 'Peso_vaso_1']

def salvaLocal(_time, i, val):
	f = open(arquivo_backup,'a')
	f.write(_time + ';' + str(i) + ';' + str(val) + '\n')
	f.close()

def enviaBackuspParaServidor():
	enviou = True
	with open(arquivo_backup) as f:
		for line in f:
			lineSplit = line.split(';')
			try:
				req = api.get('/sensor_data/send?data=' + lineSplit[0] + '&' + sensores[string.atoi(lineSplit[1])] + '=' + lineSplit[2])
コード例 #7
0
 def __init__(self, url, key='', secret=''):
     self.url = url
     self.key = key
     self.secret = secret
     self.api = ApiClient(self.key, self.secret, self.url)
コード例 #8
0
#!/usr/bin/env python
from RestfulClient.api import ApiClient

api = ApiClient('#key', '#secret', 'http://localhost:5000')

req = api.get('/')
req = api.put('/')
req = api.delete('/')
req = api.post('/')

if req.ok():
	print 'Success!'
else:
	print req.errors()
コード例 #9
0
#!/usr/bin/env python
from RestfulClient.api import ApiClient

api = ApiClient('#key', '#secret', 'http://localhost:5000')

req = api.get('/')
req = api.put('/')
req = api.delete('/')
req = api.post('/')

if req.ok():
    print 'Success!'
else:
    print req.errors()
コード例 #10
0
	def setUp(self):
		self.api = ApiClient('#your_api_key', '#your_api_secret', 'http://restful.jamiecressey.com:5000')
		self.title = str(int(time()))