How to use the mkmsdk.MKMClient.MKMClient function in mkmsdk

To help you get started, we’ve selected a few mkmsdk 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 evonove / mkm-sdk / tests / tests_unit / test_api.py View on Github external
def test_create_auth_with_empty_string_token():
    """
    Verifies that the custom MKMClient is used
    when access token and access token secret
    are empty strings.
    """
    api = Api("https://api.cardmarket.com/ws/v1.1/output.json")
    auth = api.create_auth(
        "https://api.cardmarket.com/ws/v1.1/output.json",
        app_token="app_token",
        app_secret="app_secret",
        access_token="",
        access_token_secret="",
    )

    assert isinstance(auth.client, MKMClient)
    assert auth.client.client_key == "app_token"
    assert auth.client.client_secret == "app_secret"
    assert auth.client.resource_owner_key == ""
    assert auth.client.resource_owner_secret == ""
github evonove / mkm-sdk / tests / tests_integration / test_oauth.py View on Github external
def test_widget_app_oauth1_is_correct():
    """Verifies if response from backend is positive using custom Client."""
    url = "https://sandbox.cardmarket.com/ws/v1.1/output.json/games"
    auth = MKMOAuth1(
        os.environ.get("MKM_APP_TOKEN"),
        client_secret=os.environ.get("MKM_APP_SECRET"),
        resource_owner_key=os.environ.get("MKM_ACCESS_TOKEN"),
        resource_owner_secret=os.environ.get("MKM_ACCESS_TOKEN_SECRET"),
        realm=url,
        client_class=MKMClient,
    )

    r = requests.get(url, auth=auth)

    assert r.status_code == 200
github evonove / mkm-sdk / tests / tests_unit / test_client.py View on Github external
def test_params_are_unicode():
    """
    Verifies that parameters are unicode, otherwise
    oauthlib raises a ValueError since they can't be escaped
    """
    client = MKMClient(
        client_key="app_token",
        client_secret="app_secret",
        resource_owner_key="",
        resource_owner_secret="",
        realm="https://sandbox.cardmarket.com",
        nonce="0987654321",
        timestamp="1234567890",
    )

    params = client.get_oauth_params(Request(uri="https://sandbox.cardmarket.com"))

    assert isinstance(params[0][0], six.text_type)
    assert isinstance(params[0][1], six.text_type)
    assert isinstance(params[1][0], six.text_type)
    assert isinstance(params[1][1], six.text_type)
    assert isinstance(params[2][0], six.text_type)
github evonove / mkm-sdk / tests / tests_unit / test_client.py View on Github external
def test_get_oauth_params():
    """Verifies oauth_token is added to the list of params when an empty string."""

    client = MKMClient(
        client_key="app_token",
        client_secret="app_secret",
        resource_owner_key="",
        resource_owner_secret="",
        realm="https://sandbox.cardmarket.com",
        nonce="0987654321",
        timestamp="1234567890",
    )

    params = client.get_oauth_params(Request(uri="https://sandbox.cardmarket.com"))

    assert params[0][0] == "oauth_nonce"
    assert params[0][1] == "0987654321"
    assert params[1][0] == "oauth_timestamp"
    assert params[1][1] == "1234567890"
    assert params[2][0] == "oauth_version"
github evonove / mkm-sdk / mkmsdk / api.py View on Github external
`access_token_secret`: use this access token secret instead of the one in env vars

        Return:
            `auth`: Returns an instance of `MKMOAuth1` with `url` as realm
        """

        app_token = app_token if app_token is not None else get_mkm_app_token()
        app_secret = app_secret if app_secret is not None else get_mkm_app_secret()
        access_token = access_token if access_token is not None else get_mkm_access_token()
        access_token_secret = access_token_secret if access_token_secret is not None else get_mkm_access_token_secret()

        # If access_token and access_token_secret are empty strings a personalized OAuth1 Client is used.
        # This is done because that would mean the user is using a Widget Application and having empty strings
        # as tokens causes issues with the default Client
        if not access_token and not access_token_secret:
            client = MKMClient
        else:
            client = Client

        return MKMOAuth1(
            app_token,
            client_secret=app_secret,
            resource_owner_key=access_token,
            resource_owner_secret=access_token_secret,
            client_class=client,
            realm=url,
        )
github evonove / mkm-sdk / mkmsdk / MKMClient.py View on Github external
def get_oauth_params(self, request):
        """
        A modified version of the original method get_oauth_params,
        this version appends the `oauth_token` parameter as an empty
        string to the parameters list if not found in it
        """

        parameters = super(MKMClient, self).get_oauth_params(request)

        oauthParamExist = False
        # Loop through the parameters to check if oauth_token is found
        for param in parameters:
            if "oauth_token" in param:
                oauthParamExist = True
                break

        # We append the empty string oauth_token if it's not already there since MKM expects
        # the OAuth1 Header to have the parameter in any case, this has to be done otherwise
        # the response will always be 401 Unauthorized
        # Documentation: https://www.mkmapi.eu/ws/documentation/API:Auth_OAuthHeader
        if not oauthParamExist:
            parameters.append(("oauth_token", ""))

        return parameters