Example #1
0
    def getCategories(self, project_id, cat_type=None):
        """Get categories
        
        REST: GET /projects/#{project_id}/categories.xml(?type=[post|attachment])

        Returns all categories for the given project. To filter by type, pass the
        type parameter, where type can be one of 'post' or 'attachment'.
        
        Response:
            <categories>
                <category>
                    <name>Documents</name>
                    ...
                </category>
                ...
            </categories>
        """
        # ensure we got valid input
        assert isinstance(project_id, int)
        
        path = '/projects/%d/categories.xml' % project_id
        if cat_type is not None:
            assert (isinstance(cat_type, str) and
                    cat_type.lower() in ['post', 'attachment'])
            path = '%s?type=%s' % (path, cat_type.lower())
            
        rootElement = self.fromXML(self.get(path).contents)
        # TODO: use special Array attribute
        categories = []
        for data in rootElement.getElementsByTagName('category'):
            categories.append(Category.load(data))
        return categories
Example #2
0
    def getCategories(self, project_id, cat_type=None):
        """Get categories
        
        REST: GET /projects/#{project_id}/categories.xml(?type=[post|attachment])

        Returns all categories for the given project. To filter by type, pass the
        type parameter, where type can be one of 'post' or 'attachment'.
        
        Response:
            <categories>
                <category>
                    <name>Documents</name>
                    ...
                </category>
                ...
            </categories>
        """
        # ensure we got valid input
        assert isinstance(project_id, int)

        path = '/projects/%d/categories.xml' % project_id
        if cat_type is not None:
            assert (isinstance(cat_type, str)
                    and cat_type.lower() in ['post', 'attachment'])
            path = '%s?type=%s' % (path, cat_type.lower())

        rootElement = self.fromXML(self.get(path).contents)
        # TODO: use special Array attribute
        categories = []
        for data in rootElement.getElementsByTagName('category'):
            categories.append(Category.load(data))
        return categories
Example #3
0
     # second way for company clients
     projects = self.getProjects()
     if not len(projects) > 0:     # can't do anything if we have not projects yet
         return None
     
     # get categories in old way, cause new REST API won't allow us to
     # do this for client persons
     #categories = self.getCategories(projects[0].id, 'post')
     
     # TODO: this is not working either, ForbiddenError is raised
     rootElement = self.fromXML(self.get('/projects/%d/post_categories' % projects[0].id).contents)
     categories = rootElement.getElementsByTagName('post-category')
     if not len(categories) > 0:   # can't do anything if we have not categories yet
         return None
     else:
         category = Category.load(categories[0])
     
     # create message using legacy API, cause new REST based API
     # won't return any useful information in it's response
     path = '/projects/%d/msg/create' % projects[0].id
     message = Message(category_id=category.id,
                       title='temporary message to take login for client person')
     response = self.post(path, data="""<request>%s</request>""" % message.serialize())
     if response.status == 201:    # successfuly created entry
         message_id = int(dict(response.headers)['location'].split('/')[-1][:-4])
         self.destroyMessage(message_id)
         return message
     else:
         return None
 
 
Example #4
0
                projects) > 0:  # can't do anything if we have not projects yet
            return None

        # get categories in old way, cause new REST API won't allow us to
        # do this for client persons
        #categories = self.getCategories(projects[0].id, 'post')

        # TODO: this is not working either, ForbiddenError is raised
        rootElement = self.fromXML(
            self.get('/projects/%d/post_categories' % projects[0].id).contents)
        categories = rootElement.getElementsByTagName('post-category')
        if not len(categories
                   ) > 0:  # can't do anything if we have not categories yet
            return None
        else:
            category = Category.load(categories[0])

        # create message using legacy API, cause new REST based API
        # won't return any useful information in it's response
        path = '/projects/%d/msg/create' % projects[0].id
        message = Message(
            category_id=category.id,
            title='temporary message to take login for client person')
        response = self.post(path,
                             data="""<request>%s</request>""" %
                             message.serialize())
        if response.status == 201:  # successfuly created entry
            message_id = int(
                dict(response.headers)['location'].split('/')[-1][:-4])
            self.destroyMessage(message_id)
            return message