nodrew/embedly-bundle

此包已被废弃,不再维护。未建议替代包。
此包最新版本(dev-master)没有可用的许可证信息。

Symfony2 Bundle,用于与Embedly服务协同工作

维护者

详细信息

github.com/nodrew/NodrewEmbedlyBundle

安装: 79

依赖者: 0

建议者: 0

安全: 0

星标: 9

关注者: 1

分支: 4

类型:symfony-bundle

dev-master 2012-12-20 14:58 UTC

This package is not auto-updated.

Last update: 2019-02-20 17:14:07 UTC


README

用于与http://www.embedly.com上的Embedly服务协同

支持的API

  • oEmbed: 完整
  • Preview: 几乎完整 - 模型响应结构可能发生变化。
  • Objectify: 几乎完整 - 模型响应结构可能发生变化。

注意:Preview和Objectify端点需要付费账户才能使用。如果你尝试使用免费账户从这些服务中获取数据,将返回错误,并抛出LogicException异常。

安装说明

  1. 下载NodrewEmbedlyBundle
  2. 配置自动加载器
  3. 启用Bundle
  4. 添加您的Embedly提供者密钥

第1步:下载NodrewEmbedlyBundle

最终,NodrewEmbedlyBundle文件应该下载到vendor/bundles/Nodrew/Bundle/EmbedlyBundle目录。

这可以通过多种方式完成,具体取决于您的偏好。第一种方法是标准的Symfony2方法。

使用供应商脚本

在您的deps文件中添加以下行

[NodrewEmbedlyBundle]
    git=http://github.com/nodrew/NodrewEmbedlyBundle.git
    target=/bundles/Nodrew/Bundle/EmbedlyBundle

现在,运行供应商脚本来下载Bundle

$ php bin/vendors install

使用子模块

如果您更愿意使用git子模块,请运行以下命令

$ git submodule add http://github.com/nodrew/NodrewEmbedlyBundle.git vendor/bundles/Nodrew/Bundle/EmbedlyBundle
$ git submodule update --init

第2步:配置自动加载器

<?php
// app/autoload.php

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    // ...
    'Nodrew'   => __DIR__.'/../vendor/bundles',
));

第3步:启用Bundle

最后,在kernel中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Nodrew\Bundle\EmbedlyBundle\NodrewEmbedlyBundle(),
    );
}

第4步:添加您的Embedly提供者密钥

# app/config/config.yml
nodrew_embedly:
    key:   [your api key]

用法

可以使用3个客户端。每个都对应于同名的Embedly端点

  • oEmbed: nodrew_embedly.oembed.client
  • Preview: nodrew_embedly.preview.client
  • Objectify: nodrew_embedly.objectify.client

这些接口和用法都是相同的,因此我们将使用oEmbed接口作为用法示例。

从单个URL获取

<?php

$client   = $container->get('nodrew_embedly.oembed.client');
$response = $client->fetch('http://example.com/path');

$response; // Nodrew\Bundle\EmbedlyBundle\Model\Response\ResponseInterface object

从多个URL获取

<?php

$client    = $container->get('nodrew_embedly.oembed.client');
$responses = $client->fetch(array('http://example.com/path','http://example.com/another/path'));

$responses; // array of Nodrew\Bundle\EmbedlyBundle\Model\Response\ResponseInterface objects

可能的响应对象

始终期望一个继承自Nodrew\Bundle\EmbedlyBundle\Model\Response\ResponseInterface的子类。如果没有返回,那么很可能是无法联系到Embedly或发生了超时。

如果返回了ErrorResponse对象,则它将包含一个错误消息和错误代码,尽可能详尽地描述发生了什么。通常情况下,这是当目标URL返回404错误且Embedly无法获取其信息时发生的。如果目标路径的服务器存在问题,它也可能包含500类型的错误。

oEmbed响应

预览响应

对象化响应

可选配置

这些选项可以添加到配置中。超时是指你将等待Embedly返回多长时间。如果你计划使用多个URL功能,我建议增加这个数字,因为Embedly在处理单个URL(尤其是流量大的URL)时非常快。然而,URL越不常见,你提供的信息越多,它们处理的时间就越长。

关于其他选项,请参阅Embedly查询参数文档以获取它们功能的完整参考。注意:有几个选项已被移除,因为它们在这个包的上下文中没有意义。如果你觉得其中之一是必需的,请通过错误报告告诉我,我将看看能否将其整合。

// app/config/config.yml
nodrew_embedly:
    timeout:   3
    options:
        width:      ~
        maxwidth:   ~
        maxheight:  ~
        wmode:      opaque
        nostyle:    ~
        autoplay:   ~
        videosrc:   ~
        words:      50
        chars:      ~

待办事项

  • 更多测试
  • 为预览和对象化工厂添加对象和解析,以便将事件、地点和图像处理进去。