imo-tikuwa / resas-api-client
v0.2.4
2020-06-08 23:41 UTC
Requires
- php: >=5.4.0
- vlucas/phpdotenv: 4.1
Requires (Dev)
- monolog/monolog: ^1.25
This package is auto-updated.
Last update: 2024-09-09 09:09:20 UTC
README
这是对地域经济分析系统(RESAS:リーサス)的数据进行API封装的客户端程序。
只要php5.4以上应该都可以运行。
※使用时需要RESAS的API密钥。
安装
composer require imo-tikuwa/resas-api-client
用法
- 请通过ResasApiClient的构造函数提供API密钥。
- 使用find函数设置使用的API的操作和必要的参数。
- 以下方法之一获取数据
关于.env
创建以下环境变量可以在调用ResasApiClient构造函数时省略API密钥的传递。
ENV_RESAS_API_KEY="[API キー]"
示例代码
以下是从东京都获取市区町村的程序。
require_once (dirname(__DIR__) . "/vendor/autoload.php");
use TikuwaApp\Api\ResasApiClient;
$api_key = '[API キー]';
$resas_api_client = new ResasApiClient($api_key);
$result = $resas_api_client->find('api/v1/cities', ['prefCode' => '13'])->toArray();
以下是从东京都的市区町村中筛选出与“〇〇区”匹配的自治体,并以键值对数组的形式获取的程序。
require_once (dirname(__DIR__) . "/vendor/autoload.php");
use TikuwaApp\Api\ResasApiClient;
$resas_api_client = new ResasApiClient();
$result = $resas_api_client->find('api/v1/cities', ['prefCode' => '13'])
->setKeyValuePath("{n}[cityName=/^.+区$/].cityCode", "{n}[cityName=/^.+区$/].cityName")
->toArray();
以下是从都道府县代码值15以下的数据中,以键值对数组的形式获取并输出到文件的程序。
require_once (dirname(__DIR__) . "/vendor/autoload.php");
use TikuwaApp\Api\ResasApiClient;
$date = new DateTime();
$date->setTimezone(new DateTimeZone('Asia/Tokyo'));
$filename = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . basename(__FILE__, ".php") . '_' . $date->format('YmdHis') . '.php';
(new ResasApiClient())->find('api/v1/prefectures')
->setKeyValuePath("{n}[prefCode<=15].prefCode", "{n}[prefCode<=15].prefName")
->toExport($filename);
链接
RESAS-API - 地域经济分析系统(RESAS)的API提供信息
RESAS-API - API概要
许可
在源代码中使用了cakephp/utility的程序的一部分。