peterfox/runscope

该软件包已被弃用且不再维护。未建议替代软件包。

此软件包使在应用程序中使用Runscope变得简单,包括Guzzle和GuzzleHttp插件

1.0.1 2014-05-17 22:48 UTC

This package is not auto-updated.

Last update: 2021-10-16 01:05:26 UTC


README

  • 需要免费Runscope账户,在此注册
  • 轻松生成Runescope URL
  • 提供Guzzle(3.0)和GuzzleHttp(4.0)的插件
  • 支持Laravel 4的依赖注入,通过包含ServiceProvider和Facade类

通过以下命令安装

composer require peterfox/runscope

最基本的使用方法如下

<?php
require __DIR__ . '/../vendor/autoload.php';

use Runscope\Runscope;

$runscope = new Runscope('api-key-here');

$runscopeUrl = $runscope->proxify('https://api.github.com');

请注意,生成这些URL时,始终会提供分别在80/443端口上可正常工作的http/https URL,因为使用协议的非标准端口需要头部信息。

与Guzzle/GuzzleHttp一起使用

对于Guzzle,应用插件的方式如下

<?php
require __DIR__ . '/../vendor/autoload.php';

use Runscope\Runscope;
use Guzzle\Http\Client;
use Runscope\Plugin\Guzzle\RunscopePlugin;

$runscope = new Runscope('api-key-here');

$client = new Client('https://api.github.com');

$runscopePlugin = new RunscopePlugin($runscope);

// Add the plugin
$client->addSubscriber($runscopePlugin);

// Send the request and get the response
$response = $client->get('/')->send();

使用GuzzleHttp插件可以通过以下方式完成

<?php
require __DIR__ . '/../vendor/autoload.php';

use Runscope\Runscope;
use GuzzleHttp\Client;
use Runscope\Plugin\GuzzleHttp\RunscopePlugin;

$runscope = new Runscope('api-key-here');

$client = new Client('https://api.github.com');

$runscopePlugin = new RunscopePlugin($runscope);

// Attach the plugin
$client->getEmitter()->attach($runscopePlugin);

// Send the request and get the response
$response = $client->get('/');

Laravel 4集成

添加服务提供者

'providers' => array(
    ...
    'Runscope\RunscopeServiceProvider'
)

然后您可以从软件包中发布配置文件

php artisan config:publish peterfox/runscope

空配置至少需要您的存储桶密钥(ID)

<?php

return array(
    'bucket_key' => '',
    'auth_token' => null,
    'gateway_host' => 'runscope.net'
);

有了服务提供者,它还会为您设置外观,以便您可以使用

$url = Runscope::proxify('https://api.github.com');

您还将有一个辅助函数,使事情变得更加简单

$url = runscope_url('https://api.github.com');