定制 mbagnall/gov-info 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mbagnall/gov-info

Composer 安装命令:

composer require mbagnall/gov-info

包简介

A fork for a library for using api.govinfo.gov. Compatible with Drupal 9 until it can use console 5

README 文档

README

 _______  _______            _________ _        _______  _______ 
(  ____ \(  ___  )|\     /|  \__   __/( (    /|(  ____ \(  ___  )
| (    \/| (   ) || )   ( |     ) (   |  \  ( || (    \/| (   ) |
| |      | |   | || |   | |     | |   |   \ | || (__    | |   | |
| | ____ | |   | |( (   ) )     | |   | (\ \) ||  __)   | |   | |
| | \_  )| |   | | \ \_/ /      | |   | | \   || (      | |   | |
| (___) || (___) |  \   /    ___) (___| )  \  || )      | (___) |
(_______)(_______)   \_/     \_______/|/    )_)|/       (_______)
                                                                 

CircleCI Maintainability Test Coverage Software License

This alpha stage package provides a very simple way to access api.govinfo.gov

See console demo

Install

You can install this package via composer.

composer require cnizzardini/gov-info

Usage

Retrieve an index of all collections available

use GovInfo\Api;
use GovInfo\Collection;

$api = new Api(
    new \GuzzleHttp\Client(), 
    'DEMO_KEY'
);
$collection = new Collection($api);
$result = $collection->index();

After running this code $result will contain a non-truncated version of collections:

Array
(
    [collections] => Array
        [
            [0] => Array
                [
                    [collectionCode] => USCOURTS
                    [collectionName] => United States Courts Opinions
                    [packageCount] => 1134933
                    [granuleCount] => 2525240
                ]
        ...
)

Retrieve all packages in a collection

use GovInfo\Api;
use GovInfo\Collection;
use GovInfo\Requestor\CollectionAbstractRequestor;

$api = new Api(
    new \GuzzleHttp\Client(), 
    'DEMO_KEY'
);
$collection = new Collection($api);
$requestor = new CollectionAbstractRequestor();

$requestor
    ->setStrCollectionCode('BILLS')
    ->setObjStartDate(new DateTime('2019-01-01'));

$result = $collection->item($requestor);

After running this code $result will contain a non-truncated version of packages:

Array
(
    [count] => 202767
    [message] => 
    [nextPage] => https://api.govinfo.gov/collections/BILLS/2018-01-01T00:00:00Z/?offset=100&pageSize=100
    [previousPage] => 
    [packages] => Array
        [
            [0] => Array
                [
                    [packageId] => BILLS-115hr2740rfs
                    [lastModified] => 2018-11-16T00:33:17Z
                    [packageLink] => https://api.govinfo.gov/packages/BILLS-115hr2740rfs/summary
                    [docClass] => hr
                    [title] => Rabbi Michoel Ber Weissmandl Congressional Gold Medal Act of 2017
                ]
        ...

Retrieve a specific package in a collection.

use GovInfo\Api;
use GovInfo\Collection;
use GovInfo\Requestor\CollectionAbstractRequestor;

$api = new Api(
    new \GuzzleHttp\Client(), 
    'DEMO_KEY'
);
$collection = new Collection($api);
$requestor = new CollectionAbstractRequestor();

$requestor
    ->setStrCollectionCode('BILLS')
    ->setObjStartDate(new \DateTime('2018-01-01 12:00:00'))
    ->setObjEndDate(new \DateTime('2018-02-01 12:00:00'))
    ->setStrDocClass('hr')
    ->setStrPackageId('BILLS-115hr4033rfs')
    ->setStrTitle('Geologic Mapping Act');

$result = $collection->item($requestor);

After running this code $result will contain the requested package

Array
(
    [count] => 202767
    [message] => 
    [nextPage] => https://api.govinfo.gov/collections/BILLS/2018-01-01T00:00:00Z/?offset=100&pageSize=100
    [previousPage] => 
    [packages] => Array
        [
            [2] => Array
                [
                    [packageId] => BILLS-115hr4033rfs
                    [lastModified] => 2018-11-16T00:33:00Z
                    [packageLink] => https://api.govinfo.gov/packages/BILLS-115hr4033rfs/summary
                    [docClass] => hr
                    [title] => National Geologic Mapping Act Reauthorization Act
                ]
        ]
)

Retrieve a summary of a package.

use GovInfo\Package;
use GovInfo\Requestor\PackageAbstractRequestor;

$package = new Package($api);
$requestor = new PackageAbstractRequestor();

$result = $package->summary($requestor->setStrPackageId('BILLS-115hr4033rfs'));

After running this code $result will contain a non-truncated version of the package summary

Array
(
    [title] => An Act To reauthorize the National Geologic Mapping Act of 1992.
    [shortTitle] => Array
        [
            [0] => Array
                [
                    [type] => measure
                    [title] => National Geologic Mapping Act Reauthorization Act
                ]

        ]
    ...

Retrieve a package as a specified content-type

use GovInfo\Package;
use GovInfo\Requestor\PackageAbstractRequestor;

$package = new Package($api);
$requestor = new PackageAbstractRequestor();
$requestor
    ->setStrPackageId('BILLS-115hr4033rfs')
    ->setStrContentType('xml');

$result = $package->contentType($requestor);

After running this code $result will be an instance of GuzzleHttp\Psr7\Response

For additional usage examples, please look at src/Console and tests.

Console

There is a minimalist console application that can be used, but its not designed for production use. I built this so I could easily regression test the library against the production API. Each command will prompt you for an API key. To avoid this prompt you can create a local apiKey.txt file with your API key in there.

Example

# displays collections
php console.php collection:index

# display packages for a given collection 
php console.php collection:packages

# writes to csv file
php console.php collection:packages --file

# writes to csv file in a specific folder
php console.php collection:packages --file --path=/home/username/Desktop

# retrieves a package summary as a GuzzleHttp\Psr7\Response instance
php console.php package:summary

# retrieves a package summary and writes to file
php console.php package:summary --file

# writes to file in a specific folder
php console.php collection:packages --file --path=/home/username/Desktop

Testing

vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

mbagnall/gov-info 适用场景与选型建议

mbagnall/gov-info 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「gov」 「govinfo」 「govinfo.gov」 「api.govinfo.gov」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mbagnall/gov-info 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mbagnall/gov-info 我们能提供哪些服务?
定制开发 / 二次开发

基于 mbagnall/gov-info 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 52
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-20