Ai
1 Star 0 Fork 0

Adolph/shopify_python_api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
limits.py 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
Tyler Ball 提交于 2019-04-05 05:02 +08:00 . update limits.py and test
import shopify
class Limits(object):
"""
API Calls Limit
https://help.shopify.com/en/api/getting-started/api-call-limit
Conversion of lib/shopify_api/limits.rb
"""
# num_requests_executed/max_requests
# Eg: 1/40
CREDIT_LIMIT_HEADER_PARAM = 'X-Shopify-Shop-Api-Call-Limit'
@classmethod
def response(cls):
if not shopify.Shop.connection.response:
shopify.Shop.current()
return shopify.Shop.connection.response
@classmethod
def api_credit_limit_param(cls):
response = cls.response()
_safe_header = getattr(response, "headers", '')
if not _safe_header:
raise Exception("No shopify headers found")
if cls.CREDIT_LIMIT_HEADER_PARAM in response.headers:
credits = response.headers[cls.CREDIT_LIMIT_HEADER_PARAM]
return credits.split('/')
else:
raise Exception("No valid api call header found")
@classmethod
def credit_left(cls):
"""
How many more API calls can I make?
"""
return int(cls.credit_limit() - cls.credit_used())
@classmethod
def credit_maxed(cls):
"""
Have I reached my API call limit?
"""
return bool(cls.credit_left() <= 0)
@classmethod
def credit_limit(cls):
"""
How many total API calls can I make?
"""
return int(cls.api_credit_limit_param()[1])
@classmethod
def credit_used(cls):
"""
How many API calls have I made?
"""
return int(cls.api_credit_limit_param()[0])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen_guo_hong/shopify_python_api.git
git@gitee.com:chen_guo_hong/shopify_python_api.git
chen_guo_hong
shopify_python_api
shopify_python_api
master

搜索帮助