本文整理汇总了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)