ziptastic / fluent
基于Guzzle的Ziptastic Lookup API的PHP SDK
v2.1.0
2017-02-08 02:20 UTC
Requires
- php: >=5.4
Requires (Dev)
- guzzlehttp/guzzle: >=4.0
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-08-29 04:28:32 UTC
README
这个库是基于Guzzle的Ziptastic API接口。
使用Ziptastic需要API密钥,您可以通过注册Ziptastic来获取一个。
安装
可以通过composer安装Ziptastic PHP
composer require ziptastic/fluent
使用方法
有两种不同的方法可以使用此包,但结果相同。
使用此包的第一种方法是使用Zipper,这将使用更偏向“简单英语”的语法
<?php include "vendor/autoload.php"; use Ziptastic\Fluent\Zipper; $key = 'Your Api Key from ziptastic'; $results = (new Zipper)->in('US')->withPostalCode(48867)->andWithKey($key)->find(); echo $results->response; ?>
如果这不是您喜欢的口味,或者您只是想完成任务,您可以使用Ziptastic
<?php include "vendor/autoload.php"; use Ziptastic\Fluent\Ziptastic; $key = 'Your Api Key from ziptastic'; $results = (new Ziptastic(23042,'us'))->setKey($key)->find(); echo $results->response; ?>
使用结果
如果您想的话,您可以通过调用API响应中的项目来访问任何API调用的结果。使用Zipper是使用此包的第一种方法,它将使用更偏向“简单英语”的语法
<?php include "vendor/autoload.php"; use Ziptastic\Fluent\Zipper; $key = 'Your Api Key from ziptastic'; $results = (new Zipper)->in('US')->withPostalCode(48867)->andWithKey($key)->find(); echo $results->city, ', ',$results->state,' ',$results->postal_code; ?>
在示例中,默认设置的只有一个邮编,其他都是从响应中获取的。
Ziptastic PHP遵循MIT许可证。