Skip to content

Commit 47f29f4

Browse files
Merge pull request #16 from Juice10/patch-1
Add syntax highlighting to readme
2 parents 70b96b0 + b5ad9aa commit 47f29f4

File tree

2 files changed

+108
-106
lines changed

2 files changed

+108
-106
lines changed

README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# A SoftLayer API PHP client.
2+
3+
## Warning
4+
5+
```
6+
The latest version 1.x is not backwards-compatible.
7+
It is necessary to update scripts to function properly with the new version.
8+
```
9+
10+
## Overview
11+
12+
The SoftLayer API PHP client classes provide a simple method for connecting to and making calls from the SoftLayer API and provides support for many of the SoftLayer API's features. Method calls and client management are handled by the PHP SOAP and XML-RPC extensions.
13+
14+
Making API calls using the `\SoftLayer\SoapClient` or `\SoftLayer\XmlRpcClient` classes is done in the following steps:
15+
16+
1. Instantiate a new `\SoftLayer\SoapClient` or `\SoftLayer\XmlRpcClient` object using the `\SoftLayer\SoapClient::getClient()` or `\SoftLayer\XmlRpcClient::getClient()` methods. Provide the name of the service that you wish to query, an optional id number of the object that you wish to instantiate, your SoftLayer API username, your SoftLayer API key, and an optional API endpoint base URL. The client classes default to connect over the public Internet. Enter `\SoftLayer\SoapClient::API_PRIVATE_ENDPOINT` or `\SoftLayer\XmlRpcClient::API_PRIVATE_ENDPOINT` to connect to the API over SoftLayer's private network. The system making API calls must be connected to SoftLayer's private network (eg. purchased from SoftLayer or connected via VPN) in order to use the private network API endpoints.
17+
2. Define and add optional headers to the client, such as object masks and result limits.
18+
3. Call the API method you wish to call as if it were local to your client object. This class throws exceptions if it's unable to execute a query, so it's best to place API method calls in try / catch statements for proper error handling.
19+
20+
Once your method is executed you may continue using the same client if you need to connect to the same service or define another client object if you wish to work with multiple services at once.
21+
22+
The most up to date version of this library can be found on the SoftLayer github public repositories: [http://github.com/softlayer/](http://github.com/softlayer/) . Please post to the SoftLayer forums <[http://forums.softlayer.com/](http://forums.softlayer.com/)> or open a support ticket in the SoftLayer customer portal if you have any questions regarding use of this library.
23+
24+
## System Requirements
25+
26+
The `\SoftLayer\SoapClient` class requires at least PHP 5.3.0 and the PHP SOAP enxtension installed. The `\SoftLayer\XmlRpcClient` class requires PHP at least PHP 5 and the PHP XML-RPC extension installed.
27+
28+
A valid API username and key are required to call the SoftLayer API. A connection to the SoftLayer private network is required to connect to SoftLayer's private network API endpopints.
29+
30+
## Installation
31+
32+
Install the SoftLayer API client using [Composer](https://getcomposer.org/).
33+
```bash
34+
composer require softlayer/softlayer-api-php-client:~1.0@dev
35+
```
36+
37+
## Usage
38+
39+
These examples use the `\SoftLayer\SoapClient` class. If you wish to use the XML-RPC API then replace mentions of `SoapClient.class.php` with `XmlrpcClient.class.php` and `\SoftLayer\SoapClient` with `\SoftLayer\XmlRpcClient`.
40+
41+
Here's a simple usage example that retrieves account information by calling the [getObject()](http://sldn.softlayer.com/reference/services/SoftLayer_Account/getObject) method in the [SoftLayer_Account](http://sldn.softlayer.com/reference/services/SoftLayer_Account) service:
42+
43+
```php
44+
<?php
45+
46+
require_once __DIR__.'/vendor/autoload.php';
47+
48+
$apiUsername = 'set me';
49+
$apiKey = 'set me too';
50+
51+
// Initialize an API client for the SoftLayer_Account service.
52+
$client = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
53+
54+
// Retrieve our account record
55+
try {
56+
$account = $client->getObject();
57+
print_r($account);
58+
} catch (\Exception $e) {
59+
die('Unable to retrieve account information: ' . $e->getMessage());
60+
}
61+
```
62+
63+
For a more complex example we'll retrieve a support ticket with id 123456 along with the ticket's updates, the user it's assigned to, the servers attached to it, and the datacenter those servers are in. We'll retrieve our extra information using a nested object mask. After we have the ticket we'll update it with the text 'Hello!'.
64+
65+
```php
66+
<?php
67+
68+
require_once __DIR__.'/vendor/autoload.php';
69+
70+
$apiUsername = 'set me';
71+
$apiKey = 'set me too';
72+
73+
// Initialize an API client for ticket 123456
74+
$client = \SoftLayer\SoapClient::getClient('SoftLayer_Ticket', 123456, $apiUsername, $apiKey);
75+
76+
// Create an object mask and assign it to our API client.
77+
$objectMask = new \SoftLayer\ObjectMask();
78+
$objectMask->updates;
79+
$objectMask->assignedUser;
80+
$objectMask->attachedHardware->datacenter;
81+
$client->setObjectMask($objectMask);
82+
83+
// Retrieve the ticket record
84+
try {
85+
$ticket = $client->getObject();
86+
} catch (\Exception $e) {
87+
die('Unable to retrieve ticket record: ' . $e->getMessage());
88+
}
89+
90+
// Update the ticket
91+
$update = new \stdClass();
92+
$update->entry = 'Hello!';
93+
94+
try {
95+
$update = $client->addUpdate($update);
96+
echo "Updated ticket 123456. The new update's id is " . $update[0]->id . '.');
97+
} catch (\Exception $e) {
98+
die('Unable to update ticket: ' . $e->getMessage());
99+
}
100+
```
101+
102+
## Author
103+
104+
This software is written by the SoftLayer Development Team <[[email protected]](mailto:[email protected])>.
105+
106+
## Copyright
107+
108+
This software is Copyright &copy; 2009 – 2010 [SoftLayer Technologies, Inc](http://www.softlayer.com/). See the bundled LICENSE.textile file for more information.

README.textile

-106
This file was deleted.

0 commit comments

Comments
 (0)