def getCompaniesForProject(self, project_id): """Get companies on project REST: GET /projects/#{project_id}/companies.xml Returns a list of all companies associated with given project. Response: <companies> <company> ... </company> <company> ... </company> ... </company> </companies> """ # ensure that we got numerical project id assert isinstance(project_id, int) path = '/projects/%d/companies.xml' response = self.get(path) if response.status == 404: raise NotFoundError, 'Project with %d id is not found!' % project_id rootElement = self.fromXML(response.contents) # TODO: use special Array attribute companies = [] for data in rootElement.getElementsByTagName('company'): companies.append(Company.load(data)) return companies
def getCompanies(self): """Get companies REST: GET /companies.xml Returns a list of all companies visible to the requesting user. Response: <companies> <company> ... </company> <company> ... </company> ... </company> </companies> """ path = '/companies.xml' rootElement = self.fromXML(self.get(path).contents) # TODO: use special Array attribute companies = [] for data in rootElement.getElementsByTagName('company'): companies.append(Company.load(data)) return companies
def getCompanyById(self, company_id): """Get company REST: GET /companies/#{company_id}.xml Returns a single company identified by its integer ID. Response: <company> <id type="integer">1</id> <name>Globex Corporation</name> </company> """ # ensure that we got numerical company id assert isinstance(company_id, int) path = '/companies/%d.xml' % company_id response = self.get(path) if response.status == 404: raise NotFoundError, 'Company with %d id is not found!' % company_id rootElement = self.fromXML(response.contents) return Company.load(rootElement)