import urllib.parse

import requests

TRELLO_API_URL = 'https://trello.com/1'


class TrelloError(Exception):
    def __init__(self, session, status_code, url, text, desc="API call error"):
        self.session = session
        self.status_code = status_code
        self.url = url
        self.text = text

        maxlen = 255
        if len(self.text) > maxlen:
            display_text = self.text[:(maxlen-3)] + '...'
        else:
            display_text = self.text

        super().__init__("{desc}: {url} -> {status_code} {display_text}"
                         .format(desc=desc, url=url,
                                 status_code=status_code,
                                 display_text=display_text))

class CustomTrelloError(TrelloError):
    status_code = 0
    desc = ""

    def __init__(self, session, url, text):
        super().__init__(session, self.status_code, url, text, self.desc)

class AuthError(CustomTrelloError):
    status_code = 401
    desc = "Request was denied"

class NotFoundError(CustomTrelloError):
    status_code = 404
    desc = "URL not found"

class RequestError(CustomTrelloError):
    status_code = 400
    desc = "Invalid data"


class App:
    def __init__(self, key):
        self.key = key

    def auth_url(self):