import os

import requests

from trellominer.config import yaml


class HTTP(object):

    def __init__(self):
        self.config = yaml.read(os.getenv("TRELLO_CONFIG", default=os.path.join(os.path.expanduser('~'), ".trellominer.yaml")))
        self.api_url = os.getenv("TRELLO_URL", default=self.config['api']['url'])
        self.api_key = os.getenv("TRELLO_API_KEY", default=self.config['api']['key'])
        self.api_token = os.getenv("TRELLO_API_TOKEN", default=self.config['api']['token'])
        self.organization = os.getenv("TRELLO_ORGANIZATION", default=self.config['api']['organization'])
        self.output_file = os.getenv("TRELLO_OUTPUT_FILE", default=self.config['api']['output_file_name'])

class Trello(HTTP):

    def __init__(self):
        super().__init__()

    def boards(self):
        url = "{0}/organizations/{1}/boards?key={2}&token={3}".format(
                self.api_url, self.organization, self.api_key, self.api_token)
        req = requests.get(url, params=None)
        return req.json()

    def cards(self, board_id):
        url = "{0}/boards/{1}/cards?fields=shortLink,name,desc,idList,due,dueComplete,closed,idMembers&members=true&member_fields=fullName&key={2}&token={3}".format(
                self.api_url, board_id, self.api_key, self.api_token)
        req = requests.get(url, params=None)
        return req.json()

    def lists(self, list_id):
        url = "{0}/lists/{1}?key={2}&token={3}".format(self.api_url, list_id, self.api_key, self.api_token)
        req = requests.get(url, params=None)
        return req.json()

    def checklists(self, card_id):
        url = "{0}/cards/{1}/checklists?key={2}&token={3}".format(
                self.api_url, card_id, self.api_key, self.api_token)
        req = requests.get(url, params=None)
        return req.json()

[(12, 'os.getenv', 'os.getenv', (['"""TRELLO_URL"""'], {'default': "self.config['api']['url']"}), False, 'import os\n'), (13, 'os.getenv', 'os.getenv', (['"""TRELLO_API_KEY"""'], {'default': "self.config['api']['key']"}), False, 'import os\n'), (14, 'os.getenv', 'os.getenv', (['"""TRELLO_API_TOKEN"""'], {'default': "self.config['api']['token']"}), False, 'import os\n'), (15, 'os.getenv', 'os.getenv', (['"""TRELLO_ORGANIZATION"""'], {'default': "self.config['api']['organization']"}), False, 'import os\n'), (16, 'os.getenv', 'os.getenv', (['"""TRELLO_OUTPUT_FILE"""'], {'default': "self.config['api']['output_file_name']"}), False, 'import os\n'), (26, 'requests.get', 'requests.get', (['url'], {'params': 'None'}), False, 'import requests\n'), (32, 'requests.get', 'requests.get', (['url'], {'params': 'None'}), False, 'import requests\n'), (37, 'requests.get', 'requests.get', (['url'], {'params': 'None'}), False, 'import requests\n'), (43, 'requests.get', 'requests.get', (['url'], {'params': 'None'}), False, 'import requests\n'), (11, 'os.path.expanduser', 'os.path.expanduser', (['"""~"""'], {}), False, 'import os\n')]