Exemplo n.º 1
0
    def get_projects():
        token = StorageService.get_token()
        params = {'token': token}
        response = requests.get(url=GET_PROJECTS_URL, params=params)

        if response.status_code == requests.codes.ok:
            projects = response.json()
            ShowDataService.show_projects(projects)
        elif response.status_code == requests.codes.unauthorized:
            AuthController().logout()
            show_error("Please log in to get projects")
Exemplo n.º 2
0
    def login(email, password):
        data = {
            'email': email,
            'password': password,
        }
        try:
            response = requests.post(url=AUTH_SIGN_IN_URL, data=data)

            if response.status_code == requests.codes.ok:
                response_data = response.json()
                access_token = response_data.get('accessToken', '')
                StorageService.save_token(access_token)
                show_message('Successfully logged in')
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
            else:
                show_error("Can't sign in. Email or password are incorrect")
        except Exception as e:
            show_error(e)
Exemplo n.º 3
0
    def delete(brick_directory):
        project_id = StorageService.get_project_id(brick_directory)
        brick_id = StorageService.get_brick_id(brick_directory)
        token = StorageService.get_token()
        params = {'token': token}

        try:
            url = DELETE_PROJECT_BRICK_URL.replace(':project_id',
                                                   project_id).replace(
                                                       ':brick_id', brick_id)
            response = requests.delete(url=url, params=params)

            if response.status_code == requests.codes.ok:
                StorageService.delete_brick(brick_directory)
                BrickService.remove_brick_directory(brick_directory)
                show_message('Brick successfully deleted!')
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
                show_error("Please log in to delete brick")
            else:
                show_error("Can't delete brick")
        except Exception as e:
            show_error(e)
Exemplo n.º 4
0
    def update(brick_directory, project_id, brick_id):
        brick_file_path = BrickService.pack_brick(brick_directory)
        token = StorageService.get_token()
        params = {'token': token}

        try:
            files = {'upload': open(brick_file_path, 'rb')}
            url = PATCH_PROJECT_BRICK_URL.replace(':project_id',
                                                  project_id).replace(
                                                      ':brick_id', brick_id)
            response = requests.patch(url=url, files=files, params=params)

            if response.status_code == requests.codes.ok:
                show_message('Brick successfully updated!')
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
                show_error("Please log in to push brick")
            else:
                show_error("Can't update brick")
        except Exception as e:
            show_error(e)
        finally:
            BrickService.remove_brick_file(brick_file_path)