def applicationDelete(version): backend = content.Content() success = backend.deleteApplication(request.values['key']) if success: return {'deleted': success > 0} return errors.ApplicationKeyDoesNotExist
def currencyList(version): backend = content.Content() currency = backend.getCurrency(request.values['key']) if currency: return currency.as_dict() return errors.ApplicationKeyDoesNotExist
def applicationGet(version): backend = content.Content() application = backend.getApplication(request.values['key']) if application: return application.as_dict() return errors.ApplicationKeyDoesNotExist
def testCall(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, 'events': [{ 'name': 'liftpass-metric', 'progress': ['', '', '', '', '', '', '', ''] + [0] * 24, 'time': extras.unixTimestamp() }] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(b['goods']['sword'][0], 1000) data['user'] = '******' * 32 (status, c) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(c['goods']['sword'][0], 2000)
def testCallWithMissingData(self): backend = content.Content() a = backend.addApplication('Test') (status, b) = self.request('POST', '/sdk/update/v1/', { 'user': '', 'events': [{}] }, application=a) self.assertEqual(status, errors.ApplicationUpdateIncomplete['status']) (status, c) = self.request('POST', '/sdk/update/v1/', {'events': [{}]}, application=a) self.assertEqual(status, errors.ApplicationUpdateIncomplete['status']) (status, d) = self.request('POST', '/sdk/update/v1/', {'user': ''}, application=a) self.assertEqual(status, errors.ApplicationUpdateIncomplete['status']) (status, e) = self.request('POST', '/sdk/update/v1/', { 'user': '', 'events': [] }, application=a) self.assertEqual(status, errors.ApplicationUpdateIncomplete['status'])
def testExport(self): # Create game backend = content.Content() theAnalytics = analytics.Analytics() session = content.models.getSession() a = backend.addApplication('Export Data Game') for i in range(10): update = { 'liftpass-application': a.key, 'liftpass-ip': '', 'user': '******' * 32, 'events': [{ 'name': 'liftpass-metric', 'progress': [None] * 32, 'time': extras.unixTimestamp() }] * 5 } theAnalytics.processUpdate(update, session) query = { 'application': a.key, 'from': extras.unixTimestamp() - 86400, 'to': extras.unixTimestamp() + 86400, } (status, a) = self.request('GET', '/export/json/v1/', query, raw=True) self.assertEqual(len(a.split('\n')), 51)
def applicationList(version): backend = content.Content() applications = backend.getApplications() result = list(map(lambda g: g.as_dict(), applications)) return {'applications': result}
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 pricesAdd(version): backend = content.Content() try: prices = backend.addPrices(request.values['key'], request.values['engine'], request.values.get('data', ''), request.values.get('path', '')) return prices.as_dict() except pricing.DataEngineException as e: return {'error': '%s' % e}
def __loadPrices(self, prices_key): import core.content.content as content backend = content.Content() data = backend.getPrice(prices_key).as_dict() engine = PricingEngine.getPricingEngine(data['engine']) if engine == None: raise DataEngineException('Unknown pricing engine') return engine(data)
def __init__(self, application_key): import core.content.content as content backend = content.Content() self.groupAPrices = None self.groupBPrices = None self.abtest = backend.getABTest(application_key) # If there is no AB test for application.. we are done if self.abtest == None: monitor.getMonitor().count('PricingNoPriceFound') raise ApplicationNotFoundException() self.abtest = self.abtest.as_dict() if self.abtest['groupAPrices_key'] != None: self.groupAPrices = self.__loadPrices(self.abtest['groupAPrices_key']) if self.abtest['groupBPrices_key'] != None: self.groupBPrices = self.__loadPrices(self.abtest['groupBPrices_key'])
def goodsGet(version): backend = content.Content() good = backend.getGood(request.values['key']) if good: return good.as_dict() return errors.GoodKeyDoesNotExist
def goodsList(version): backend = content.Content() goods = backend.getGoods(request.values['key']) results = list(map(lambda g: g.as_dict(), goods)) return {'goods': results}
except: return None if status != 200: return None return time.time() - start class StressTest(APITest): def testBlank(self): pass # api = discoverTests(StressTest, config.APIServer['address'], config.APIServer['port'], config.UserKey, config.UserSecret, main.app)[0] api = discoverTests(StressTest, '54.175.122.247', 80, config.UserKey, config.UserSecret, main.app)[0] backend = content.Content() application = backend.getApplicationWithName('Test SDK') if application == None: application = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(application.key, 'JSON', json.dumps({'sword':1000}), None) jsonPricesB = backend.addPrices(application.key, 'JSON', json.dumps({'sword':2000}), None) backend.setABTest(application.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(application.key, {'groupBPrices_key': jsonPricesB.key}) def runSingleThread(): iterations = 1000 res = list(map(lambda i: makeRequest(), range(iterations)))
def goodsDelete(version): backend = content.Content() res = backend.deleteGood(request.values['key']) return {'deleted': res > 0}
def goodsUpdate(version): backend = content.Content() good = backend.updateGood(request.values['key'], request.values) if good: return good.as_dict() return errors.GoodKeyDoesNotExist
def metricsUpdate(version): backend = content.Content() metrics = backend.setMetrics(request.values['key'], request.values) return metrics.as_dict()
def applicationAdd(version): backend = content.Content() application = backend.addApplication(request.values['name']) return application.as_dict()
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
theTerminal = terminal.getTerminal() theTerminal.put(request.values['liftpass-application'], request.values, json.loads(response.data.decode('utf-8'))) return response return update_wrapper(aux, f) return decorator @app.route('/sdk/update/<version>/', methods=['POST']) @terminalLog() @rest.applicationAuthenticate( secretLookup=lambda key: content.Content().getApplicationSecret(key)) 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
def pricesDelete(version): backend = content.Content() res = backend.deletePrices(request.values['key']) return {'deleted': res > 0}
def pricesGet(version): backend = content.Content() prices = backend.getPrice(request.values['key']) if prices: return prices.as_dict() return errors.PricesKeyDoesNotExist
def pricesList(version): backend = content.Content() prices = backend.getPrices(request.values['key']) prices = list(map(lambda p: p.as_dict(), prices)) return {'prices': prices}
def goodsAdd(version): backend = content.Content() good = backend.addGood(request.values['key'], request.values['name']) return good.as_dict()
def abtestUpdate(version): backend = content.Content() abtest = backend.setABTest(request.values['key'], request.values) return abtest.as_dict()
def abtestGet(version): backend = content.Content() abtest = backend.getABTest(request.values['key']) if abtest: return abtest.as_dict() return errors.ApplicationKeyDoesNotExist
def start(): theContent = content.Content() # Delete existing apps apps = theContent.getApplications() for app in apps: theContent.deleteApplication(app.key) # Create demo game game = theContent.addApplication('Monopoly') goods = { 'com.monopoly.mediterranean': 60, 'com.monopoly.baltic': 60, 'com.monopoly.oriental': 100, 'com.monopoly.vermont': 100, 'com.monopoly.connecticut': 120, 'com.monopoly.charles': 140, 'com.monopoly.states': 140, 'com.monopoly.virginia': 160, 'com.monopoly.james': 180, 'com.monopoly.tennessee': 180, 'com.monopoly.newyork': 200, 'com.monopoly.kentucky': 220, 'com.monopoly.indiana': 220, 'com.monopoly.illinois': 240, 'com.monopoly.atlantic': 260, 'com.monopoly.ventnor': 260, 'com.monopoly.marvin': 280, 'com.monopoly.pacific': 300, 'com.monopoly.northcarolina': 300, 'com.monopoly.pennsylvania': 320, 'com.monopoly.parkplace': 350, 'com.monopoly.boardwalk': 400, 'com.monopoly.electric': 150, 'com.monopoly.water': 150, 'com.monopoly.readingrailroad': 200, 'com.monopoly.pennrailroad': 200, 'com.monopoly.borailroad': 200, 'com.monopoly.shortlinerailroad': 200 } # Add goods to game for good in goods: theContent.addGood(game.key, good) # Set currencies theContent.setCurrency(game.key, {'currency1': 'dollar'}) # Set metrics theContent.setMetrics( game.key, { 'metricString1': 'Device', 'metricString2': 'OS', 'metricString3': 'OS Version', 'metricString4': 'Language', 'metricNumber1': 'Rolls', 'metricNumber2': 'Total earned dollars', 'metricNumber3': 'Total spent dollars', 'metricNumber4': 'Total purchases', 'metricNumber5': 'Times in Jail', 'metricNumber6': 'Total Rent Paid', 'metricNumber7': 'Total Rent Earned', }) # Set prices pricesA = dict(map(lambda good: (good, int(goods[good] * 1.0)), goods)) pricesA = theContent.addPrices(game.key, 'JSON', json.dumps(pricesA), None) pricesB = dict(map(lambda good: (good, int(goods[good] * 2.5)), goods)) pricesB = theContent.addPrices(game.key, 'JSON', json.dumps(pricesB), None) # Set A/B test theContent.setABTest( game.key, { 'groupAPrices_key': pricesB.key, 'groupBPrices_key': pricesA.key, 'modulus': 5, 'modulusLimit': 3, }) print('Demo application key:', game.key) print('Demo application sercret:', game.secret)
def metricsGet(version): backend = content.Content() metrics = backend.getMetrics(request.values['key']) if metrics: return metrics.as_dict() return errors.ApplicationKeyDoesNotExist