Example #1
0
    def filter_companies(self, query, **kwargs):
        """Filter companies by a given query string. The query string must be in
        the format specified in the API documentation at:
          https://developers.freshdesk.com/api/#filter_companies

        query = "(company_field:integer OR company_field:'string') AND company_field:boolean"
        """
        if len(query) > 512:
            raise AttributeError("Query string can have up to 512 characters")

        url = "search/companies?"
        page = kwargs.get("page", 1)
        per_page = 30

        companies = []
        while True:
            this_page = self._api._get(
                url + 'page={}&query="{}"'.format(page, query), kwargs)
            this_page = this_page["results"]
            companies += this_page
            if len(this_page) < per_page or page == 10 or "page" in kwargs:
                break
            page += 1

        return [Company(**c) for c in companies]
Example #2
0
    def list_companies(self, **kwargs):
        url = "companies?"
        page = kwargs.get("page", 1)
        per_page = kwargs.get("per_page", 100)

        companies = []

        # Skip pagination by looping over each page and adding companies if 'page' key is not in kwargs.
        # else return the requested page and break the loop
        while True:
            this_page = self._api._get(url + "page=%d&per_page=%d" % (page, per_page), kwargs)
            companies += this_page
            if len(this_page) < per_page or "page" in kwargs:
                break

            page += 1

        return [Company(**c) for c in companies]
Example #3
0
 def get_company(self, company_id):
     url = "companies/%s" % company_id
     return Company(**self._api._get(url))
Example #4
0
 def update_company(self, company_id, **data):
     url = "companies/%d" % company_id
     return Company(**self._api._put(url, data=json.dumps(data)))
Example #5
0
 def create_company(self, *args, **kwargs):
     """Creates a company"""
     url = "companies"
     return Company(**self._api._post(url, data=json.dumps(kwargs)))
Example #6
0
 def get_companies(self):
     # NOTIMPL pagination
     url = 'companies/'
     companies = self._api._get(url)
     return [Company(**c) for c in companies]