當前位置: 首頁>>代碼示例>>Python>>正文


Python Session.get_all方法代碼示例

本文整理匯總了Python中Session.Session.get_all方法的典型用法代碼示例。如果您正苦於以下問題:Python Session.get_all方法的具體用法?Python Session.get_all怎麽用?Python Session.get_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Session.Session的用法示例。


在下文中一共展示了Session.get_all方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from Session import Session [as 別名]
# 或者: from Session.Session import get_all [as 別名]
class Wrapper: 

    def __init__(self, credentials):
        self.credentials = credentials
        self.queue = RequestQueue(request_limit=600)
        self.session = Session(self.credentials, self.queue)
        self.all_endpoints = {'ticket':{'plural':'tickets', 'singular':'ticket'}, 
                            'organization':{'plural':'organizations', 'singular':'organization'},
                            'requester': {'plural':'users','singular':'user'},
                            'user': {'plural':'users','singular':'user'},
                            'assignee': {'plural':'users','singular':'user'}}
        self.object_cache = BasicCache()
        self.tickets = Endpoint('ticket', self)
        self.organizations = Endpoint('organization', self)
        self.users = Endpoint('user', self)

    def get_all(self, member, fetch=False):
        singular = self.all_endpoints[member]['singular']
        plural = self.all_endpoints[member]['plural']
        responses = self.session.get_all(plural)
        objects = itertools.chain.from_iterable(((zenContainer(self, singular, item['id'], data=item) for item in response.json()[plural]) for response in responses))
        if(fetch):
            objects = list(objects)
        return objects

    def get(self, member, object_id, cache=True):
        singular = self.all_endpoints[member]['singular']
        plural = self.all_endpoints[member]['plural']
        endpoint = '{}/{}'.format(self.plural, object_id)
        if not cache:
            self.expire_cache(endpoint)
        new_obj = self.object_cache.get(endpoint)
        if new_obj:
            return new_obj
        return zenContainer(self, singular, object_id)

    def expire_cache(endpoint):
        cache_url = self.credentials.create_url(endpoint)
        self.queue.cache.delete(cache_url)
        self.object_cache.delete(endpoint)
開發者ID:Nebopolis,項目名稱:pyzendesk,代碼行數:42,代碼來源:Wrapper.py


注:本文中的Session.Session.get_all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。