mkmsdk2 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mkmsdk2-0.7.0/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2015 Silvano Cerza
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include README.rst
2
+ include HISTORY.rst
mkmsdk2-0.7.0/PKG-INFO ADDED
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: mkmsdk2
3
+ Version: 0.7.0
4
+ Summary: MagicKardMarket sdk
5
+ Home-page: https://github.com/katry0/mkm-sdk
6
+ Author: Najada
7
+ License: MIT
8
+ Keywords: mkm magickardmarket magiccardmarket sdk mtg magic the gathering card market rest tcg trading card game pokemon wow world of warcraft yugioh
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Natural Language :: English
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ License-File: LICENSE
23
+ Requires-Dist: requests
24
+ Requires-Dist: requests_oauthlib
25
+ Dynamic: author
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: home-page
29
+ Dynamic: keywords
30
+ Dynamic: license
31
+ Dynamic: license-file
32
+ Dynamic: requires-dist
33
+ Dynamic: summary
34
+
35
+ # Fork of mkm-sdk project
36
+
37
+ This is fork of mkm-sdk project [Original repo](https://github.com/silvanocerza/mkm-sdk).<br>
38
+
39
+ This fork was created to update the endpoint address in the mkm library, as the maintainer of the original project has not yet responded to [PR](https://github.com/silvanocerza/mkm-sdk/pull/2).
40
+
41
+
42
+ # Magic Kard Market Python SDK
43
+
44
+ [![image](https://badge.fury.io/py/mkmsdk.png)](http://badge.fury.io/py/mkmsdk)
45
+
46
+ [![image](https://readthedocs.org/projects/mkm-sdk/badge/?version=latest)](http://mkm-sdk.readthedocs.org/en/latest/)
47
+
48
+ [![image](https://coveralls.io/repos/evonove/mkm-sdk/badge.svg)](https://coveralls.io/r/evonove/mkm-sdk)
49
+
50
+ [![image](https://travis-ci.org/evonove/mkm-sdk.svg)](https://travis-ci.org/evonove/mkm-sdk)
51
+
52
+ A simple SDK for dedicated and widget apps working with Magic Kard
53
+ Market.
54
+
55
+ # Contributing
56
+
57
+ Feel free to contribute! Submit [a PR following the
58
+ guidelines](https://mkm-sdk.readthedocs.io/en/latest/contributing.html#pull-request-guidelines/)
59
+ and it will be alright.
60
+
61
+ # Requirements
62
+
63
+ - Python 3.8, 3.9, 3.10, 3.11
64
+ - [Requests](http://docs.python-requests.org/)
65
+ - [Requests_OAuthlib](https://github.com/requests/requests-oauthlib/)
66
+
67
+ # Setup
68
+
69
+ From the command line:
70
+
71
+ pip install mkmsdk
72
+
73
+ For the SDK to work properly you need to create four environment
74
+ variables holding the tokens necessary to create the authorization to
75
+ make requests. You can find them in your Magic Kard Market account page
76
+ under the apps section.
77
+
78
+ - `MKM_APP_TOKEN`
79
+ - `MKM_APP_SECRET`
80
+ - `MKM_ACCESS_TOKEN`
81
+ - `MKM_ACCESS_TOKEN_SECRET`
82
+
83
+ [MKM_ACCESS_TOKEN]{.title-ref} and [MKM_ACCESS_TOKEN_SECRET]{.title-ref}
84
+ need to be set to empty string if you want to use a widget app.
85
+
86
+ # Usage
87
+
88
+ First thing to do is import the [Mkm]{.title-ref} class and the API map:
89
+
90
+ from mkmsdk.mkm import Mkm
91
+ from mkmsdk.api_map import _API_MAP
92
+
93
+ Instance a new instance of Mkm:
94
+
95
+ # Using API v1.1
96
+ mkm = Mkm(_API_MAP["1.1"]["api"], _API_MAP["1.1"]["api_root"])
97
+ # Using API v2.0
98
+ mkm = Mkm(_API_MAP["2.0"]["api"], _API_MAP["2.0"]["api_root"])
99
+
100
+ If you want to test on Magic Card Market\'s sandbox you must use the
101
+ sandbox root endpoint:
102
+
103
+ mkm_sandbox = Mkm(_API_MAP["2.0"]["api"], _API_MAP["2.0"]["api_sandbox_root"])
104
+
105
+ To make a request:
106
+
107
+ response = mkm.account_management.account()
108
+
109
+ # Formats an endpoint
110
+ response = mkm.market_place.user(user='SampleUser')
111
+
112
+ # Call endpoint with specified parameters
113
+ response = mkm.account_management.vacation(params={"onVacation": "false"})
114
+
115
+ This will return a
116
+ [Response](http://docs.python-requests.org/en/latest/api/?highlight=response#requests.Response/)
117
+ object that contains the response from the server.
118
+
119
+ Note that only [market_place]{.title-ref} requests work when using a
120
+ widget app.
121
+
122
+ To get a json you can call response.json().
123
+
124
+ # Tests
125
+
126
+ Integration tests will be skipped if the four environment variables are
127
+ not set.
128
+
129
+ - `MKM_APP_TOKEN`
130
+ - `MKM_APP_SECRET`
131
+ - `MKM_ACCESS_TOKEN`
132
+ - `MKM_ACCESS_TOKEN_SECRET`
133
+
134
+ Note that some tests will be skipped depending if
135
+ [MKM_ACCESS_TOKEN]{.title-ref} and [MKM_ACCESS_TOKEN_SECRET]{.title-ref}
136
+ are empty strings or not.
@@ -0,0 +1,102 @@
1
+ # Fork of mkm-sdk project
2
+
3
+ This is fork of mkm-sdk project [Original repo](https://github.com/silvanocerza/mkm-sdk).<br>
4
+
5
+ This fork was created to update the endpoint address in the mkm library, as the maintainer of the original project has not yet responded to [PR](https://github.com/silvanocerza/mkm-sdk/pull/2).
6
+
7
+
8
+ # Magic Kard Market Python SDK
9
+
10
+ [![image](https://badge.fury.io/py/mkmsdk.png)](http://badge.fury.io/py/mkmsdk)
11
+
12
+ [![image](https://readthedocs.org/projects/mkm-sdk/badge/?version=latest)](http://mkm-sdk.readthedocs.org/en/latest/)
13
+
14
+ [![image](https://coveralls.io/repos/evonove/mkm-sdk/badge.svg)](https://coveralls.io/r/evonove/mkm-sdk)
15
+
16
+ [![image](https://travis-ci.org/evonove/mkm-sdk.svg)](https://travis-ci.org/evonove/mkm-sdk)
17
+
18
+ A simple SDK for dedicated and widget apps working with Magic Kard
19
+ Market.
20
+
21
+ # Contributing
22
+
23
+ Feel free to contribute! Submit [a PR following the
24
+ guidelines](https://mkm-sdk.readthedocs.io/en/latest/contributing.html#pull-request-guidelines/)
25
+ and it will be alright.
26
+
27
+ # Requirements
28
+
29
+ - Python 3.8, 3.9, 3.10, 3.11
30
+ - [Requests](http://docs.python-requests.org/)
31
+ - [Requests_OAuthlib](https://github.com/requests/requests-oauthlib/)
32
+
33
+ # Setup
34
+
35
+ From the command line:
36
+
37
+ pip install mkmsdk
38
+
39
+ For the SDK to work properly you need to create four environment
40
+ variables holding the tokens necessary to create the authorization to
41
+ make requests. You can find them in your Magic Kard Market account page
42
+ under the apps section.
43
+
44
+ - `MKM_APP_TOKEN`
45
+ - `MKM_APP_SECRET`
46
+ - `MKM_ACCESS_TOKEN`
47
+ - `MKM_ACCESS_TOKEN_SECRET`
48
+
49
+ [MKM_ACCESS_TOKEN]{.title-ref} and [MKM_ACCESS_TOKEN_SECRET]{.title-ref}
50
+ need to be set to empty string if you want to use a widget app.
51
+
52
+ # Usage
53
+
54
+ First thing to do is import the [Mkm]{.title-ref} class and the API map:
55
+
56
+ from mkmsdk.mkm import Mkm
57
+ from mkmsdk.api_map import _API_MAP
58
+
59
+ Instance a new instance of Mkm:
60
+
61
+ # Using API v1.1
62
+ mkm = Mkm(_API_MAP["1.1"]["api"], _API_MAP["1.1"]["api_root"])
63
+ # Using API v2.0
64
+ mkm = Mkm(_API_MAP["2.0"]["api"], _API_MAP["2.0"]["api_root"])
65
+
66
+ If you want to test on Magic Card Market\'s sandbox you must use the
67
+ sandbox root endpoint:
68
+
69
+ mkm_sandbox = Mkm(_API_MAP["2.0"]["api"], _API_MAP["2.0"]["api_sandbox_root"])
70
+
71
+ To make a request:
72
+
73
+ response = mkm.account_management.account()
74
+
75
+ # Formats an endpoint
76
+ response = mkm.market_place.user(user='SampleUser')
77
+
78
+ # Call endpoint with specified parameters
79
+ response = mkm.account_management.vacation(params={"onVacation": "false"})
80
+
81
+ This will return a
82
+ [Response](http://docs.python-requests.org/en/latest/api/?highlight=response#requests.Response/)
83
+ object that contains the response from the server.
84
+
85
+ Note that only [market_place]{.title-ref} requests work when using a
86
+ widget app.
87
+
88
+ To get a json you can call response.json().
89
+
90
+ # Tests
91
+
92
+ Integration tests will be skipped if the four environment variables are
93
+ not set.
94
+
95
+ - `MKM_APP_TOKEN`
96
+ - `MKM_APP_SECRET`
97
+ - `MKM_ACCESS_TOKEN`
98
+ - `MKM_ACCESS_TOKEN_SECRET`
99
+
100
+ Note that some tests will be skipped depending if
101
+ [MKM_ACCESS_TOKEN]{.title-ref} and [MKM_ACCESS_TOKEN_SECRET]{.title-ref}
102
+ are empty strings or not.
@@ -0,0 +1,32 @@
1
+ from oauthlib.oauth1 import Client
2
+
3
+
4
+ class MKMClient(Client):
5
+ """
6
+ A personalized OAuth1 Client used for Widget Applications
7
+ """
8
+
9
+ def get_oauth_params(self, request):
10
+ """
11
+ A modified version of the original method get_oauth_params,
12
+ this version appends the `oauth_token` parameter as an empty
13
+ string to the parameters list if not found in it
14
+ """
15
+
16
+ parameters = super(MKMClient, self).get_oauth_params(request)
17
+
18
+ oauthParamExist = False
19
+ # Loop through the parameters to check if oauth_token is found
20
+ for param in parameters:
21
+ if "oauth_token" in param:
22
+ oauthParamExist = True
23
+ break
24
+
25
+ # We append the empty string oauth_token if it's not already there since MKM expects
26
+ # the OAuth1 Header to have the parameter in any case, this has to be done otherwise
27
+ # the response will always be 401 Unauthorized
28
+ # Documentation: https://www.mkmapi.eu/ws/documentation/API:Auth_OAuthHeader
29
+ if not oauthParamExist:
30
+ parameters.append(("oauth_token", ""))
31
+
32
+ return parameters
@@ -0,0 +1,45 @@
1
+ from requests_oauthlib import OAuth1
2
+ from requests.utils import to_native_string
3
+ from urllib.parse import unquote
4
+
5
+
6
+ class MKMOAuth1(OAuth1):
7
+ """
8
+
9
+ """
10
+
11
+ def __call__(self, r):
12
+ r = super(MKMOAuth1, self).__call__(r)
13
+
14
+ r.prepare_headers(r.headers)
15
+
16
+ correct_signature = self.decode_signature(r.headers)
17
+
18
+ r.headers.__setitem__("Authorization", correct_signature)
19
+ r.url = to_native_string(r.url)
20
+ return r
21
+
22
+ @staticmethod
23
+ def decode_signature(given_header):
24
+ """
25
+ Decodes the signature given an header. This is done because MKM
26
+ expects an authorization header with different parameters encoding
27
+ specified in section 3.6 of OAuth 1 specification (RFC5849).
28
+
29
+ Parameters:
30
+ `given_header`: Authorization header
31
+
32
+ Return:
33
+ `authorization_string`: Returns a string of the decoded signature
34
+ """
35
+
36
+ authorization_byte = given_header["Authorization"]
37
+ authorization_string = authorization_byte.decode()
38
+ signature_position = authorization_string.find('oauth_signature="') + len('oauth_signature="')
39
+ sub_string_signature = authorization_string[signature_position:]
40
+
41
+ decoded_sub_string_signature = unquote(sub_string_signature)
42
+ authorization_string = authorization_string[:signature_position]
43
+ authorization_string = "{}{}".format(authorization_string, decoded_sub_string_signature)
44
+
45
+ return authorization_string
@@ -0,0 +1,8 @@
1
+ """Magic Kard Market SDK"""
2
+
3
+ __title__ = "Magic Kard Market SDK"
4
+ __version__ = "0.7.0"
5
+ __author__ = "Evonove"
6
+ __license__ = "MIT"
7
+
8
+ VERSION = __version__
@@ -0,0 +1,98 @@
1
+ from requests import request
2
+ from oauthlib.oauth1.rfc5849 import Client
3
+
4
+ from .MKMClient import MKMClient
5
+ from . import exceptions
6
+ from .utils import get_mkm_app_token, get_mkm_app_secret, get_mkm_access_token, get_mkm_access_token_secret
7
+ from .MKMOAuth1 import MKMOAuth1
8
+
9
+
10
+ class Api:
11
+ def __init__(self, base_endpoint):
12
+ """
13
+ Initializes the endpoint used for requests
14
+ """
15
+ self.base_endpoint = base_endpoint
16
+
17
+ def request(self, url, method, auth_params=None, **kwargs):
18
+ """
19
+ Sends requests to the server with parameters passed
20
+
21
+ Params:
22
+ `url`: URL where request is submitted
23
+ `method`: Method used for the requests
24
+ `kwargs`: Optional additional parameters used for the request
25
+
26
+ Return:
27
+ `response`: Returns the response received from the server
28
+ """
29
+
30
+ complete_url = "{}{}".format(self.base_endpoint, url)
31
+
32
+ if auth_params is None:
33
+ auth_params = {}
34
+
35
+ auth = self.create_auth(complete_url, **auth_params)
36
+
37
+ # Some MKM endpoints might return a 3xx status code but they're not meant to be followed
38
+ # so disable auto follow of redirections.
39
+ # For more info see the official MKM documentation:
40
+ # https://www.mkmapi.eu/ws/documentation/API_1.1:Main_Page#307_Temporary_Redirect
41
+ response = request(method=method, url=complete_url, auth=auth, allow_redirects=False, **kwargs)
42
+ return self.handle_response(response)
43
+
44
+ def create_auth(self, url, app_token=None, app_secret=None, access_token=None, access_token_secret=None):
45
+ """
46
+ Create authorization with MKMOAuth1, if Access Token and Access Token Secret
47
+ are not found a custom Client is used.
48
+ This is done because MKM expects an authorization header with certain parameters
49
+ even if they're empty strings.
50
+
51
+ Params:
52
+ `url`: URL where request is submitted
53
+ `app_token`: use this app token instead of the one in env vars
54
+ `app_secret`: use this app secret instead of the one in env vars
55
+ `access_token`: use this access token instead of the one in env vars
56
+ `access_token_secret`: use this access token secret instead of the one in env vars
57
+
58
+ Return:
59
+ `auth`: Returns an instance of `MKMOAuth1` with `url` as realm
60
+ """
61
+
62
+ app_token = app_token if app_token is not None else get_mkm_app_token()
63
+ app_secret = app_secret if app_secret is not None else get_mkm_app_secret()
64
+ access_token = access_token if access_token is not None else get_mkm_access_token()
65
+ access_token_secret = access_token_secret if access_token_secret is not None else get_mkm_access_token_secret()
66
+
67
+ # If access_token and access_token_secret are empty strings a personalized OAuth1 Client is used.
68
+ # This is done because that would mean the user is using a Widget Application and having empty strings
69
+ # as tokens causes issues with the default Client
70
+ if not access_token and not access_token_secret:
71
+ client = MKMClient
72
+ else:
73
+ client = Client
74
+
75
+ return MKMOAuth1(
76
+ app_token,
77
+ client_secret=app_secret,
78
+ resource_owner_key=access_token,
79
+ resource_owner_secret=access_token_secret,
80
+ client_class=client,
81
+ realm=url,
82
+ )
83
+
84
+ def handle_response(self, response):
85
+ """
86
+ Check the HTTP response
87
+
88
+ Params:
89
+ `response`: Response received from the server
90
+ Return:
91
+ `response`: Returns the response received if positive or raise exception if negative
92
+ """
93
+
94
+ # We don't automatically follow redirects so accept those responses
95
+ if 200 <= response.status_code <= 399:
96
+ return response
97
+ else:
98
+ raise exceptions.ConnectionError(response)