def parts_match(self, queries, exact_only=False, **show_hide): ''' https://octopart.com/api/docs/v3/rest-api#endpoints-parts-match ''' method = 'parts/match' args = {'queries': queries, 'exact_only': exact_only} params = {} params.update(Part.includes(**select_incls(show_hide))) params.update(Part.shows(**select_shows(show_hide))) params.update(Part.hides(**select_hides(show_hide))) for q in queries: if type(q) != dict: raise TypeArgumentError(['queries'], ['str'], []) json_obj = self._get_data(method, args, params, ver=3) # XXX consider using the following? # items = [Part.new_from_dict(item) for\ # item in json_obj['results']['items']] if json_obj: return dict_to_class(json_obj) else: return None
def parts_get(self, uid): ''' https://octopart.com/api/docs/v3/rest-api#endpoints-parts-get ''' method = 'parts/{:d}'.format(uid) json_obj = self._get_data(method, {}, ver=3) if json_obj: return dict_to_class(json_obj) else: return None
def __init__(self, request, results, hits, msec, **kwargs): args = copy.deepcopy(kwargs) self.request = dict_to_class(request, SearchRequest) self.results = list_to_class(results, SearchResult) self.hits = hits self.msec = msec self.facet_results = args.get('facet_results') # XXX This doesn't appear to be a SearchFacetResult! # Unsure of which object in the schema to use... #self.facet_results = list_to_class( # args.get('facet_results'), SearchFacetResult) self.stats_results = list_to_class(args.get('stats_results'), SearchStatsResult) self.spec_metadata = args.get('spec_metadata')
def parts_search( self, q="", start=0, limit=10, sortby="score desc", ): ''' https://octopart.com/api/docs/v3/rest-api#endpoints-parts-search''' # filter[fields][<fieldname>][]: string = "", # filter[queries][]: string = "", # facet[fields][<fieldname>][include]: boolean = false, # facet[fields][<fieldname>][exclude_filter]: boolean = false, # facet[fields][<fieldname>][start]: integer = 0, # facet[fields][<fieldname>][limit]: integer = 10, # facet[queries][]: string = "", # stats[<fieldname>][include]: boolean = false, # stats[<fieldname>][exclude_filter]: boolean = false, # spec_drilldown[include]: boolean = false, # spec_drilldown[exclude_filter]: boolean = false, # spec_drilldown[limit]: integer = 10 method = 'parts/search' if not len(q) >= 2: raise RangeArgumentError(['q'], [int], [2, float('inf')]) if limit not in range(0, 101): raise RangeArgumentError(['limit'], [int], [0, 100]) if start not in range(0, 1001): raise RangeArgumentError(['limit'], [int], [0, 1000]) json_obj = self._get_data(method, { 'q': q, 'limit': limit, 'start': start, 'sortby': sortby }, ver=3) if json_obj: return dict_to_class(json_obj) else: return None
def __init__(self, item): # XXX HACK: We need to implement dynamic object instantiation # This could be any type of object. self.item = dict_to_class(item, Part)
def __init__(self, request, results, msec): self.request = dict_to_class(request, PartsMatchRequest) self.results = list_to_class(results, PartsMatchResult) self.msec = msec