brego / feedbin-opml-export
将Feedbin订阅转换为OPML文件,可以在您的网站上发布
dev-master
2019-11-06 21:43 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-07 07:52:39 UTC
README
使用Feedbin API,获取并转换您的Feedbin订阅到OPML文件,可以在您的网站上发布。
此库旨在定期发布您的个人订阅列表 - 没有内置的缓存机制,但请在自己的端实现它。没有理由滥用API服务器资源。
用法
使用您的Feedbin凭据构建一个Brego\FeedbinOpmlExport\Curl
对象,将其传递给Brego\FeedbinOpmlExport\Feedbin
,并运行fetchAndConvertToOpml
以获取一个Brego\FeedbinOpmlExport\Opml\Document
实例,您可以对其进行操作、保存为OPML文件或直接输出。
以下示例也位于examples
目录中
简单示例
use Brego\FeedbinOpmlExport\CurlFake; use Brego\FeedbinOpmlExport\Feedbin; /** * Your user and password for Feedbin. */ $user = 'your-feedbin@account.user'; $password = 'your-feedbin-password'; /** * CurlFake is a stub Used for testing, so we don't call the live API all of the time. It uses json * files found in `/json-examples/`. * * Use Brego\FeedbinOpmlExport\Curl to call the API. */ $curl = new CurlFake($user, $password); $feedbin = new Feedbin($curl); /** * This shortcut method fetches subscriptions, taggings, and convert those to an OPML document * containing subscriptions and categories. See example-full.php for more controll. */ $document = $feedbin->fetchAndConvertToOpml('RSS subscriptions for John Doe', 'johndoe@exemple.com'); echo $document;
完整示例
use Brego\FeedbinOpmlExport\CurlFake; use Brego\FeedbinOpmlExport\Feedbin; use Brego\FeedbinOpmlExport\Opml\Document; use Brego\FeedbinOpmlExport\Opml\Element; use Brego\FeedbinOpmlExport\Opml\Outlines; /** * Your user and password for Feedbin. */ $user = 'your-feedbin@account.user'; $password = 'your-feedbin-password'; /** * CurlFake is a stub Used for testing, so we don't call the live API all of the time. It uses json * files found in `/json-examples/`. * * Use Brego\FeedbinOpmlExport\Curl to call the API. */ $curl = new CurlFake($user, $password); $feedbin = new Feedbin($curl); /** * The Feedbin class provides interfaces to fetch Subscriptions and Taggings, and make categories * out of those. This is usefull if you need to manipulate those in any way before converting to * OPML. */ $subscriptions = $feedbin->fetchSubscriptions(); $taggings = $feedbin->fetchTaggings(); $categories = $feedbin->makeCategories($subscriptions, $taggings); $document = (new Document()) ->head( function(Element $head) { $head ->addAttribute('title', 'RSS subscriptions for John Doe') ->addAttribute('ownerEmail', 'johndoe@exemple.com') ->addAttribute('dateUpdated', (new DateTime())->format(DateTime::RFC822)); } ) ->body( function(Element $body) use ($subscriptions, $categories) { $body ->addChildren(Outlines::from($subscriptions)) ->addChildren(Outlines::from($categories)); } ); /** * `flatten()` shown here can be useful if you want to save the OPML document to a file. */ echo $document->flatten();