def testLog(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******' * 32, 'liftpass-debug': True, 'events': [{ 'name': 'liftpass-metric', 'progress': ['', '', '', '', '', '', '', ''] + [0] * 32, 'time': extras.unixTimestamp() }] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) theTerminal = terminal.getTerminal() res = theTerminal.get(a.key) self.assertEqual(len(res), 3)
def testLog(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword':1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword':2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******'*32, 'liftpass-debug': True, 'events': [ { 'name': 'liftpass-metric', 'progress': ['','','','','','','','']+[0]*32, 'time': extras.unixTimestamp() } ] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) theTerminal = terminal.getTerminal() res = theTerminal.get(a.key) self.assertEqual(len(res), 2)
def update(version): theTerminal = terminal.getTerminal() backend = content.Content() theAnalytics = analytics.Analytics() # Check minimum number of keys required in JSON update if extras.keysInDict(request.values, ['user', 'events']) == False: return errors.ApplicationUpdateIncomplete # Events must have at least one item if len(request.values['events']) == 0: return errors.ApplicationUpdateMissingEvents # Event has progress if 'progress' not in request.values['events'][-1]: return errors.ApplicationUpdateMissingEvents # Save update (include IP address of user) request.values['liftpass-ip'] = request.remote_addr theAnalytics.saveUpdate(request.values) # Try getting price engine try: prices = backend.getPricingEngine(request.values['liftpass-application']) except pricing.ApplicationNotFoundException as e: return errors.ApplicationNotConfigured # Try getting price for user + progress try: userPrices = prices.getPrices(request.values['user'], request.values['events'][-1]['progress']) except pricing.NoPricingForGroup: return errors.ApplicationHasNoPriceForUser return {'goods':userPrices[1], 'version':userPrices[0]}
def aux(*args, **kwargs): response = f(*args, **kwargs) if 'liftpass-application' in request.values and 'liftpass-debug' in request.values: if request.values['liftpass-debug'] == True: theTerminal = terminal.getTerminal() theTerminal.put(request.values['liftpass-application'], request.values, json.loads(response.data.decode('utf-8'))) return response
def debugGet(version): theTerminal = terminal.getTerminal() return {'log':theTerminal.get(request.values['key'])}
def debugAppGet(version): theTerminal = terminal.getTerminal() return {'log':theTerminal.get(request.values['liftpass-application'])}
def update(version): theTerminal = terminal.getTerminal() backend = content.Content() theAnalytics = analytics.Analytics() # Check minimum number of keys required in JSON update if extras.keysInDict(request.values, ['user', 'events']) == False: monitor.getMonitor().count('ApplicationUpdateMissingKeysCount') return errors.ApplicationUpdateIncomplete if len(request.values['user']) != 32: monitor.getMonitor().count('ApplicationUpdateMissingUsersCount') return errors.ApplicationUpdateBadUser # Events must have at least one item if len(request.values['events']) == 0: monitor.getMonitor().count('ApplicationUpdateNoEventsCount') return errors.ApplicationUpdateMissingEvents # Event has progress if 'progress' not in request.values['events'][-1]: monitor.getMonitor().count('ApplicationUpdateMissingProgressCount') return errors.ApplicationUpdateMissingEvents # Save update (include IP address of user) with monitor.getMonitor().time('ApplicationUpdateSaveUpdateTime'): request.values['liftpass-ip'] = request.environ.get('HTTP_X_REAL_IP') theAnalytics.saveUpdate(request.values) # Lookup player country try: country = geolite2.reader().get(request.environ.get('HTTP_X_REAL_IP')) country = country['country']['iso_code'] except Exception as e: monitor.getMonitor().count('ApplicationUpdateNoCountryCount') country = None response = None with monitor.getMonitor().time('ApplicationUpdateBuildResponseTime'): # Try getting price engine try: prices = backend.getPricingEngine(request.values['liftpass-application']) except pricing.ApplicationNotFoundException as e: monitor.getMonitor().count('ApplicationUpdateNoApplicationCount') return errors.ApplicationNotConfigured # Try getting price for user + progress try: userPrices = prices.getPrices(request.values['user'], request.values['events'][-1]['progress'], country=country) except pricing.NoPricingForGroup: monitor.getMonitor().count('ApplicationUpdateNoPriceCount') return errors.ApplicationHasNoPriceForUser # Build response response = {'goods':userPrices[1], 'version':userPrices[0]} # If debug mode save to terminal if 'liftpass-debug' in request.values and request.values['liftpass-debug'] == True: theTerminal.put(request.values['liftpass-application'], request.values, response) return response
def debugGet(version): theTerminal = terminal.getTerminal() return {'log': theTerminal.get(request.values['key'])}
def debugAppGet(version): theTerminal = terminal.getTerminal() return {'log': theTerminal.get(request.values['liftpass-application'])}
def update(version): theTerminal = terminal.getTerminal() backend = content.Content() theAnalytics = analytics.Analytics() # Check minimum number of keys required in JSON update if extras.keysInDict(request.values, ['user', 'events']) == False: monitor.getMonitor().count('ApplicationUpdateMissingKeysCount') return errors.ApplicationUpdateIncomplete if len(request.values['user']) != 32: monitor.getMonitor().count('ApplicationUpdateMissingUsersCount') return errors.ApplicationUpdateBadUser # Events must have at least one item if len(request.values['events']) == 0: monitor.getMonitor().count('ApplicationUpdateNoEventsCount') return errors.ApplicationUpdateMissingEvents # Event has progress if 'progress' not in request.values['events'][-1]: monitor.getMonitor().count('ApplicationUpdateMissingProgressCount') return errors.ApplicationUpdateMissingEvents # Save update (include IP address of user) with monitor.getMonitor().time('ApplicationUpdateSaveUpdateTime'): request.values['liftpass-ip'] = request.environ.get('HTTP_X_REAL_IP') theAnalytics.saveUpdate(request.values) # Lookup player country try: country = geolite2.reader().get(request.environ.get('HTTP_X_REAL_IP')) country = country['country']['iso_code'] except Exception as e: monitor.getMonitor().count('ApplicationUpdateNoCountryCount') country = None response = None with monitor.getMonitor().time('ApplicationUpdateBuildResponseTime'): # Try getting price engine try: prices = backend.getPricingEngine( request.values['liftpass-application']) except pricing.ApplicationNotFoundException as e: monitor.getMonitor().count('ApplicationUpdateNoApplicationCount') return errors.ApplicationNotConfigured # Try getting price for user + progress try: userPrices = prices.getPrices( request.values['user'], request.values['events'][-1]['progress'], country=country) except pricing.NoPricingForGroup: monitor.getMonitor().count('ApplicationUpdateNoPriceCount') return errors.ApplicationHasNoPriceForUser # Build response response = {'goods': userPrices[1], 'version': userPrices[0]} # If debug mode save to terminal if 'liftpass-debug' in request.values and request.values[ 'liftpass-debug'] == True: theTerminal.put(request.values['liftpass-application'], request.values, response) return response