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()

[((262, 320), 'os.getenv', 'os.getenv', (['"""TRELLO_URL"""'], {'default': "self.config['api']['url']"}), "('TRELLO_URL', default=self.config['api']['url'])\n", (271, 320), False, 'import os\n'), ((344, 406), 'os.getenv', 'os.getenv', (['"""TRELLO_API_KEY"""'], {'default': "self.config['api']['key']"}), "('TRELLO_API_KEY', default=self.config['api']['key'])\n", (353, 406), False, 'import os\n'), ((432, 498), 'os.getenv', 'os.getenv', (['"""TRELLO_API_TOKEN"""'], {'default': "self.config['api']['token']"}), "('TRELLO_API_TOKEN', default=self.config['api']['token'])\n", (441, 498), False, 'import os\n'), ((527, 603), 'os.getenv', 'os.getenv', (['"""TRELLO_ORGANIZATION"""'], {'default': "self.config['api']['organization']"}), "('TRELLO_ORGANIZATION', default=self.config['api']['organization'])\n", (536, 603), False, 'import os\n'), ((631, 710), 'os.getenv', 'os.getenv', (['"""TRELLO_OUTPUT_FILE"""'], {'default': "self.config['api']['output_file_name']"}), "('TRELLO_OUTPUT_FILE', default=self.config['api']['output_file_name'])\n", (640, 710), False, 'import os\n'), ((971, 1001), 'requests.get', 'requests.get', (['url'], {'params': 'None'}), '(url, params=None)\n', (983, 1001), False, 'import requests\n'), ((1310, 1340), 'requests.get', 'requests.get', (['url'], {'params': 'None'}), '(url, params=None)\n', (1322, 1340), False, 'import requests\n'), ((1520, 1550), 'requests.get', 'requests.get', (['url'], {'params': 'None'}), '(url, params=None)\n', (1532, 1550), False, 'import requests\n'), ((1763, 1793), 'requests.get', 'requests.get', (['url'], {'params': 'None'}), '(url, params=None)\n', (1775, 1793), False, 'import requests\n'), ((191, 214), 'os.path.expanduser', 'os.path.expanduser', (['"""~"""'], {}), "('~')\n", (209, 214), False, 'import os\n')]