nafresne/guzzle-ovh-plugin

用于管理OVH认证的Guzzle插件

dev-master 2014-11-06 11:57 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:02:54 UTC


README

#Guzzle OVH 插件

PHP version Build Status Scrutinizer Code Quality Code Coverage

用于使用OVH API的Guzzle 4插件

关于OVH API的更多信息:https://api.ovh.com/

##安装

###通过composer安装

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add the plugin as a dependency
php composer.phar require nafresne/guzzle-ovh-plugin:dev-master

安装完成后,您需要要求Composer的自动加载器

require 'vendor/autoload.php';

##基本用法

require 'vendor/autoload.php';

use Nafresne\GuzzleHttp\OvhClient;
use Nafresne\GuzzleHttp\Subscriber\OvhSubscriber;

//Configuration
$config = array(
    'application_key'    => 'ApplicationKey',
    'application_secret' => 'ApplicationSecret',
    'consumer_key'       => 'ConsumerKey'
);

// Create a Guzzle client
$client new OvhClient(['base_url' => 'https://eu.api.ovh.com/1.0/, 'time_url' => 'auth/time');
// and add it the plugin
$client->getEmitter()->attach(new OvhSubscriber($config));

// Now the plugin will add the correct OVH headers to your guzzle request
$response = $client->get('/data')->send();

##Symfony 2 使用

parameters:
    ovh.baseurl: "https://eu.api.ovh.com/1.0/"
    ovh.timeurl: "auth/time"
    ovh.config:
        application_key: ApplicationKey
        application_secret: ApplicationSecret
        consumer_key: ConsumerKey

services:
    guzzle.ovh.client:
        class: Nafresne\GuzzleHttp\OvhClient
        arguments:
            - { base_url: %ovh.baseurl%, time_url: %ovh.timeurl%, emitter: @guzzle.ovh.emitter }

    guzzle.ovh.emitter:
        class: GuzzleHttp\Event\Emitter
        calls:
            - [attach, [@guzzle.ovh.subscriber]]

    guzzle.ovh.subscriber:
        class: Nafresne\GuzzleHttp\Subscriber\OvhSubscriber
        arguments: [%ovh.config%]
$client = $this->container->get('guzzle.ovh.client');
$response = $client->get('hosting/web');
$body = $response->getBody();

##测试

composer install && vendor/bin/phpunit

##许可证

此插件受MIT许可证的许可