embed.ly API 库

1.1.0 2015-02-04 11:20 UTC

This package is auto-updated.

Last update: 2024-08-28 06:32:21 UTC


README

Build Status SensioLabs Insight Coverage Status Scrutinizer Code Quality Total Downloads

基于 embed.ly APIs 的库,采用 Guzzle 5

API: emanueleminotto.github.io/Embedly

安装

emanueleminotto/embedly 添加到您的 composer.json 或通过 CLI 安装 Embedly 库

$ composer require emanueleminotto/embedly

有关 Composer 安装的更多信息,请参阅: getcomposer.org/doc/00-intro.md

使用方法

此库提供 3 个 API: embed.ly/docs/api

某些 API 需要一个 API 密钥,您可以在构造函数中设置或使用 setApiKey 方法。构造函数的第二个参数可以是一个 Guzzle HTTP 客户端,用作默认客户端的替代。

嵌入

选项可在 http://embed.ly/docs/api/embed/arguments 中找到

对于此方法,$api_key 可以是 null。

use EmanueleMinotto\Embedly\Client;

$client = new Client($api_key);

$embed = $client->oembed([
    'url' => 'http://www.example.com/',
]);

// enumerated array containing
// arrays like $embed
$embeds = $client->oembed([
    'urls' => [
        'http://www.example.com/',
        'http://www.google.com/'
    ]
]);

提取

选项可在 http://embed.ly/docs/api/embed/arguments 中找到

use EmanueleMinotto\Embedly\Client;

$client = new Client($api_key);

$extracted = $client->extract([
    'url' => 'http://www.example.com/',
]);

// enumerated array containing
// arrays like $extracted
$extracteds = $client->oembed([
    'urls' => [
        'http://www.example.com/',
        'http://www.google.com/'
    ]
]);

显示

第一个参数可以是 NULLcropresizefill

选项可在以下位置找到:

目前需要 url 属性。

use EmanueleMinotto\Embedly\Client;

$client = new Client($api_key);

$content = $client->display('resize', [
    'url' => 'http://placehold.it/250x100',
    'color' => '000',
    'height' => 150,
    'width' => 150,
]);

Twig 扩展

此库包含一个 Twig 扩展,以允许与框架简单集成。

函数前缀是: embedly_,参数与上述方法相同。

{{ embedly_oembed({url: 'http://www.example.com'}).title }} {# Example Domain #}