import requests
import json


def __get_main_measures(desired_metadata):
    """
    Just use the requests module to make requests to the API for the top level
    metadata we need to retrieve
    
    Parameters
    ----------
    desired_metadata : dict
        A nested JSON like structure of {'measure':content} format. For each 
        measure, the content is a dictionary, which has 'url' containing the
        API address for that measure
    Returns
    -------
    desired_metadata : dict
        The original dictionary modified in place to add responses, json, and 
        DataFrames from the successful API requests
    """
    
    for dim, contents in desired_metadata.items():
        print(dim)
        # Make request
        response = requests.get(contents['url'])
        # Load to JSON
        json_content = json.loads(response.content)
        
        # Write back to dimensions dict
        desired_metadata[dim]['response'] = response
        desired_metadata[dim]['json'] = json_content
    
    return desired_metadata