posti智能船api

smartship的Python项目详细描述


与posti smartship/unifaun在线api交互的python库。

待办事项

  • 文档
  • 根据架构实现装运中的剩余属性
  • 必要时添加日志记录

兼容性

  • python 2.7+或python 3.4+

用法

创建发货

此API支持用于创建装运和 然后下载生成的pdf文件。

载波

像posti这样的某些运营商有一些方法可以覆盖更常见的用途 案例。为邮政承运人创建装运,例如:

fromsmartship.carriers.postiimportcreate_shipmentreceiver={"name":"Anders Innovations","city":"Helsinki","country":"FI","address1":"Iso Roobertinkatu 20-22","zipcode":"00120"}sender={"quickId":"1",}agent={"quickId":"2",}shipment=create_shipment("12345",# Posti customer number"PO2102",# Service IDreceiver,sender,[{"copies":1}],# Parcelsagent=agent,# Optional pickup pointpdf_config=pdf_config,# Optional custom PDF config)

请参阅smartship.carriers.posti模块中的更多文档。

pdf配置

如果要传递自定义pdf_config,它应该具有以下结构:

{"target1Media":"laser-a5","target1YOffset":0,"target1XOffset":0}

使用"target1Media"作为以下选项之一:

"laser-a5"
"laser-2a5"
"laser-ste"
"thermo-se"
"thermo-225"

您可以使用"target1YOffset""target1XOffset"参数自定义偏移量。

客户

要发送装运和使用其他api资源,您需要一个客户机。 使用用户名和密钥令牌初始化客户机,如下所示。创建 您在Unifaun Online portal中的api标记。

fromsmartshipimportClientclient=Client("username","secret")

发送货物

按如下方式发送货物:

response=client.send_shipment(shipment)

响应将是一个特殊的ShipmentResponse对象,用响应代码和 json内容在response.data中。

状态代码:

  • 201-发货创建正常
  • 422-数据验证错误。引发一个ShipmentResponseError

有关错误,请参阅error.response.json(),以获取unifaun online api的详细信息。

装运地址PDF表

一旦得到响应,请按如下方式检索相关的PDF数据:

data=response.get_pdfs(client)# Client needed in case of additional fetchingpdf_data=data[0][0]# Simplest case with a single shipment with a single parcel

药剂

按如下方式检索代理列表(取件点):

agents=client.get_agents("FI","ITELLASP","Iso Roobertinkatu 20-22","00120")

响应将是一个Agents对象,可以对单个代理数据进行迭代。

位置

由于上述代理方法是付费服务,我们还提供了一个到posti位置服务api的接口。

fromsmartship.carriers.postiimportget_locationslocations=get_locations(country_code="FI",zipcode="00120")

响应将是一个Locations对象,可以对单个位置数据进行迭代。

高级使用

有关完整的属性列表,请参见完整的Smartship API documentation 可以发货。当使用 smartship.shipments.Shipment直接。导入相关对象 从smartship.objects将它们传递给Shipment对象。

开发

要求

使用以下命令将需求安装到虚拟环境中:

pip install -U setuptools pip  # These should be up to date
pip install -r requirements-dev.txt

测试

要在当前虚拟环境中进行测试,请运行:

py.test

要检查编码样式,请运行:

flake8

要测试所有支持的环境,请运行:

tox

建筑文档

制作文档时使用:

sphinx-build -b html docs docs/_build

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring引导类NotFoundException EmbeddedServletContainerCustomizer   java osgi安全模型是如何工作的?   java在双链表中迭代?   (JAVA)使用命令提示符创建。来自多个服务器的jar文件。类文件   Java处理在使用线程时不显示内容   java不休眠SessionFactory。openSession()等待数据库连接从池中可用   MySQL Java Bukkit插件从数据库中选择   java如何使用CharSequence   java如何在Spring MVC REST中为JSON设置contentlength?   java在现有SOAP web服务上构建REST包装器   java Vertx NetServer控制读取流   Linux下的C++全局java语言   java我可以使用数组。用2d数组填充?如果是,我该怎么做?   java如何在google应用程序引擎的日志中显示UTF8字符?