@@ -0,0 +1,2309 @@
+%0Aimport requests%0A%0A# Yummly API: https://developer.yummly.com%0A%0A# API URLs%0AURL_BASE    = 'http://api.yummly.com/v1'%0AURL_GET     = URL_BASE + '/api/recipe/'%0AURL_SEARCH  = URL_BASE + '/api/recipes'%0A%0A# API auth properties which should be set externally%0Aapi_id  = None%0Aapi_key = None%0A%0A# basic request config options%0A# @note: have found that Yummly's API %22hangs%22 so it might be a good idea to have some reasonable timeout and handle appropriately%0Atimeout = 5.0%0A%0Aclass YummlyError( Exception ):%0A    '''Exception class for Yummly errors'''%0A    pass%0A%0A### Methods for API get recipe and search recipes%0A%0Adef recipe( recipe_id ):%0A    url = URL_GET + recipe_id%0A    response    = _request( url )%0A    result      = _extract_response( response )%0A    return result%0A%0Adef search( q, limit=40, offset=0 ):%0A    '''%0A    Prepares yummly search API request%0A%0A    :param q: search string%0A    :param limit: max results%0A    :param offset: pagination offset in # of records (e.g. offset=5 means skip first 5 results)%0A%0A    '''%0A%0A    url     = URL_SEARCH%0A    params  = %7B%0A        'q':            q,%0A        'maxResult':    limit,%0A        'start':        offset%0A    %7D%0A%0A    response    = _request( url, params=params )%0A    results     = _extract_response( response )%0A    return results%0A%0A%0A### Helper functions%0A%0Adef handle_errors( fn ):%0A    '''Decorator for handling Yummly errors'''%0A    def handle( *args, **kargs ):%0A        response = fn( *args, **kargs )%0A%0A        status = response.status_code%0A%0A        if status != 200:%0A            if status == 409:%0A                raise YummlyError( 'API id and/or key are invalid or API rate limit exceeded' )%0A            else:%0A                # error ocurred which may not be documented%0A                response.raise_for_status()%0A%0A        return response%0A%0A    return handle%0A%0A@handle_errors%0Adef _request( url, params=None ):%0A    '''%0A    Generic yummly request which attaches meta info (e.g. auth)%0A%0A    :param url: URL of endpoint%0A    :param params: GET params of request%0A%0A    '''%0A%0A    # auth headers%0A    headers = %7B%0A        'X-Yummly-App-ID':  api_id,%0A        'X-Yummly-App-Key': api_key,%0A    %7D%0A%0A    response = requests.get( url, params=params, headers=headers, timeout=timeout )%0A%0A    return response%0A%0Adef _extract_response( response ):%0A    '''Extract data from api resposne'''%0A    return response.json()%0A%0A

Add yummly.recipe and yummly.search functions.