def test_sanity_check_parameter(sample_sanity_check_parameter: list, expected_sanity_check_query: list) -> None: result = [] for sample in sample_sanity_check_parameter: result.append(sanity_check_parameter(domain=sample['domain'], query=sample['query'], refine=sample['refine'], additional=sample['additional'], lang=sample['lang'])) assert expected_sanity_check_query == result
def plenty_api_get_orders_by_date(self, start, end, date_type='create', additional=None, refine=None): """ Get all orders within a specific date range. Parameter: start [str] - Start date end [str] - End date date_type [str] - Specify the type of date {Creation, Change, Payment, Delivery} additional [list] - Additional arguments for the query as specified in the manual refine [dict] - Apply filters to the request Example: {'orderType': '1,4', referrerId: '1'} Restrict the request to order types: 1 and 4 (sales orders and refund) And restrict it to only orders from the referrer with id '1' Return: [JSON(Dict) / DataFrame] <= self.data_format """ date_range = utils.build_date_range(start=start, end=end) if not date_range: print(f"ERROR: Invalid range {start} -> {end}") if not utils.check_date_range(date_range=date_range): print(f"ERROR: {date_range['start']} -> {date_range['end']}") return {} query = utils.build_query_date(date_range=date_range, date_type=date_type) query = utils.sanity_check_parameter(domain='order', query=query, refine=refine, additional=additional) orders = self.__repeat_get_request_for_all_records(domain='orders', query=query) orders = utils.transform_data_type(data=orders, data_format=self.data_format) return orders
def plenty_api_get_items(self, refine: dict = None, additional: list = None, last_update: str = '', lang: str = ''): """ Get product data from PlentyMarkets. Parameter: refine [dict] - Apply filters to the request Example: {'id': '12345', 'flagOne: '5'} additional [list] - Add additional elements to the response data. Example: ['variations', 'itemImages'] last_update [str] - Date of the last update given as one of the following formats: YYYY-MM-DDTHH:MM:SS+UTC-OFFSET YYYY-MM-DDTHH:MM YYYY-MM-DD lang [str] - Provide the text within the data in one of the following languages: developers.plentymarkets.com/rest-doc/gettingstarted#countries Return: [JSON(Dict) / DataFrame] <= self.data_format """ items = None query = {} query = utils.sanity_check_parameter(domain='item', query=query, refine=refine, additional=additional, lang=lang) if last_update: query.update( {'updatedBetween': utils.date_to_timestamp(date=last_update)}) items = self.__repeat_get_request_for_all_records(domain='items', query=query) items = utils.transform_data_type(data=items, data_format=self.data_format) return items
def plenty_api_get_manufacturers(self, refine: dict = None, additional: list = None, last_update: str = ''): """ Get a list of manufacturers (brands), which are setup on PlentyMarkets. Parameter: refine [dict] - Apply a filter to the request The only viable option currently is: 'name' additional [list] - Add additional elements to the response data. Viable options currently: ['commisions', 'externals'] last_update [str] - Date of the last update given as one of the following formats: YYYY-MM-DDTHH:MM:SS+UTC-OFFSET YYYY-MM-DDTHH:MM YYYY-MM-DD Return: [JSON(Dict) / DataFrame] <= self.data_format """ manufacturers = None query = {} query = utils.sanity_check_parameter(domain='manufacturer', query=query, refine=refine, additional=additional) if last_update: query.update({'updatedAt': last_update}) manufacturers = self.__repeat_get_request_for_all_records( domain='manufacturer', query=query) manufacturers = utils.transform_data_type(data=manufacturers, data_format=self.data_format) return manufacturers
def plenty_api_get_variations(self, refine: dict = None, additional: list = None, lang: str = ''): """ Get product data from PlentyMarkets. Parameter: refine [dict] - Apply filters to the request Example: {'id': '2345', 'flagOne: '5'} additional [list] - Add additional elements to the response data. Example: ['stock', 'images'] lang [str] - Provide the text within the data in one of the following languages: Example: 'de', 'en', etc. developers.plentymarkets.com/rest-doc/gettingstarted#countries Return: [JSON(Dict) / DataFrame] <= self.data_format """ variations = None query = {} query = utils.sanity_check_parameter(domain='variation', query=query, refine=refine, additional=additional, lang=lang) variations = self.__repeat_get_request_for_all_records( domain='variations', query=query) variations = utils.transform_data_type(data=variations, data_format=self.data_format) return variations
def plenty_api_get_attributes(self, additional: list = None, last_update: str = '', variation_map: bool = False): """ List all attributes from PlentyMarkets, this will fetch the basic attribute structures, so if you require an attribute value use: additional=['values']. The option variation_map performs an additional request to /rest/items/variations in order to map variation IDs to attribute values. Parameter: additional [list] - Add additional elements to the response data. Viable options: ['values', 'names', 'maps'] last_update [str] - Date of the last update given as one of the following formats: YYYY-MM-DDTHH:MM:SS+UTC-OFFSET attributes-MM-DDTHH:MM YYYY-MM-DD variation_map [bool]- Fetch all variations and add a list of variations, where the attribute value matches to the corresponding attribute value Return: [JSON(Dict) / DataFrame] <= self.data_format """ attributes = None query = {} query = utils.sanity_check_parameter(domain='attribute', query=query, additional=additional) if last_update: query.update({'updatedAt': last_update}) # variation_map was given but the required '&with=values' query is # missing, we assume the desired request was to be made with values if variation_map: if not additional: query.update({'with': 'values'}) if additional: if 'values' not in additional: query.update({'with': 'values'}) attributes = self.__repeat_get_request_for_all_records( domain='attributes', query=query) if variation_map: variation = self.plenty_api_get_variations( additional=['variationAttributeValues']) attributes = utils.attribute_variation_mapping( variation=variation, attribute=attributes) attributes = utils.transform_data_type(data=attributes, data_format=self.data_format) return attributes