Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def handle_error_response(self, rbody, rcode, resp, rheaders):
     try:
         error_message = resp["message"]
         error_code = resp["code"]
         message = "%s (GameballException with error code %s)" % (error_message, error_code)
     except (KeyError, TypeError):
         raise APIError(
             "Invalid response object from API: %r (HTTP response code "
             "was %d)" % (rbody, rcode),
             rbody,
             rcode,
             resp,
         )
     return GameballException(message, rbody, rcode, resp, rheaders)
Exemplo n.º 4
0
    def interpret_response(self, rbody, rcode, rheaders):
        try:
            resp_object = gameballResponse(rbody, rcode, rheaders)
            resp = resp_object.get_data()
        except Exception:
            # Done for boolean returns in general and for vaildate coupon specially
            if rcode == 200:
                return True
            else:
                raise GameballException(
                    "Invalid response body from API: %s "
                    "(HTTP response code was %d)" % (rbody, rcode),
                    rbody,
                    rcode,
                    rheaders,
                )
        if rcode != 200:
            resp = self.handle_error_response(rbody, rcode, resp_object.data, rheaders)

        return resp 
Exemplo n.º 5
0
    def __init__(self,
                 player_unique_id,
                 player_attributes,
                 email=None,
                 mobile=None,
                 referrer_code=None,
                 level_order=None):
        if len(str(player_unique_id)) < 1 or len(str(player_unique_id)) > 50:
            raise GameballException(
                'player_unique_id should be between 1 and 50 letters')
        else:
            self.player_unique_id = player_unique_id

        if player_attributes is None:
            self.player_attributes = playerAttributes()

        self.player_attributes = player_attributes
        self.email = email
        self.mobile = mobile
        self.referrer_code = referrer_code
        self.level_order = level_order
Exemplo n.º 6
0
    def request_raw(self, method, url, params=None, supplied_headers=None):
        """
        Mechanism for issuing an API call
        """

        if self.api_key:
            my_api_key = self.api_key
        else:
            from gameball import api_key
            my_api_key = api_key
        
        if self.transaction_key:
            my_transaction_key = self.transaction_key
        else:
            from gameball import transaction_key
            my_api_key = transaction_key

        if my_api_key is None:
            raise AuthenticationError(
                "No API key provided. (HINT: set your API key using "
                '"gameball.api_key = <API-KEY>"). You can generate API keys '
                "from the Gameball web interface.  See "
                "https://help.gameball.co/en/articles/3467114-get-your-account-integration-details-api-key-and-transaction-key "
                "for details, or email [email protected] if you have any "
                "questions."
            )

        if my_transaction_key is None:
            raise AuthenticationError(
                "No Secret key provided. (HINT: set your API key using "
                '"gameball.api_key = <API-KEY>"). You can generate API keys '
                "from the Gameball web interface.  See "
                "https://help.gameball.co/en/articles/3467114-get-your-account-integration-details-api-key-and-transaction-key "
                "for details, or email [email protected] if you have any "
                "questions."
            )

        abs_url = "%s%s" % (self.api_base, url)

        if method == "get":
            post_data = None
        elif method == "post":
            post_data = params
        elif method == "put":
            post_data = params
        elif method == "delete":
            post_data = params
        else:
            raise GameballException(
                "Unrecognized HTTP method %r.  This may indicate a bug in the "
                "Gameball bindings.  Please contact [email protected] for "
                "assistance." % (method)
            )

        if supplied_headers is None:
            supplied_headers={}
            
        supplied_headers['APIKey']=my_api_key
        supplied_headers['secretKey']=my_transaction_key

        rcode, rbody, rheaders = self._client.request(
            method, abs_url, supplied_headers, post_data
        )

        return rcode, rbody, rheaders