# Path: courseraresearchexports/constants/api_constants.py
# COURSE_API = 'https://www.coursera.org/api/onDemandCourses.v1/'
# 
# PARTNER_API = 'https://www.coursera.org/api/partners.v1/'


import logging
import requests
from courseraresearchexports.constants.api_constants import \
    COURSE_API, PARTNER_API
    """
    return requests.get(requests.compat.urljoin(COURSE_API, course_id))


@requests_response_to_model(
    lambda response: response.json()['elements'][0]['id'])
def lookup_course_id_by_slug(course_slug):
    """
    Find the course_id given a course_slug
    """
    payload = {'q': 'slug', 'slug': course_slug}
    return requests.get(COURSE_API, params=payload)


@requests_response_to_model(
    lambda response: int(response.json()['elements'][0]['id']))
def lookup_partner_id_by_short_name(partner_short_name):
    """
    Find the partner_id by short name
    """
    payload = {'q': 'shortName', 'shortName': partner_short_name}
    return requests.get(PARTNER_API, params=payload)


@requests_response_to_model(
    lambda response: response.json()['elements'][0]['shortName'])
def lookup_partner_short_name_by_id(partner_id):
    """
    Find the partner_id by short name
    """

# Path: courseraresearchexports/constants/api_constants.py
# COURSE_API = 'https://www.coursera.org/api/onDemandCourses.v1/'
# 
# PARTNER_API = 'https://www.coursera.org/api/partners.v1/'


# Path: courseraresearchexports/models/utils.py
import logging
import requests
from courseraresearchexports.constants.api_constants import \
    COURSE_API, PARTNER_API

    """
    return requests.get(requests.compat.urljoin(COURSE_API, course_id))


@requests_response_to_model(
    lambda response: response.json()['elements'][0]['id'])
def lookup_course_id_by_slug(course_slug):
    """
    Find the course_id given a course_slug
    """
    payload = {'q': 'slug', 'slug': course_slug}
    return requests.get(COURSE_API, params=payload)


@requests_response_to_model(
    lambda response: int(response.json()['elements'][0]['id']))
def lookup_partner_id_by_short_name(partner_short_name):
    """
    Find the partner_id by short name
    """
    payload = {'q': 'shortName', 'shortName': partner_short_name}
    return requests.get(PARTNER_API, params=payload)


@requests_response_to_model(
    lambda response: response.json()['elements'][0]['shortName'])
def lookup_partner_short_name_by_id(partner_id):
    """
    Find the partner_id by short name
    """

    return requests.get(requests.compat.urljoin(PARTNER_API, str(partner_id)))