seanmcn/php-represent

PHP 库,用于 http://represent.opennorth.ca/

v2.0 2021-12-12 11:57 UTC

This package is auto-updated.

Last update: 2024-09-12 17:49:20 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

PHP 库,用于 http://represent.opennorth.ca/

查找任何加拿大地址或邮政编码的选举官员和选举区,涵盖各级政府

安装

使用 composer 安装

"require": {
  "seanmcn/php-represent": "1.*"
}

或者您可以下载该软件包并自行加载。

示例用法

$represent = new PHPRepresent\API();
$represent->getAll('boundaries', ['sets' => ['toronto-wards', 'ottawa-wards']]);

API 文档

库文档

get($path, $params, $throttle);

从提供的 API 路径和参数中返回单个结果或一页结果。

参数:

  • $path - 您请求的 API 路径。
  • $params - 要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。
  • $throttle - 默认 TRUE。选项忽略 API 速率限制。

示例用法

$represent = new PHPRepresent\API();
$path = 'boundaries';
$params = ['sets' => ['toronto-wards', 'ottawa-wards']];
$represent->get($path, $params);

getAll($path, $params);

从提供的 API 路径和参数中返回所有结果。

参数:

  • $path - 您请求的 API 路径。
  • $params - 要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。

示例用法

$represent = new PHPRepresent\API();
$path = 'boundaries';
$params = ['sets' => 'toronto-wards,ottawa-wards'];
$represent->getAll($path, $params);

postcode($postcode);

通过邮政编码查找代表和边界。

参数:

  • $postcode - 要查找代表和边界的邮政编码。

示例用法

$represent = new PHPRepresent\API();
$represent->postcode('L5G4L3');

boundarySets($name, $params);

返回边界集合,例如 BC 省级选区或多伦多选区。

参数:

  • $name - 可选,如果提供,将返回单个边界集合。
  • $params - 要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。

示例用法

$represent = new PHPRepresent\API();
$represent->boundarySets();

boundaries($boundarySet, $name, $representatives, $params)

返回选举区的边界,可以提供一个集合,如 toronto-wards 以返回单个集合的边界。

所有参数都是可选的,但是 $name 需要您提供 $boundarySet,而 $representatives 需要您提供 $boundarySet$name

参数:

  • $boundarySet - 可选,如果提供,则返回单个边界集合的边界。
  • $name - 可选,如果提供,将返回单个边界。
  • $representatives - 可选,如果提供,将返回边界的代表。
  • $params - 可选,要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。

示例用法

$represent = new PHPRepresent\API();
// One Set
$represent->boundaries('toronto-wards');
// Multiple Sets
$represent->boundaries(null, null, false,  ['sets' => ['toronto-wards', 'ottawa-wards']]);

representativeSets($set);

返回所有或单个代表集合。

代表集合是一组当选官员,如众议院或多伦多市议会。

参数:

  • $set - 可选,如果提供,将返回单个代表集合。

示例用法

$represent = new PHPRepresent\API();
$represent->representativeSets('north-dumfries-township-council');

representatives($set, $params);

返回代表名单。

参数:

  • $set - 可选,如果提供,将返回单个集合的代表。
  • $params - 可选,要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。

示例用法

$represent = new PHPRepresent\API();
$represent->representatives('house-of-commons');

elections($election);

返回选举名单或单个选举。

目前没有数据,所以我不确定这是否正常工作。

参数:

  • $election - 可选,如果提供,将返回基于提供的 ID 的单个选举。

示例用法

$represent = new PHPRepresent\API();
$represent->elections();

candidates($election, $params);

返回所有选举的候选人名单或单个选举的所有候选人名单。

目前没有数据,所以我不确定这是否正常工作。

参数:

  • $election - 可选,如果提供,将返回单个选举的候选人。
  • $params - 可选,要附加到请求中的 $_GET 变量。允许通过数组或逗号分隔为每个键提供多个值。

示例用法

$represent = new PHPRepresent\API();
$represent->candidates();

setInsecure();

可以选择禁用HTTPS,例如在测试时遇到证书问题。

注意:你实际上不应该在生产环境中使用这个选项。

示例用法

$represent = new PHPRepresent\API();
$represent->setInsecure();
$represent->boundaries('toronto-wards');

setRateLimit($limit);

可以选择设置每分钟的速率限制(请求数量)。默认速率限制为每分钟60个请求。

注意:除非你已与Open North协商同意更高的速率限制,否则你将收到HTTP 503错误。

示例用法

$represent = new PHPRepresent\API();
$represent->setRateLimit(42);
$represent->boundaries('ottawa-wards');