def main(): context = kiilib.KiiContext(APP_ID, APP_KEY, BASE_URL) api = kiilib.AppAPI(context) user = api.login('fkmtest', 'password1234') print 'access token = %s' % (context.access_token) # create object bucket = kiilib.KiiBucket(user, 'address') obj = api.objectAPI.create(bucket, {'name': 'fkm'}) print 'object id = %s' % (obj.id) # update object obj.data['age'] = 29 api.objectAPI.update(obj) print 'object is updated' # get by ID obj2 = api.objectAPI.getById(obj.bucket, obj.id) print str(obj2) # update patch patch = {'score': 100} api.objectAPI.updatePatch(obj2, patch) print 'object is updated' # get by ID obj2 = api.objectAPI.getById(obj2.bucket, obj2.id) print str(obj2)
def test_0000_refresh_ok(self): bucket = kiilib.KiiBucket(kiilib.KiiApp(), 'test') obj = kiilib.KiiObject(bucket, 'id1234') # set response self.factory.client.responses.append( MockResponse(200, {}, u'{"name":"fkm"}')) self.app_api.objectAPI.refresh(obj) #assertion self.assertEqual(u'fkm', obj['name']) self.assertEqual('id1234', obj.id)
def test_0300_delete_ok(self): bucket = kiilib.KiiBucket(kiilib.KiiApp(), 'test') obj = kiilib.KiiObject(bucket, 'id1234') # set response self.factory.client.responses.append( MockResponse(204, {}, u'')) self.app_api.objectAPI.delete(obj) #assertion request = self.factory.client.requests[0] self.assertEqual('https://api.kii.com/api/apps/appId/buckets/test/objects/id1234', request.url) self.assertEqual("DELETE", request.method)
def test_0010_refresh_404(self): bucket = kiilib.KiiBucket(kiilib.KiiApp(), 'test') obj = kiilib.KiiObject(bucket, 'id1234') # set response self.factory.client.responses.append( MockResponse(404, {}, u'{"errorCode":"OBJECT_NOT_FOUND"}')) try: self.app_api.objectAPI.refresh(obj) self.fail() except kiilib.CloudException as e: #assertion self.assertEqual(404, e.code)
def test_0200_update_ok(self): bucket = kiilib.KiiBucket(kiilib.KiiApp(), 'test') obj = kiilib.KiiObject(bucket, 'id1234') obj['score'] = 230 # set response self.factory.client.responses.append( MockResponse(200, {}, u'{"modifiedAt":2233}')) self.app_api.objectAPI.save(obj) #assertion request = self.factory.client.requests[0] self.assertEqual('https://api.kii.com/api/apps/appId/buckets/test/objects/id1234', request.url) self.assertEqual('PUT', request.method) self.assertEqual(2233, obj['_modified'])
def main(): context = kiilib.KiiContext(APP_ID, APP_KEY, BASE_URL) api = kiilib.AppAPI(context) user = api.login('fkmtest', 'password1234') print 'access token = %s' % (context.access_token) # create object bucket = kiilib.KiiBucket(user, 'images') condition = kiilib.KiiCondition(clause=kiilib.KiiClause.all(), limit=1) while True: objs = api.bucketAPI.query(bucket, condition) for o in objs: print str(o) if condition.hasNext() == False: break
def test_0100_create_ok(self): bucket = kiilib.KiiBucket(kiilib.KiiApp(), 'test') data = { 'name' : u'fkm', 'score' : 120 } # set response self.factory.client.responses.append( MockResponse(201, {}, u'{' + '"objectID":"d8dc9f29-0fb9-48be-a80c-ec60fddedb54",' + '"createdAt":1337039114613,' + '"dataType":"application/vnd.sandobx.mydata+json"' + '}')) obj = self.app_api.objectAPI.create(bucket, **data) #assertion self.assertEqual(u'fkm', obj['name']) self.assertEqual(120, obj['score']) self.assertEqual('d8dc9f29-0fb9-48be-a80c-ec60fddedb54', obj.id)
def main(): context = kiilib.KiiContext(APP_ID, APP_KEY, BASE_URL) api = kiilib.AppAPI(context) user = api.login('fkmtest', 'password1234') print 'access token = %s' % (context.access_token) # create object bucket = kiilib.KiiBucket(user, 'images') obj = api.objectAPI.create(bucket, {}) print 'object id = %s' % (obj.id) # upload body filePath = sys.path[0] + '/image.jpg' api.objectAPI.updateBody(obj, 'image/jpeg', open(filePath, 'rb'), os.path.getsize(filePath)) print 'file uploaded' # download body with open('downloaded.jpg', 'wb') as target: api.objectAPI.downloadBody(obj, target) print 'file downloaded'
#!/usr/bin/python import sys import os # Python Tutorial 6.1.2. "The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path." sys.path.append(sys.path[0] + "/../..") import kiilib from config import * if __name__ == "__main__": # CRUD an object in app-scope context = kiilib.KiiContext(APP_ID, APP_KEY, BASE_URL) api = kiilib.AppAPI(context) user = api.login('fkmtest', 'password1234') bucket = kiilib.KiiBucket(kiilib.APP_SCOPE, "dummy") # create obj = api.objectAPI.create(bucket, name="John Doe", age=28) print "saved object : %s" % obj obj["hungry"] = True api.objectAPI.save(obj) print "updated object : %s" % obj api.objectAPI.refresh(obj) print "re-retrieved the object : %s" % obj api.objectAPI.delete(obj) print "deleted" print "trying to retrieve the object" try: