PK!݀ucscart/__init__.pyfrom .client import * PK! cscart/client.pyimport requests import json import base64 from logging import basicConfig, getLogger, DEBUG from typing import Dict, Any logger = getLogger(__name__) class Client: def __init__(self, url_base: str, email: str, api_key: str) -> None: self.url_base = url_base self.authorization = "Basic " + base64.b64encode( f"{email}:{api_key}".encode("utf-8") ).decode("utf-8") def _get_API(self, url: str) -> requests.Response: return requests.get(url, headers={"authorization": self.authorization}) def get_categories( self, category_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "categories" + ("" if category_id is None else f"/{category_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_orders( self, order_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = self.url_base + "orders" + ("" if order_id is None else f"/{order_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_payment_methods( self, payment_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "payments" + ("" if payment_id is None else f"/{payment_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_product_features( self, feature_id: int = None, product_id: int = None, params: Dict[str, Any] = {}, ) -> requests.Response: url = self.url_base + ("" if product_id is None else f"products/{product_id}/") url = url + "features" + ("" if feature_id is None else f"/{feature_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_products( self, product_id: int = None, category_id: int = None, params: Dict[str, Any] = {}, ) -> requests.Response: url = self.url_base + ( "" if category_id is None else f"categories/{category_id}/" ) url = url + "products" + ("" if product_id is None else f"/{product_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_settings( self, setting_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "settings" + ("" if setting_id is None else f"/{setting_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_shipments( self, shipment_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "shipments" + ("" if shipment_id is None else f"/{shipment_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_shipping_methods( self, shipping_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "shippings" + ("" if shipping_id is None else f"/{shipping_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_statuses( self, statuse_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = ( self.url_base + "statuses" + ("" if statuse_id is None else f"/{statuse_id}") ) url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_stores( self, store_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = self.url_base + "stores" + ("" if store_id is None else f"/{store_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_taxes( self, taxe_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = self.url_base + "taxes" + ("" if taxe_id is None else f"/{taxe_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_users( self, user_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = self.url_base + "users" + ("" if user_id is None else f"/{user_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) def get_usergroups( self, usergroup_id: int = None, user_id: int = None, params: Dict[str, Any] = {} ) -> requests.Response: url = self.url_base + ("" if user_id is None else f"users/{user_id}/") url = url + "usergroups" + ("" if usergroup_id is None else f"/{usergroup_id}") url = url + ( "" if not params else "?" + "&".join([f"{k}={v}" for k, v in params.items()]) ) return self._get_API(url) if __name__ == "__main__": basicConfig(format="%(asctime)s : %(threadName)s : %(levelname)s : %(message)s") logger.setLevel(DEBUG) f = open("config.json", encoding="utf-8") config = json.load(f) f.close() url_base = config["cscart"]["url_base"] email = config["cscart"]["email"] api_key = config["cscart"]["api_key"] c = Client(url_base, email, api_key) logger.debug(f"url_base :{url_base}, email :{email}, api_key:{api_key}") params = {"page": 1, "items_per_page": 1} logger.debug(c.get_categories(params=params).json()) logger.debug(c.get_orders(params=params).json()) logger.debug(c.get_payment_methods(params=params).json()) logger.debug(c.get_product_features(params=params).json()) logger.debug(c.get_products(params=params).json()) logger.debug(c.get_settings(params=params).json()) logger.debug(c.get_shipments(params=params).json()) logger.debug(c.get_shipping_methods(params=params).json()) logger.debug(c.get_statuses(params=params).json()) logger.debug(c.get_stores(params=params).json()) logger.debug(c.get_taxes(params=params).json()) logger.debug(c.get_users(params=params).json()) PK!(7  )cscart_api_client-0.1.0.dist-info/LICENSECopyright 2019 Mizuki Kobayashi 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. PK!HڽTU'cscart_api_client-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HH/\*cscart_api_client-0.1.0.dist-info/METADATASO0*_8&&EjT0iZ\S ;'-[5 "wݽLe!Q&eMOE}2\zLSI^)0A'/NؼZMƇdHP>a+pi .`Ma7VCdI/]ҴTDnu:UV`a6yl huW B8 .AxFJmF|yB Y.WrmʔVQFvڱC{֩<&QU ;tw.Oiwq&N=rLgqdܑ\55ӧ>Zƃt,tO?gB7q3Z\;-#s"! j;O`)rJ%4g\.0%V c~ -mxG6v Ru8~chQa%<=zuU kۅkPK!H~ژ.(cscart_api_client-0.1.0.dist-info/RECORDMr0@g$@Yt$Z_ BdD!EAO߅uK/yyg~J)㬧TjGT? 9T\QJ6;6@*BRl6P^"{kyܴnh" Ϗv7iUMYe HTL ~ dq~uoФ ؖ{l"/OM) Y&g\vn^giJN7>fQx/.&2 Xd]6ݱZUj 1U'^Xc_#APK!݀ucscart/__init__.pyPK! Fcscart/client.pyPK!(7  )cscart_api_client-0.1.0.dist-info/LICENSEPK!HڽTU'!cscart_api_client-0.1.0.dist-info/WHEELPK!HH/\*"cscart_api_client-0.1.0.dist-info/METADATAPK!H~ژ.(%cscart_api_client-0.1.0.dist-info/RECORDPKz&