<commit_before>import requests

"""Class which interacts with API provided by webserver"""
class WebServerInterface():
    """Constructs a WebServerInterface
    Args:
        - server_url (str): URL of webserver to interact with
    """
    def __init__(self, server_url="localhost:5000"):
        self.server_url = server_url

        # Mark that we haven't retrieve any ChessBoard credentials yet
        self.chess_board_id = None
        self.chess_board_secret = None

    """Make complete API url
    Args:
        - path (str): Path to add onto end of API url
    """
    def mk_api_url(self, path):
        return "{}{}".format(self.server_url, path)

    """Check response for errors
    Args:
        - resp(requests.Response): Response to check for errors
    
    Returns:
        - None: If no errors
        - dict: Dict with 'status_code' and 'errors' from response
    """
    def check_resp_errs(self, resp):
        # Check for errors
        data = resp.json()
        if 'errors' in data:
            # If errors present
            if len(data['errors']) > 0:
                return dict(status_code=resp.status_code, errors=data['errors'])

        if resp.status_code != 200:
            # If status code not good
            return dict(status_code=resp.status_code, errors=None)

        # If all checks pass, we good
        return None


    """Determines if we are registered with the API yet
    Returns:
        - bool: True if already registered, False if not
    """
    def registered(self):
        if self.chess_board_id is None or self.chess_board_secret is None:
            return False

        return True

    """Register with API to get ChessBoard credentials
    Does not re-register if already has credentials
    
    Returns:
        - bool: True if registration is success, False otherwise
    """
    def register(self):
        if not self.registered():
            resp = requests.get(self.mk_api_url("/chess_board/register"))

            # Check for errors
            errs_dict = self.check_resp_errs(resp)
            if errs_dict is not None:
                print("Error registering ChessBoard: {}".format(errs_dict))
                return False

            # Save creds
            data = resp.json()
            self.chess_board_id = data['chess_board']['id']
            self.chess_board_secret = data['chess_board']['secret']

            return True
        else:
            return False

    def push_move(self, move):
        pass

    def signal_game_over(self):
        pass<commit_msg>added 2 move push methods<commit_after>import requests

"""Class which interacts with API provided by webserver"""
class WebServerInterface():
    """Constructs a WebServerInterface
    Args:
        - server_url (str): URL of webserver to interact with
    """
    def __init__(self, server_url="localhost:5000"):
        self.server_url = server_url

        # Mark that we haven't retrieve any ChessBoard credentials yet
        self.chess_board_id = None
        self.chess_board_secret = None

    """Make complete API url
    Args:
        - path (str): Path to add onto end of API url
    """
    def mk_api_url(self, path):
        return "{}{}".format(self.server_url, path)

    """Check response for errors
    Args:
        - resp(requests.Response): Response to check for errors
    
    Returns:
        - None: If no errors
        - dict: Dict with 'status_code' and 'errors' from response
    """
    def check_resp_errs(self, resp):
        # Check for errors
        data = resp.json()
        if 'errors' in data:
            # If errors present
            if len(data['errors']) > 0:
                return dict(status_code=resp.status_code, errors=data['errors'])

        if resp.status_code != 200:
            # If status code not good
            return dict(status_code=resp.status_code, errors=None)

        # If all checks pass, we good
        return None


    """Determines if we are registered with the API yet
    Returns:
        - bool: True if already registered, False if not
    """
    def registered(self):
        if self.chess_board_id is None or self.chess_board_secret is None:
            return False

        return True

    """Register with API to get ChessBoard credentials
    Does not re-register if already has credentials
    
    Returns:
        - bool: True if registration is success, False otherwise
    """
    def register(self):
        if not self.registered():
            resp = requests.get(self.mk_api_url("/chess_board/register"))

            # Check for errors
            errs_dict = self.check_resp_errs(resp)
            if errs_dict is not None:
                print("Error registering ChessBoard: {}".format(errs_dict))
                return False

            # Save creds
            data = resp.json()
            self.chess_board_id = data['chess_board']['id']
            self.chess_board_secret = data['chess_board']['secret']

            return True
        else:
            return False

    def push_opponent_move(self, move):
        pass

    def push_player_move(self, move):
        pass

    def signal_game_over(self):
        pass
{'fraction_non_alphanumeric': 0.08720818059039166, 'fraction_numerical': 0.003279953694771368, 'mean_word_length': 2.1004784688995217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5751108', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1391, 'n_words': 457}