howard1982 / softlayer-api-php-client

此包的最新版本(dev-master)没有提供许可证信息。

将 softlayer/softlayer-api-php-client 添加到 composer

dev-master 2014-06-11 10:03 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:12:00 UTC


README

概述

SoftLayer API PHP 客户端类提供了一种简单的方法来连接和调用 SoftLayer API,并支持许多 SoftLayer API 的功能。方法调用和客户端管理由 PHP SOAP 和 XML-RPC 扩展处理。

使用 SoftLayer_SoapClient 或 SoftLayer_XmlrpcClient 类调用 API 的步骤如下

  1. 使用 SoftLayer_SoapClient::getClient() 或 SoftLayer_XmlrpcClient::getClient() 方法实例化一个新的 SoftLayer_SoapClient 或 SoftLayer_XmlrpcClient 对象。提供您要查询的服务名称、您要实例化的对象的可选 id 号、您的 SoftLayer API 用户名、您的 SoftLayer API 密钥以及可选的 API 端点基本 URL。客户端类默认通过公共互联网连接。输入 SoftLayer_SoapClient::API_PRIVATE_ENDPOINT 或 SoftLayer_XmlrpcClient::API_PRIVATE_ENDPOINT 以通过 SoftLayer 的私有网络连接到 API。发出 API 调用的系统必须连接到 SoftLayer 的私有网络(例如,从 SoftLayer 购买或通过 VPN 连接)才能使用私有网络 API 端点。
  2. 定义并添加可选的标题到客户端,如对象掩码和结果限制。
  3. 调用您希望调用的 API 方法,就像它是您客户端对象的本地方法一样。此类在无法执行查询时抛出异常,因此最好将 API 方法调用放在 try / catch 语句中以进行适当的错误处理。

您的操作执行后,如果需要连接到同一服务,则可以继续使用同一客户端,或者如果您希望同时处理多个服务,则可以定义另一个客户端对象。

此库的最新版本可以在 SoftLayer github 公共存储库中找到:http://github.com/softlayer/。如果您对使用此库有任何疑问,请在 SoftLayer 论坛 <http://forums.softlayer.com/> 发帖或在 SoftLayer 客户端门户中提交支持票证。

系统要求

SoftLayer_SoapClient 类需要至少 PHP 5.2.3 和 PHP SOAP 扩展安装。SoftLayer_Xmlrpc 类需要 PHP 至少 PHP 5 和 PHP XML-RPC 扩展安装。

调用 SoftLayer API 需要有效的 API 用户名和密钥。要连接到 SoftLayer 的私有网络 API 端点,需要连接到 SoftLayer 私有网络。

安装

下载并将 SoftLayer API 客户端复制到您的 PHP 项目本地目录或 PHP 安装包含路径内的路径。

用法

以下示例使用 SoftLayer_SoapClient 类。如果您想使用 XML-RPC API,请将 SoapClient.class.php 替换为 XmlrpcClient.class.php,并将 SoftLayer_SoapClient 替换为 SoftLayer_XmlrpcClient。

以下是一个简单的用法示例,通过调用 getObject 方法在 SoftLayer_Account 服务中检索账户信息


<?php

require_once dirname(__FILE__) . '/SoftLayer/SoapClient.class.php';

$apiUsername = 'set me';
$apiKey = 'set me too';

// Initialize an API client for the SoftLayer_Account service.
$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);

// Retrieve our account record
try {
    $account = $client->getObject();
    print_r($account);
} catch (Exception $e) {
    die('Unable to retrieve account information: ' . $e->getMessage());
}

为了一个更复杂的示例,我们将检索一个ID为123456的支持工单及其更新、分配给的用户、附加到该工单的服务器以及这些服务器所在的数据中心。我们将使用嵌套对象掩码来检索额外信息。获取工单后,我们将使用文本‘Hello!’更新它。


<?php

require_once dirname(__FILE__) . '/SoftLayer/SoapClient.class.php';

$apiUsername = 'set me';
$apiKey = 'set me too';

// Initialize an API client for ticket 123456
$client = SoftLayer_SoapClient::getClient('SoftLayer_Ticket', 123456, $apiUsername, $apiKey);

// Create an object mask and assign it to our API client.
$objectMask = new SoftLayer_ObjectMask();
$objectMask->updates;
$objectMask->assignedUser;
$objectMask->attachedHardware->datacenter;
$client->setObjectMask($objectMask);

// Retrieve the ticket record
try {
    $ticket = $client->getObject();
} catch (Exception $e) {
    die('Unable to retrieve ticket record: ' . $e->getMessage());
}

// Update the ticket
$update = new stdClass();
$update->entry = 'Hello!';

try {
    $update = $client->addUpdate($update);
    echo "Updated ticket 123456. The new update's id is " . $update[0]->id . '.');
} catch (Exception $e) {
    die('Unable to update ticket: ' . $e->getMessage());
}

作者

本软件由SoftLayer开发团队编写 <sldn@softlayer.com>。

版权

本软件版权所有 © 2009 – 2010 SoftLayer Technologies, Inc。有关更多信息,请参阅捆绑的LICENSE文本文件。