예제 #1
0
def _ooyala_feed(feed, *resource, **kwargs):
    method = kwargs.pop('method', 'post' if 'data' in kwargs else 'get')
    path = '/'.join(('', 'v2', feed) + resource)
    params = dict(
        api_key=app.config['OOYALA_API_KEY'],
        expires=int(time()) + 60,
    )
    params.update(kwargs.pop('params', {}))
    params['signature'] = _generate_signature(method, path, params, kwargs.get('data', ''))
    response = requests.request(method, urljoin(BASE_URL, path), params=params, **kwargs)
    response.raise_for_status()
    return response.json()
예제 #2
0
def _youtube_feed_requests(feed, id, params=None, content=None):
    """Get youtube feed data as json"""
    url = GDATA_URL % (feed, id)
    params = dict(v=2, alt='json', **(params or {}))
    headers = {'User-Agent': app.config['USER_AGENT']}
    if content:
        method = 'POST'
        headers['Content-Type'], data = content
    else:
        method = 'GET'
        data = None
    try:
        response = requests.request(method, url, headers=headers,
                                    params=params, data=data)
        response.raise_for_status()
    except Exception, e:
        if hasattr(e, 'response'):
            log.error('youtube request failed for %s/%s: %d: %s',
                      feed, id, e.response.status_code, e.response.text)
        raise