codelinefi / mac-lookup
macaddress.io API 的 PHP 客户端库。
1.0.0
2018-09-20 08:36 UTC
Requires
- php: ^5.5 || ^7.0
- guzzlehttp/guzzle: ~6.0
- nesbot/carbon: ~1.18
Requires (Dev)
- phpunit/php-code-coverage: ^6.0
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-09-29 05:42:10 UTC
README
由 macaddress.io 提供的 MAC 供应商查找 API 的 PHP 库
安装
您可以通过 Composer 安装此库
composer require codelinefi/mac-lookup
要使用此库,请使用 Composer 的 自动加载
require_once('vendor/autoload');
需求
支持的 PHP 版本
- PHP 5.5.x
- PHP 5.6.x
- PHP 7.0.x
- PHP 7.1.x
- PHP 7.2.x
依赖项
- mbstring
- mbregex
- json
- curl
文档
完整的 API 文档可在 此处 查看
入门
基本用法
<?php use CodeLine\MacLookup\Builders\ClientBuilder; $builder = new ClientBuilder(); $client = $builder->build('Your API key'); echo $client->get('F041C81')->blockDetails->dateUpdated . PHP_EOL; echo $client->getRawData('18810E') . PHP_EOL; echo $client->getVendorName('F041C81') . PHP_EOL;
高级用法
<?php use CodeLine\MacLookup\Builders\ResponseModelBuilder; use CodeLine\MacLookup\Clients\GuzzleClient; use CodeLine\MacLookup\ApiClient; use \GuzzleHttp\Client; $requestor = new GuzzleClient(new Client()); $builder = new ResponseModelBuilder(''); $client = new ApiClient($requestor, $builder, 'Your API key'); echo $client->get('18810E')->vendorDetails->companyName . PHP_EOL; echo $client->getRawData('18810E') . PHP_EOL; echo $client->getVendorName('18810E') . PHP_EOL;
请注意!此库使用 trigger_error 函数与 E_USER_DEPRECATED 常量来通知您关于 API 的更新
示例
您可以在示例目录中找到一些示例。要运行这些示例,请执行以下命令
export API_KEY="<Your api key>" php vendor.php php basic.php
类
ApiClient 类
/** * ApiClient constructor. * @param \CodeLine\MacLookup\Clients\ClientInterface $client * @param \CodeLine\MacLookup\Builders\ResponseModelBuilderInterface $builder * @param string $apiKey Your API key * @param string $url API base URl */ public function __construct( ClientInterface $client, ResponseModelBuilderInterface $builder, $apiKey, $url = "" ) /** * @param string $url API base URl */ public function setBaseUrl($url); /** * @param string $apiKey Your API key */ public function setApiKey($apiKey); /** * @param string $mac Mac address or OUI * @return \CodeLine\MacLookup\Models\Response * @throws EmptyResponseException * @throws ServerErrorException * @throws UnknownOutputFormatException * @throws AuthorizationRequiredException * @throws NotEnoughCreditsException * @throws AccessDeniedException * @throws InvalidMacOrOUIException */ public function get($mac); /** * @param string $mac Mac address or OUI * @param string $format Supported formats json/xml/csv/vendor * @return string * @throws EmptyResponseException * @throws ServerErrorException * @throws UnknownOutputFormatException * @throws AuthorizationRequiredException * @throws NotEnoughCreditsException * @throws AccessDeniedException * @throws InvalidMacOrOUIException */ public function getRawData($mac, $format = 'json'); /** * @param string $mac Mac address or OUI * @return string * @throws ServerErrorException * @throws UnknownOutputFormatException * @throws AuthorizationRequiredException * @throws NotEnoughCreditsException * @throws AccessDeniedException * @throws InvalidMacOrOUIException */ public function getVendorName($mac);
模型
namespace CodeLine\MacLookup\Models
响应
/** * @var VendorDetails */ public $vendorDetails; /** * @var BlockDetails */ public $blockDetails; /** * @var MacAddressDetails */ public $macAddressDetails;
VendorDetails
/** * @var string */ public $oui; /** * @var boolean */ public $isPrivate; /** * @var string */ public $companyName; /** * @var string */ public $companyAddress; /** * @var string */ public $countryCode;
BlockDetails
/** * @var boolean */ public $blockFound; /** * @var string */ public $borderLeft; /** * @var string */ public $borderRight; /** * @var int|float */ public $blockSize; /** * @var string */ public $assignmentBlockSize; /** * @var \DateTimeInterface */ public $dateCreated; /** * @var \DateTimeInterface */ public $dateUpdated;
MacAddressDetails
/** * @var string */ public $searchTerm; /** * @var boolean */ public $isValid; /** * @var string */ public $transmissionType; /** * @var string */ public $administrationType;
ClientBuilder
namespace \CodeLine\MacLookup\Builders
/** * @param string $apiKey * @param string $url * @return \CodeLine\MacLookup\ApiClient */ public function build($apiKey, $url = '');
开发
从仓库克隆代码
git clone https://github.com/CodeLineFi/maclookup-php.git
安装依赖项
composer install
运行测试
./vendor/bin/phpunit --testdox tests