GithubHelp home page GithubHelp logo

Comments (2)

RasmusThing avatar RasmusThing commented on June 23, 2024

This should do the trick.
`def _get_groups(self, url, filter: str = None):
"""
Get generic group lists.

:param url: Base URL for requesting lists
:return: result dictionary
"""
result = {
    "success": False,
    "response": "",
    "error": "",
}

self.ise.headers.update(
    {"Accept": "application/json", "Content-Type": "application/json"}
)

f = furl(url)
# Max resources per page cannot be more then 100 resources.
f.args["size"] = 100
# TODO add filter valication
if filter:
    f.args["filter"] = filter

resp = self.ise.get(f.url, timeout=self.timeout)

if resp.status_code == 200:
    result["success"] = True
    result["total"] = resp.json()["SearchResult"]["total"]
    result["response"] = []
    for page in range(1, int((result["total"] / f.args["size"] + 1) + 1)):
        f.args["page"] = page
        resp = self.ise.get(f.url, timeout=self.timeout)
        if resp.status_code == 200:
            result["response"] += [
                (i["name"], i["id"], i["description"])
                for i in resp.json()["SearchResult"]["resources"]
            ]
    return result

else:
    return ERS._pass_ersresponse(result, resp)

def _get_objects(self, url, filter: str = None):
"""
Generic method for requesting objects lists.

:param url: Base URL for requesting lists
:param filter: argument side of a ERS filter string. Default: None
:return: result dictionary
"""
result = {
    "success": False,
    "response": "",
    "error": "",
}

self.ise.headers.update(
    {"Accept": "application/json", "Content-Type": "application/json"}
)

f = furl(url)
# Max resources per page cannot be more then 100 resources.
f.args["size"] = 100
# TODO add filter valication
if filter:
    f.args["filter"] = filter

resp = self.ise.get(f.url, timeout=self.timeout)

if resp.status_code == 200:
    json_res = resp.json()["SearchResult"]

    if int(json_res["total"]) >= 1:
        result["success"] = True
        result["total"] = json_res["total"]
        result["response"] = []
        for page in range(1, int((result["total"] / f.args["size"] + 1) + 1)):
            f.args["page"] = page
            resp = self.ise.get(f.url, timeout=self.timeout)
            if resp.status_code == 200:
                json_res = resp.json()["SearchResult"]
                result["response"] += [
                    (i["name"], i["id"]) for i in json_res["resources"]
                ]
        return result

    elif int(json_res["total"]) == 0:
        result["success"] = True
        result["response"] = []
        result["total"] = json_res["total"]
        return result
else:
    return ERS._pass_ersresponse(result, resp)`

from pyise-ers.

falkowich avatar falkowich commented on June 23, 2024

Hi,

Thanks for the code!
Is it possible that you can and/or have the time to do a PR?

If not, I'll create a PR myself with the changes.
Again, thanks for the help :)

--
Kind Regards Falk

from pyise-ers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.