"""Class to interact with CoinMarketCap"""

import requests


class coinmarketcap:
    def __init__(self, api_key: str) -> None:
        self.api_key = api_key
        self.base_url = "https://pro-api.coinmarketcap.com/v1"

    def all_coins(self) -> list:
        """Retrieve all coins actively present on CMC using the "Map" API
        https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyMap

        Returns:
            list: Contains a dictionary for each coin on CMC
        """
        headers = {"X-CMC_PRO_API_KEY": self.api_key}

        response = requests.get(
            url=f"{self.base_url}/cryptocurrency/map", headers=headers
        )

        return response.json()["data"]
