def create_discount_coupon(coupon): api_requestor_instance = APIRequestor() body_hashed = gameball.utils.hash_body(coupon.player_unique_id) body = { "playerUniqueId": coupon.player_unique_id, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "hash": body_hashed } if coupon.code is not None: body["code"] = coupon.code if coupon.start_at is not None: body["startAt"] = coupon.start_at if coupon.ends_at is not None: body["endsAt"] = coupon.ends_at if coupon.usage_limit is not None: body["usageLimit"] = coupon.usage_limit if coupon.value is not None: body["value"] = coupon.value if coupon.value_type is not None: body["valueType"] = coupon.value_type if coupon.cap is not None: body["cap"] = coupon.cap response = api_requestor_instance.request( method='POST', url=gameball.constants.create_coupon, params=body) return response
def start_batch(batch): api_requestor_instance = APIRequestor() body = { "method": batch.method, "operation": batch.operation, "params": batch.params, "body": batch.body } if batch.method.upper() not in ["GET", "POST", "DELETE"]: raise GameballException( "Unrecognized HTTP method %r. This may indicate a bug in the " "Gameball bindings. Please contact [email protected] for " "assistance." % (body.method)) if batch.operation.lower() not in ["cashback", "redeem", "balance"]: raise GameballException( "Unrecognized operation %r. This may indicate a bug in the " "Gameball bindings. Please contact [email protected] for " "assistance." % (body.operation)) response = api_requestor_instance.request( method='POST', url=gameball.constants.start_batch, params=body) return response
def manual_transaction(player_unique_id, transaction_id, username, reason, amount=None, points=None, email=None, mobile=None): api_requestor_instance = APIRequestor() body = { "playerUniqueId": player_unique_id, "amount": amount, "points": points, "transactionId": transaction_id, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "username": username, "reason": reason } body = gameball.utils.handle_channel_merging(body, email, mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.manual_transaction, params=body) return response
def send_order(order): api_requestor_instance = APIRequestor() body = { "playerUniqueId": order.player_unique_id, "orderId": order.order_id, "orderDate": order.order_date, "totalPrice": order.total_price, "totalPaid": order.total_paid, "totalDiscount": order.total_discount, "totalShipping": order.total_shipping, "totalTax": order.total_tax, "lineItems": order.line_items, "discountCodes": order.discount_codes, "redeemedAmount": order.redeemed_amount, "holdReference": order.hold_reference, "extra": order.extra, "guest": order.guest, "source": order.source } body = gameball.utils.handle_channel_merging(body, order.email, order.mobile) response = api_requestor_instance.request(method='POST', url=gameball.constants.order, params=body) return response
def reverse_hold(hold_reference): api_requestor_instance = APIRequestor() response = api_requestor_instance.request( method='DELETE', url=gameball.constants.reverse_hold.format( hold_reference=hold_reference), params=None) return response
def mark_notifications(notification_ids): api_requestor_instance = APIRequestor() body = {"notificationIds": notification_ids} response = api_requestor_instance.request( method='PUT', url=gameball.constants.mark_notifications, params=body) return response
def delete_batch(batch_id): api_requestor_instance = APIRequestor() if batch_id is None: raise GameballException("No batch id was defined") response = api_requestor_instance.request( method='DELETE', url=gameball.constants.delete_batch.format(batch_id=batch_id), params=None) return response
def send_event(event): api_requestor_instance = APIRequestor() body = {"playerUniqueId": event.player_unique_id, "events": event.events} body = gameball.utils.handle_channel_merging(body, event.email, event.mobile) response = api_requestor_instance.request(method='POST', url=gameball.constants.events, params=body) return response
def get_player_progress(player_unique_id, email=None, mobile=None): api_requestor_instance = APIRequestor() to_replace = email or mobile or player_unique_id response = api_requestor_instance.request( method='GET', url=gameball.constants.player_progress.format( player_unique_id=to_replace), params=None) return response
def detach_tags(player_unique_id, tags, email=None, mobile=None): api_requestor_instance = APIRequestor() body = {"tags": tags} to_replace = email or mobile or player_unique_id response = api_requestor_instance.request( method='DELETE', url=gameball.constants.player_tags.format(player_unique_id=to_replace), params=body, headers=None) return response
def send_action(action): api_requestor_instance = APIRequestor() body={ "playerUniqueId": action.player_unique_id, "playerAttributes":action.player_attributes, "events": action.events } if action.points_transaction is not None: body["pointsTransaction"] = action.points_transaction response = api_requestor_instance.request(method='POST',url=gameball.constants.send_action, params = body) return response
def validate_discount_coupon(player_unique_id, code): api_requestor_instance = APIRequestor() body_hashed = gameball.utils.hash_body(player_unique_id) body = { "playerUniqueId": player_unique_id, "code": code, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "hash": body_hashed } response = api_requestor_instance.request( method='POST', url=gameball.constants.validate_coupon, params=body) return response
def hold_points(player_unique_id, amount, email=None, mobile=None): api_requestor_instance = APIRequestor() body = { "playerUniqueId": player_unique_id, "amount": amount, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), } body = gameball.utils.handle_channel_merging(body, email, mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.hold_Points, params=body) return response
def get_configurations(lang=None): api_requestor_instance = APIRequestor() query = "" if lang is not None: query += "?lang=" + lang response = api_requestor_instance.request(method='GET', url=gameball.constants.config + query, params=None) return response
def initialize_player(player): api_requestor_instance = APIRequestor() player_attributes = player.player_attributes.__dict__ body = { "playerUniqueId": player.player_unique_id, "playerAttributes": player_attributes, "referrerCode": player.referrer_code, "levelOrder": player.level_order } body = gameball.utils.handle_channel_merging(body, player.email, player.mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.create_player, params=body) return response
def get_player_info(player_unique_id, email=None, mobile=None, language=None): api_requestor_instance = APIRequestor() supplied_headers = {} if language is not None: supplied_headers['lang'] = gameball.constants.Languages[ language.name].value to_replace = email or mobile or player_unique_id response = api_requestor_instance.request( method='GET', url=gameball.constants.player_info.format(player_unique_id=to_replace), params=None, headers=supplied_headers) return response
def list_transactions(page=1, limit=50, direction=None, from_date=None, to_date=None, transaction_id=None, status=None): api_requestor_instance = APIRequestor() parameters = {} if page is not None: parameters['page'] = page if limit is not None: parameters['limit'] = limit if direction is not None: parameters['direction'] = direction if from_date is not None: parameters['from'] = from_date if to_date is not None: parameters['to'] = to_date if transaction_id is not None: parameters['transactionId'] = transaction_id if status is not None: parameters['status'] = status # urlencode query = "?" for key in parameters: query += key + "=" + str(parameters[key]) + "&" # query= "?" + parse.urlparse(parameters) response = api_requestor_instance.request( method='GET', url=gameball.constants.list_transactions + query, params=None) return response
def reward_points(reward): api_requestor_instance = APIRequestor() body = { "playerUniqueId": reward.player_unique_id, "amount": reward.amount, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "transactionId": reward.transaction_id, "merchant": reward.merchant } body = gameball.utils.handle_channel_merging(body, reward.email, reward.mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.reward_points, params=body) return response
def get_notifications(player_unique_id, is_read=None, lang=None, page=None, limit=None, email=None, mobile=None): api_requestor_instance = APIRequestor() parameters = {} if limit is not None: parameters['limit'] = limit if is_read is not None: parameters['isRead'] = is_read if lang is not None: parameters['lang'] = lang if page is not None: parameters['page'] = page # urlencode query = "?" for key in parameters: query += key + "=" + str(parameters[key]) + "&" if len(query) == 1: query = "" to_replace = email or mobile or player_unique_id response = api_requestor_instance.request( method='GET', url=gameball.constants.player_notifications.format( player_unique_id=to_replace) + query, params=None, headers=None) return response
def redeem_points(player_unique_id, transaction_id, redeemed_amount=None, hold_reference=None, email=None, mobile=None): api_requestor_instance = APIRequestor() body = { "playerUniqueId": player_unique_id, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "holdReference": hold_reference, "redeemedAmount": redeemed_amount, "transactionId": transaction_id } body = gameball.utils.handle_channel_merging(body, email, mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.redeem_points, params=body) return response
def refund(player_unique_id, transaction_id, reversed_transaction_id, amount=None, email=None, mobile=None): api_requestor_instance = APIRequestor() body = { "playerUniqueId": player_unique_id, "transactionId": transaction_id, "reverseTransactionId": reversed_transaction_id, "transactionTime": gameball.utils.encode_date(datetime.utcnow()), "amount": amount } body = gameball.utils.handle_channel_merging(body, email, mobile) response = api_requestor_instance.request( method='POST', url=gameball.constants.refund_transaction, params=body) return response
def leaderboard(limit=20, from_date=None, to_date=None, player_unique_id=None, challenge_id=None): api_requestor_instance = APIRequestor() parameters = {} if player_unique_id is not None: parameters['playerUniqueId'] = player_unique_id if limit is not None: parameters['limit'] = limit if challenge_id is not None: parameters['challengeId'] = challenge_id if from_date is not None: parameters['from'] = from_date if to_date is not None: parameters['to'] = to_date # urlencode query = "?" for key in parameters: query += key + "=" + str(parameters[key]) + "&" if len(query) == 1: query = "" # query= "?" + parse.urlparse(parameters) response = api_requestor_instance.request( method='GET', url=gameball.constants.leaderboard + query, params=None) return response