How to use the jwplatform.Client function in jwplatform

To help you get started, we’ve selected a few jwplatform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwplayer / jwplatform-py / tests / test_build_request.py View on Github external
def test_signature():

    KEY = 'api_key'
    SECRET = 'api_secret'
    PATH = '/test/resource/show'

    request_params = {
        'a': 1,
        'b': 'two',
        'c3': 'Param 3',
        u'❄': u'⛄',
        't1': True,
        'n0': None
    }

    jwp_client = jwplatform.Client(KEY, SECRET)

    url, params = jwp_client._build_request(PATH, request_params)

    assert url == 'https://api.jwplatform.com/v1{}'.format(PATH)
    assert 'api_nonce' in params
    assert 'api_timestamp' in params
    assert 'api_key' in params
    assert 'api_format' in params
    assert 'api_kit' in params
    assert 'api_signature' in params

    request_params['api_nonce'] = params['api_nonce']
    request_params['api_timestamp'] = params['api_timestamp']
    request_params['api_key'] = params['api_key']
    request_params['api_format'] = params['api_format']
    request_params['api_kit'] = params['api_kit']
github jwplayer / jwplatform-py / tests / test_errors.py View on Github external
def test_supported_errors_parsing(test_case):
    url_expr = re.compile(r'https?://api\.test\.tst/v1/error\?.*')

    responses.add(
        responses.GET, url_expr,
        status=test_case['http_status'],
        content_type='application/json',
        body=json.dumps(test_case['response']))

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')

    with pytest.raises(test_case['expected_exception']) as err:
        jwp_client.error()

    assert err.value.message == test_case['response']['message']
github jwplayer / jwplatform-py / tests / test_resource.py View on Github external
def test_post_existing_resource():
    url_expr = re.compile(r'https?://api\.test\.tst/v1/a/b/c/d')
    responses.add(
        responses.POST, url_expr,
        status=200,
        content_type='application/json',
        body='{"status": "ok"}')

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')
    resp = jwp_client.a.b.c.d(http_method='POST', abcde=123)

    assert resp['status'] == 'ok'
github jwplayer / jwplatform-py / tests / test_resource.py View on Github external
def test_post_parameters_in_url():
    url_expr = re.compile(r'https?://api\.test\.tst/v1/a/b/c/d\?.*')
    responses.add(
        responses.POST, url_expr,
        status=200,
        content_type='application/json',
        body='{"status": "ok"}')

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')
    resp = jwp_client.a.b.c.d(http_method='POST', use_body=False, _post='true', _body='false')

    assert resp['status'] == 'ok'
github jwplayer / jwplatform-py / tests / test_resource.py View on Github external
def test_post_parameters_in_body():
    url_expr = re.compile(r'https?://api\.test\.tst/v1/a/b/c/d\?.*')
    responses.add(
        responses.POST, url_expr,
        status=200,
        content_type='application/json',
        body='{"status": "ok"}')

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')

    # ConnectionError is expected as request parameters are included in the
    # request body for POST request by default.
    with pytest.raises(ConnectionError):
        resp = jwp_client.a.b.c.d(http_method='POST', post='true', _body='none')
github jwplayer / jwplatform-py / tests / test_init.py View on Github external
def test_custom_initialization():

    KEY = '_key_'
    SECRET = '_secret_'
    SCHEME = 'http'
    HOST = 'api.host.domain'
    PORT = 8080
    API_VERSION = 'v7'
    AGENT = 'test_agent'

    jwp_client = jwplatform.Client(
        KEY, SECRET,
        scheme=SCHEME,
        host=HOST,
        port=PORT,
        version=API_VERSION,
        agent=AGENT)

    assert jwp_client._Client__key == KEY
    assert jwp_client._Client__secret == SECRET
    assert jwp_client._scheme == SCHEME
    assert jwp_client._host == HOST
    assert jwp_client._port == PORT
    assert jwp_client._api_version == API_VERSION
    assert jwp_client._agent == AGENT
    assert 'User-Agent' in jwp_client._connection.headers
    assert jwp_client._connection.headers['User-Agent'] == \
github jwplayer / jwplatform-py / tests / test_errors.py View on Github external
def test_empty_response_parsing():
    url_expr = re.compile(r'https?://api\.test\.tst/v1/error\?.*')

    responses.add(
        responses.GET, url_expr,
        status=500,
        content_type='application/json',
        body='')

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')

    with pytest.raises(jwplatform.errors.JWPlatformUnknownError) as err:
        jwp_client.error()

    assert err.value.message == 'Not a valid JSON string: '
github jwplayer / jwplatform-py / tests / test_resource.py View on Github external
def test_long_resource():
    url_expr = re.compile(r'https?://api\.test\.tst/v1/a/b/c/d/f/e\?.*'
                          'abcde=.*')
    responses.add(
        responses.GET, url_expr,
        status=200,
        content_type='application/json',
        body='{"status": "ok"}')

    jwp_client = jwplatform.Client('api_key', 'api_secret', host='api.test.tst')
    resp = jwp_client.a.b.c.d.f.e(abcde='')

    assert resp['status'] == 'ok'
github jwplayer / jwplatform-py / examples / video_s3_create.py View on Github external
def create_video(api_key, api_secret, local_video_path, **kwargs):
    """
    Function which creates new video object via s3 upload method.

    :param api_key:  JWPlatform api-key
    :param api_secret:  JWPlatform shared-secret
    :param local_video_path:  Path to media on local machine.
    :param kwargs: Arguments conforming to standards found @ https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/create.html
    :return:
    """
    filename = os.path.basename(local_video_path)

    # Setup API client
    jwplatform_client = jwplatform.Client(api_key, api_secret)

    # Make /videos/create API call
    logging.info("creating video")
    try:
        response = jwplatform_client.videos.create(upload_method='s3', **kwargs)
    except jwplatform.errors.JWPlatformError as e:
        logging.error("Encountered an error creating a video\n{}".format(e))
        sys.exit(e.message)
    logging.info(response)

    # Construct base url for upload
    upload_url = '{}://{}{}'.format(
        response['link']['protocol'],
        response['link']['address'],
        response['link']['path']
    )