用于与Arcgis GeoTrigger API交互的简单客户端库。

geotrigger-python的Python项目详细描述


用于与arcgis交互的简单python客户端库 通过GeotriggerClient对象的GeoTrigger服务。

GeoTrigger服务是一个云托管的地理围栏平台,它 当设备发生故障时发送推送通知或通知远程服务器 进入或退出一个区域。

geotrigger api管理应用程序和设备信息,并 权限,以及提供创建、更新和列表的访问权限 有关触发器、标记和设备位置的信息。

有关详细信息,请参阅Geotrigger Service Documentation

功能

  • 处理凭据的身份验证和刷新
  • 支持作为应用程序发出请求,允许 设备、触发器、标记和权限的管理
  • 还支持作为设备发出请求,这对于 测试目的

依赖关系

  • 请求(>;=2.1.0)

运行测试时,您还需要:

  • 模拟(>;=1.0.1)

安装

可以使用以下命令从pypi安装geotrigger-python。 命令:

pip install geotrigger-python

也可以通过运行 setup.py installsetup.py develop

示例

将geotriggerclient用作应用程序

这种使用geotriggerclient的方法是用于服务器端应用程序,其作用如下 您的arcgis应用程序的唯一所有者。

在继续之前,您需要找到client_idclient_secret用于ArcGIS for Developers站点上的arcgis应用程序。 您可以在应用程序的api access部分找到它们 细节。

请确保您的客户安全。如果第三个 一方获得你的客户机密,他们将可以做任何事情 想要你的GeoTrigger应用程序。您的client_secret只应 包含在服务器端应用程序中,不应分发 作为客户端web或移动应用程序的一部分。

您需要为中给定的变量名填写值 所有的帽子。

fromgeotriggerimportGeotriggerClient# Create a GeotriggerClient as an Applicationgt=GeotriggerClient(CLIENT_ID,CLIENT_SECRET)# Fetch a list of all triggers in this application.triggers=gt.request('trigger/list')# Print all the triggers and any tags applied to them.print"\nFound %d triggers:"%len(triggers['triggers'])fortintriggers['triggers']:print"- %s (%s)"%(t['triggerId'],",".join(t['tags']))# Add "testing123" tag to all of the triggers that we fetched above.triggers_updated=gt.request('trigger/update',{'triggerIds':[t['triggerId']fortintriggers['triggers']],'addTags':TAG})# Print the updated triggers.print"\nUpdated %d triggers:"%len(triggers_updated['triggers'])fortintriggers_updated['triggers']:print"- %s (%s)"%(t['triggerId'],",".join(t['tags']))# Delete the "testing123" tag from the application.tags_deleted=gt.request('tag/delete',{'tags':TAG})print'\nDeleted tags: "%s"'%", ".join(tags_deleted.keys())

将geotriggerclient用作设备

也可以将GeotriggerClient用作一个设备,它 将允许您发送位置更新和触发,但您将 无法接收任何GeoTrigger通知,因为它们作为 将消息推送到实际的移动设备。你可以使用 trigger/history 使用callbackUrl路由或配置触发器,以便 注意触发器正在被触发。

您只需要应用程序的client_id就可以使用 作为设备的GeotriggerClient

对于测试回调触发器,可以使用 RequestBin服务。创建一个新的垃圾箱并 创建触发器时,将其url作为callbackUrl提供。

您需要为中给定的变量名填写值 所有的帽子。

fromgeotriggerimportGeotriggerClient# Create a GeotriggerClient as a devicegt=GeotriggerClient(CLIENT_ID)# Default tags are created for all devices and triggers. Device default tags# can be used when you want to allow devices to create triggers that only they# can fire. Default tags look like: 'device:device_id' or 'trigger:trigger_id'device_tag='device:%s'%gt.session.device_id# Build a callback trigger, using your default tag and RequestBin URL.esri_hq={'condition':{'geo':{'latitude':34.0562,'longitude':-117.1956,'distance':100},'direction':'enter'},'action':{'callbackUrl':CALLBACK_URL},'setTags':device_tag}# Post the trigger to the Geotrigger APItrigger=gt.request('trigger/create',esri_hq)printtrigger# Construct a fake location update to send to the Geotrigger API.# Supplying a previous location is not strictly required, but will speed up# trigger processing by avoiding a database lookup.location_update={'previous':{'timestamp':datetime.now().isoformat(),'latitude':45.5165,'longitude':-122.6764,'accuracy':5,},'locations':[{'timestamp':datetime.now().isoformat(),'latitude':34.0562,'longitude':-117.1956,'accuracy':5,}]}# Send the location update.update_response=gt.request('location/update',location_update)printupdate_response

运行上述代码后不久,您将看到 回调URL。

高级geotriggerclient用法

如果您已经有了arcgis应用程序access_token,那么 要使用创建GeotriggerClient,请传入 GeotriggerApplication作为sessionkwarg。如果你想这样做 您正在将geotrigger功能集成到一个应用程序中 已从Arcgis Online获取凭据。

类似地,如果您想模拟一个现有的设备 已经有一个client_iddevice_idaccess_token,和 refresh_token,您可以创建自己的GeotriggerDevice来传递 进入GeotriggerClient。这可用于调试 正在为Android和iOS开发GeoTrigger SDK。

fromgeotriggerimportGeotriggerClient,GeotriggerApplication,GeotriggerDeviceapp=GeotriggerApplication(CLIENT_ID,CLIENT_SECRET,ACCESS_TOKEN)app_client=GeotriggerClient(session=app)device=GeotriggerDevice(CLIENT_ID,DEVICE_ID,ACCESS_TOKEN,REFRESH_TOKEN)device_client=GeotriggerClient(session=device)

问题

找到一个bug或者想要请求一个新特性?请通过提交问题通知我们。

贡献

ESRI欢迎任何人和所有人的贡献。请看我们的guidelines for contributing

许可证

2013 ESRI版权所有

根据apache许可证2.0版(以下简称“许可证”)授权; 除非符合许可证,否则您不能使用此文件。 您可以在

http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则软件 根据许可证分发是按“原样”分发的, 无任何明示或默示的保证或条件。 有关管理权限的特定语言和 许可下的限制。

许可证文件中提供了许可证的副本。

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

推荐PyPI第三方库


热门话题
html如何在JavaScript中获取当前Windows用户的名称   用于屏蔽电子邮件的java正则表达式   java Jsoup Android解析   为了避免在运行时缺少Java泛型,将超类型绑定到子类实例   java JTextArea。setText(空);不会释放内存   安卓源Java OutOfMemoryError在构建AOSP 10时出错   java打印到达数组末尾所需的最小跳数序列   使用mvn命令的java Selenium TestNG并行执行   javasocket编程:在关闭服务器之前通知所有客户端   java如何在加载新的安卓片段时显示progressbar?   java从actor系统中删除AKKA actor,并创建另一个具有相同路径名的actor   java我可以用浓缩咖啡做性能测试,还是应该用其他东西?   JavaTreeView(TreeItem)是否可以获取层次结构索引?   带远程服务的java Android应用程序