コード例 #1
0
 def __read_details_helper(self, detail_xml, type_string, DetailClass):
     """
     Use this method to read the details responses from get and post 
     requests for LikeMinded projects and resources.
     """
     detail_dict = xml2dict(detail_xml)[type_string]
     detail_dict = self.__fill_in_params(detail_dict, DetailClass)
     details = DetailClass(**detail_dict)
     return details
コード例 #2
0
 def organizations(self):
     """Get all the organizations used in LikeMinded.
     
     Return a list of Organization objects.
     """
     path = '/organizations'
     query = { 'apikey' : self.__key }
     response, organizations_xml = self.__connection.get(path, query)
     
     organizations = []
     organizations_dict = xml2dict(organizations_xml).organizations
     
     for organization_dict in organizations_dict.organization:
         organization = Organization(**organization_dict)
         organizations.append(organization)
     
     return organizations
コード例 #3
0
 def __search_helper(self, query, category, subcategory, 
                     type, status, sort, page):
     """
     A helper search function that is aware of pagination.  Pagination is
     abstracted out of the public search function so that the user has no
     need to be aware of it.
     """
     
     # Process the arguments.
     if isinstance(category, (list, tuple)):
         category = ','.join(map(str, category))
     else:
         category = str(category)
     
     if isinstance(subcategory, (list, tuple)):
         subcategory = ','.join(map(str, subcategory)) 
     else:
         subcategory = str(subcategory)
     
     search_terms = { 'query' : query,
                      'category' : category, 
                      'subcategory' : subcategory, 
                      'type' : type, 
                      'status' : status, 
                      'sort' : sort,
                      'page' : page, 
                      'apikey' : self.__key }
     response, search_xml = self.__connection.get('/search/', search_terms)
     
     search_dict = xml2dict(search_xml)
     results_dict = search_dict.search_results.results
     
     results = self.__make_search_results(
         results_dict, 
         lambda: self.__search_helper(query, category, subcategory, 
                                      type, status, sort, page+1))
     return results
コード例 #4
0
 def categories(self):
     """Get all categories and subcategories used in LikeMinded.
     
     Return a CategoryList object.  This is like a tuple of Category objects.
     It has two additional properties: ``subcategories``, which returns a
     list of all Subcategory objects, and ``all``, which gives all 
     Category and Subcategory objects.
     """
     path = '/categories'
     query = { 'apikey' : self.__key }
     response, categories_xml = self.__connection.get(path, query)
     
     category_list = []
     categories_dict = xml2dict(categories_xml).categories
     
     subcategories_by_category_id = {}
     for subcategory_dict in categories_dict.sub_categories:
         subcategory = SubCategory(**subcategory_dict)
         
         cid = subcategory.category_id
         if cid not in subcategories_by_category_id:
             subcategories_by_category_id[cid] = [subcategory]
         else:
             subcategories_by_category_id[cid].append(subcategory)
     
     categories_by_id = {}
     for category_dict in categories_dict.category:
         category_dict['subcategories'] = \
             subcategories_by_category_id[category_dict.id]
         category = Category(**category_dict)
         
         categories_by_id[category.id] = category
         category_list.append(category)
     
     categories = CategoryList(category_list)
     
     return categories