import requests
import lnpay_py
import json


def get_request(location):
    """
    Network utility method for making a GET call to a LNPay endpoint

    Parameters
    ----------
    location (str): URL path requested

    Returns
    -------
    Network response as a JSON Object.
    """
    endpoint = lnpay_py.__ENDPOINT_URL__ + location
    headers = {
        'X-Api-Key': lnpay_py.__PUBLIC_API_KEY__,
        'X-LNPay-sdk': lnpay_py.__VERSION__
    }

    r = requests.get(url=endpoint, headers=headers)
    return r.json()


def post_request(location, params):
    """
    Network utility method for making a POST call to a LNPay endpoint

    Parameters
    ----------
    location (str): URL path requested
    params (object): the `data` to be POSTed in the network request

    Returns
    -------
    Network response as a JSON Object.
    """
    endpoint = lnpay_py.__ENDPOINT_URL__ + location
    headers = {
        'Content-Type': 'application/json',
        'X-Api-Key': lnpay_py.__PUBLIC_API_KEY__,
        'X-LNPay-sdk': lnpay_py.__VERSION__
    }
    data = json.dumps(params)

    r = requests.post(url=endpoint, data=data, headers=headers)
    return r.json()
