softlayer_api 1.0.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7f6dacd2a3f7e2589109a815000ed208497963e
4
- data.tar.gz: b8b38d3cdaa828b98508ba13e494d0b771257c70
3
+ metadata.gz: 138098883bbed45430cd5f87cf3a55f3c44cec86
4
+ data.tar.gz: e0759954adc4ced91c4af376a3186cee67e6d8b3
5
5
  SHA512:
6
- metadata.gz: b80012657f2387a7ef60bfb284a64e2fa65ff6f8095a8b074d6992504f461b4547215607c583943ce13d86e9790fb7eddf8e5a3af90ca89eabb24293a3c7d5bf
7
- data.tar.gz: aa3cc1087a9449539d69c29277a73b4a436afe61ce5ec1b25a9235e0bb4aa7dbc5af747e1fe60dc3eff5de63f5a4d224490977832742b87f59f6b8c28569ec25
6
+ metadata.gz: bb2b89e1893eaafe7d07f07b9e0e96de18e158aadd1fe97ce0b45ca817c64bd434cb8995e0add07b54334086eb848fa692fc172dd0a2ec78ff53e9d0c6e84319
7
+ data.tar.gz: 1cf7a2aa2fc70c5b84b2405cc201e3da0a46d1e57ba8ea172cd239b791366268bc1016514fd9546d2cd5734975e47bb280b92cb562a360eceefb0977b02d5b9c
data/README.textile CHANGED
@@ -2,23 +2,63 @@ h1=. SoftLayer API Client for Ruby
2
2
 
3
3
  The SoftLayer API Client for Ruby is a library for connecting to and calling the routines of "The SoftLayer API":http://sldn.softlayer.com/article/The_SoftLayer_API from the "Ruby":http://www.ruby-lang.org programming language.
4
4
 
5
+ <div id="note" style="margin: 1em; padding: 0.5em; background-color: #fcfcfc; border: 1px solid black">
6
+ *Important Note*
7
+
8
+ Version 2.0 of the gem may require you change your existing scripts. Please see "What's New":#whats_new for details.
9
+ </div>
10
+
5
11
  h2. Overview
6
12
 
7
- The client invokes methods in the API using a REST inspired URL scheme. HTTP calls are handled using the Net::HTTP classes that are part of the Ruby core library.
13
+ The client invokes methods in the API using XML-RPC as a transport mechanism. XML-RPC is handled using @XMLRPC@ classes from the Ruby core library.
8
14
 
9
- To make calls to the Ruby API through the client you will create an instance of the @SoftLayer::Service@ class, optionally identifying an API endpoint, and providing authentication information in the form of a username and API key. You then make calls to the SoftLayer API by calling methods on the Service object. Results of those calls are communicated from the server to the client as JSON objects and then decoded and returned to you as standard Ruby objects.
15
+ To make calls to the Ruby API through the client you will create an instance of the @SoftLayer::Client@ class, optionally identifying an API endpoint, and providing authentication information in the form of a username and API key. From the client you can obtain various @SoftLayer::Service@ instances and use them to invoke the methods of the API. Results of those calls are communicated from the server to the client as XML, then decoded and returned to you as standard Ruby objects like Hashes, Arrays, and Strings.
10
16
 
11
- Source code for the most up to date version of this library can be found on the "SoftLayer github public repositories":http://github.com/softlayer/. The latest library should also be available as a Ruby gem. (see "Installation":#installation below)
17
+ Source code for daily builds of this Gem can be found on the "SoftLayer github public repositories":http://github.com/softlayer/. The latest release version of the Gem is available from the Ruby gem system. (see "Installation":#installation below)
12
18
 
13
- Should you encounter problems with the client, please contact us on the "SoftLayer forums":http://forums.softlayer.com/ or open a support ticket in the SoftLayer customer portal.
19
+ Should you encounter problems with the client, please contact us in the "SoftLayer Developer Network forums":http://forums.softlayer.com/forum/softlayer-developer-network or open a support ticket in the SoftLayer customer portal.
14
20
 
15
21
  h2. Requirements
16
22
 
17
- The Ruby client has been tested using a wide variety of Ruby implementations using both Ruby 1.8 and Ruby 1.9.
23
+ The Ruby client has been tested using a wide variety of Ruby implementations including Ruby version 1.9.2, 2.0, and 2.1. It has also been tested on JRuby running in 1.9 mode.
24
+
25
+ A network connection is required, and a valid SoftLayer API username and api 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 endpoints.
26
+
27
+ h2(#whats_new). What's New
28
+
29
+ Version 2.0 of the @softlayer_api@ gem changes the protocol used to communicate with the SoftLayer API from REST to XML-RPC. This change should not require any changes to existing scripts. However there are two new behaviors which may require you to change existing scripts:
30
+ * Object Masks are now sent to the server using the "Extended Object Mask Format":http://sldn.softlayer.com/article/Object-Masks.
31
+ * Result limits are now specified using a single call rather than requiring two
32
+
33
+ Version 2.0 does not support Ruby 1.8.x
34
+
35
+ h3. XML-RPC
36
+
37
+ In the broad view of the SoftLayer API, when sending requests to the server, an API client may use "SOAP":http://sldn.softlayer.com/article/SOAP, "XML-RPC":http://sldn.softlayer.com/article/XML-RPC, or "REST":http://sldn.softlayer.com/article/REST. Previous versions of the SoftLayer API Gem used REST to communicate with the server. This version uses XML-RPC. Adopting the XML-RPC transport mechanism allows the Gem to take adavantage of features of the API that are not available through the REST interface.
38
+
39
+ h3. Extended Object Masks
40
+
41
+ In previous versions of the SoftLayer Gem the @object_mask@ call modifier accepted Ruby structres like Arrays and Hashes and would do its best to construct Object Masks from them. @object_mask@ now expects masks to be passed as strings in the "Object Mask":http://sldn.softlayer.com/article/Object-Masks format and passes them through to the API for processing. If you are using @object_mask@, you will probably have to change your existing scripts.
42
+
43
+ The Gem extends the Ruby @Hash@ class with a method, @to_sl_object_mask@, which can help with the conversion between masks made of structured objects and the string format. This method, however, must be called explicitly. Here is an example of calling @to_sl_object_mask@:
44
+
45
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">mask_hash = { "mask" => ["id", {"assignedUser" => ["id", "username"]}, "createDate"],
46
+ "mask(SoftLayer_Hardware_Server)" => ["id", "bareMetalInstanceFlag"] }
47
+ mask_string = mask_hash.to_sl_object_mask
48
+ # mask_string is "[mask[id,assignedUser[id,username],createDate],mask(SoftLayer_Hardware_Server)[id,bareMetalInstanceFlag]]"
49
+ </code></pre>
50
+
51
+ h3. Result Limits
52
+
53
+ In previous versions of the SoftLayer API Gem, result limits were specified using two API filters:
54
+
55
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">account_service.result_offset(3).result_limit(5).getOpenTickets # this is the "old way" of specifying a result limit
56
+ </code></pre>
18
57
 
19
- This gem relies on the JSON library which, at the time of this writing, is called simply @json@ for most Ruby implementations and @json-jruby@ for JRuby. Correspondingly we have created a @softlayer_api@ gem and a @softlayer_api_jruby@ gem to account for the difference.
58
+ These two API filters have been combined into a single result limits filter:
20
59
 
21
- A network connection is required, and a valid SoftLayer 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 endpoints.
60
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">account_service.result_limit(3, 5).getOpenTickets # this is the "new way" of supplying a result limit
61
+ </code></pre>
22
62
 
23
63
  h2(#installation). Installation
24
64
 
@@ -30,13 +70,24 @@ installs the gem and makes it available to Ruby scripts. Where the gem is instal
30
70
 
31
71
  h2. Usage
32
72
 
33
- To begin using the Ruby client, you will have to create an instance of the @SoftLayer::Service@ class for each the "API Services":http://sldn.softlayer.com/reference/services that your code will call. To create the instance, you will have to provide information that the library will use to authenticate your account with the API servers.
34
-
35
- Once you have created a service object, you will use that service object to call methods in the SoftLayer API.
73
+ To begin using the Ruby client, you will have to create an instance of the @SoftLayer::Client@. From the Client you must obtain @SoftLayer::Service@ objects corresponding to each of the "API Services":http://sldn.softlayer.com/reference/services that your code wants to call. To create the client instance, you will have to provide information that the library will use to authenticate your account with the API servers.
36
74
 
37
75
  h3. Authentication
38
76
 
39
- That instance will have to know your "API authentication information":http://sldn.softlayer.com/article/Authenticating_to_the_SoftLayer_API consisting of your account username and API key. In addition, you will have to select an endpoint, the web address the client will use to contact the SoftLayer API. You may provide this information either through global variables, or by passing them to the constructor.
77
+ That instance will have to know your "API authentication information":http://sldn.softlayer.com/article/Authenticating_to_the_SoftLayer_API consisting of your account username and API key. In addition, you will have to select an endpoint, the web address the client will use to contact the SoftLayer API. You may provide this information in a configuration file, through global variables, or by passing them to the constructor.
78
+
79
+ h4. Providing authentication in a config file
80
+
81
+ The Ruby client will look for a configuration file that can provide the username and api_key for requests. A sample configuraiton file looks like this:
82
+
83
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">[softlayer]
84
+ username = joeusername
85
+ api_key = DEADBEEFBADF00D
86
+ </code></pre>
87
+
88
+ It is important that the config file declare the section "softlayer". The keys accepted in that section are @username@, @api_key@, and @endpoint_url@. You will have to provide an explicit endpoint url, for example, if you want to use the SoftLayer private network API endpoint.
89
+
90
+ The client will look for configuration files in your home directory under the name ".softlayer" or in the directory @/etc/softlayer.conf@
40
91
 
41
92
  h4. Providing authentication information through Globals
42
93
 
@@ -52,8 +103,8 @@ If you are going to create a lot of different @Service@ objects and they are all
52
103
  In addition to the globals, the @SoftLayer@ namespace defines two constants representing the endpoints for the SoftLayer API on the private and public networks:
53
104
 
54
105
  table{position:relative;left:2em;width:80%}.
55
- |{vertical-align:baseline;width:35%}.@API_PUBLIC_ENDPOINT@|A constant containing the base address for the public network REST inspired endpoint of the SoftLayer API - @https://api.softlayer.com/rest/v3/@|
56
- |{vertical-align:baseline}.@API_PRIVATE_ENDPOINT@|A constant containing the base address for the private network REST inspired endpoint of the SoftLayer API - @https://api.service.softlayer.com/rest/v3/@|
106
+ |{vertical-align:baseline;width:35%}.@API_PUBLIC_ENDPOINT@|A constant containing the base address for the public network XML-RPC endpoint of the SoftLayer API - @https://api.softlayer.com/xmlrpc/v3/@|
107
+ |{vertical-align:baseline}.@API_PRIVATE_ENDPOINT@|A constant containing the base address for the private network XML-RPC endpoint of the SoftLayer API - @https://api.service.softlayer.com/xmlrpc/v3/@|
57
108
 
58
109
  For more information about the two networks see "Choosing_the_Public_or_Private_Network":http://sldn.softlayer.com/article/The_SoftLayer_API#Choosing_the_Public_or_Private_Network. You can change the default endpoint URL by setting the global variable @$SL_API_BASE_URL@ to either of these two values.
59
110
 
@@ -62,14 +113,15 @@ Here is an example of using these globals to create a service:
62
113
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">$SL_API_USERNAME = "joeusername";
63
114
  $SL_API_KEY = "omitted_for_brevity"
64
115
 
65
- account_service = SoftLayer::Service.new("SoftLayer_Account")
116
+ client = SoftLayer::Client.new()
117
+ account_service = client.service_named("Account")
66
118
  </code></pre>
67
119
 
68
120
  Note that the endpoint URL is not specified. The default endpoint URL is set to the @API_PUBLIC_ENDPOINT@
69
121
 
70
122
  h4. Providing authentication information through the Constructor
71
123
 
72
- You can provide the authentication information needed by a @Service@ object as hash arguments in the constructor. The keys used in the hash arguments are symbols whose values should be strings:
124
+ You can provide the authentication information needed by a @Client@ object as hash arguments in the constructor. The keys used in the hash arguments are symbols whose values should be strings:
73
125
 
74
126
  table{position:relative;left:2em;width:80%}.
75
127
  |{vertical-align:baseline;width:30%}.@:username@|The username used to authenticate with the server.|
@@ -78,10 +130,10 @@ table{position:relative;left:2em;width:80%}.
78
130
 
79
131
  Here is an example, analogous to the one for global variables, which provides the username and API key as hash arguments. This example also changes the endpoint with the @:endpoint_url@ symbol so that the service will use the API on the SoftLayer Private Network:
80
132
 
81
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">account_service = SoftLayer::Service.new("SoftLayer_Account",
82
- :username => "joeusername",
133
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">client = SoftLayer::Client.new(:username => "joeusername",
83
134
  :api_key => "omitted_for_brevity",
84
135
  :endpoint_url => API_PRIVATE_ENDPOINT)
136
+ account_service = client.service_named("Account")
85
137
  </code></pre>
86
138
 
87
139
  h3. Calling Service Methods
@@ -91,10 +143,13 @@ With an instance of @SoftLayer::Service@ in hand, you can call the methods provi
91
143
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">open_tickets = account_service.getOpenTickets
92
144
  </code></pre>
93
145
 
94
- If the method requires arguments, you can supply them as arguments to the method you're calling on the service object. The arguments should be arguments that can be encoded using the JSON encoder provided by the @json@ gem. Generally this means your argument should be hashes, arrays, strings, numbers, booleans, or nil. Here is an example of calling the @createStandardTicket@ method on a ticket service:
146
+ If the method requires arguments, you can supply them as arguments to the method you're calling on the service object. The arguments should be arguments that XML-RPC can encode into XML. Generally this means your argument should be hashes, arrays, strings, numbers, booleans, or nil.
147
+
148
+ Here is an example of calling the @createStandardTicket@ method on a ticket service. This example also uses the "bracket" syntax on a client @client['<service-name>']@ to obtain the service object:
95
149
 
96
150
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">#authentication information will be found in the global variables
97
- ticket_service = SoftLayer::Service.new("SoftLayer_Ticket")
151
+ client = SoftLayer::Client.new()
152
+ ticket_service = client['Ticket']
98
153
  new_ticket = ticket_service.createStandardTicket(
99
154
  {
100
155
  "assignedUserId" => my_account_id,
@@ -106,16 +161,16 @@ new_ticket = ticket_service.createStandardTicket(
106
161
 
107
162
  h4. Identifying Particular Objects
108
163
 
109
- Some method calls in the SoftLayer API are made on particular objects, rather than on the services themselves. These objects, however, are always obtained by a service. To call a method on a particular object you can chain a call to @object_with_id@ onto the service that provides the object in question. @object_with_id@ takes one argument, the object id of the object you are interested in. For example, if you were interested in getting the Ticket with a ticket id of 123456 you could so so by calling:
164
+ Some method calls in the SoftLayer API are made on particular objects, rather than on the services themselves. These objects, however, are always obtained by a service. To call a method on a particular object you can chain a call to @object_with_id@ onto the service that provides the object in question. @object_with_id@ takes one argument, the object id of the object you are interested in. For example, if you were interested in getting the Ticket with a ticket id of 123456 you could so so by calling:
110
165
 
111
166
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">ticket_of_interest = ticket_service.object_with_id(123456).getObject
112
167
  </code></pre>
113
168
 
114
- The @object_with_id@ call returns an object that you can use as a reference to a particular object through the service. This allows you to reuse that object multiple times without having to repeatedly tack @object_with_id@ on to all your requests. For example, if you want to find a ticket with the id 98765 and add an update to it if it's assigned to user 123456, you might write code like this:
169
+ The @object_with_id@ call returns an object that you can use as a reference to a particular object through the service. This allows you to reuse that object multiple times without having to repeatedly tack @object_with_id@ on to all your requests. For example, if you want to find a ticket with the id 98765 and add an update to it if it's assigned to user 123456, you might write code like this:
115
170
 
116
171
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">begin
117
172
  ticket_ref = ticket_service.object_with_id(98765)
118
- ticket = ticket_ref.object_mask("assignedUserId").getObject
173
+ ticket = ticket_ref.object_mask("mask.assignedUserId").getObject
119
174
  if ticket['assignedUserId'] == 123456
120
175
  updates = ticket_ref.addUpdate({"entry" => "Get to work on these tickets!"})
121
176
  end
@@ -126,15 +181,13 @@ end
126
181
 
127
182
  The code creates a variable named @ticket_ref@ which refers to ticket 98765 through the tickets_service. This @ticket_ref@ is used with an @object_mask@ to retrieve the ticket and, if the ticket meets the conditional requirement, that same @ticket_ref@ is reused to add an update to the ticket.
128
183
 
129
- h4. Adding an object mask
184
+ h4. Adding an Object Mask
130
185
 
131
- If you wish to limit the volume of information that the server returns about a particular object, you can use an object mask to indicate exactly which attributes you are interested in. To provide an object mask you simply insert a call to @object_mask@ in the call chain for the method you are invoking.
186
+ If you wish to limit the volume of information that the server returns about a particular object, you can use an Object Mask to indicate exactly which attributes you are interested in. To provide an Object Mask you simply insert a call to @object_mask@ in the call chain for the method you are invoking.
132
187
 
133
- The arguments to object_mask can be strings, arrays, or hashes. The Strings provide the names of properties you are interested in and the hash and array elements allow you to structure your mask much as the properties themselves are structured.
188
+ The arguments to @object_mask@ must strings. Each string should be a well defined Object Mask as defined in the "SLDN documentation":http://sldn.softlayer.com/article/Object-Masks.
134
189
 
135
- To look at some examples, consider the following object from the server. It has four properties and an entity, and id, a title, a createDate (giving the date it was create), a modifyDate (the date it was last modified), and an assignedUser entity.
136
-
137
- The assignedUser entity has three properties, id, username, and health.
190
+ To look at some examples, consider the following object from the server. It has four properties: @id@, @title@, @createDate@ and @modifyDate@. It also has an entity, @assignedUser@. The @assignedUser@ entity has three properties: @id@, @username@, and @health@.
138
191
 
139
192
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">{
140
193
  "id"=>1736473,
@@ -146,99 +199,94 @@ The assignedUser entity has three properties, id, username, and health.
146
199
  "username"=>"AlfredQHacker",
147
200
  "health"=>"Fantastic"
148
201
  },
149
- }
150
- </code></pre>
202
+ }</code></pre>
151
203
 
152
- If we were making a request to the server to retrieve this object, or an array of such objects, we might want to limit the response so that it contains just the id fields:
204
+ If we were making a request to the server to retrieve this object, or an array of such objects, we might want to limit the response so that it contains just the @id@ fields:
153
205
 
154
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("id").getObject
206
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("mask.id").getObject
155
207
  => {"id"=>1736473}
156
208
  </code></pre>
157
209
 
158
210
  If we want more than one property back from the server the call to @object_mask@ can identify multiple properties as separate argumnents:
159
211
 
160
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("id", "createDate").getObject # object_mask with multiple arguments
161
- => {"id"=>1736473, "createDate"=>"2010-04-22T00:12:36-05:00"}
162
- </code></pre>
163
-
164
- or it can include them in an array:
165
-
166
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask(["id", "createDate"]).getObject # multiple mask items presented in an array
212
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("mask[id,createDate]").getObject
167
213
  => {"id"=>1736473, "createDate"=>"2010-04-22T00:12:36-05:00"}
168
214
  </code></pre>
169
215
 
170
- If we ask for the assignedUser we get back that entire entity:
216
+ If we ask for the @assignedUser@ we get back that entire entity:
171
217
 
172
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("assignedUser").getObject
218
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("mask.assignedUser").getObject
173
219
  => {"assignedUser"=> {"id"=>14, "username"=>"AlfredQHacker", "health"=>"Fantastic"}}
174
220
  </code></pre>
175
221
 
176
222
  However, we may not be interested in the entire assigned user entity, we may
177
- want to get just the id of the assigned user. To do that we pass a hash argument to @object_mask@. The has follows the hierarchical nature of the properties
223
+ want to get just the id of the assigned user:
178
224
 
179
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask({"assignedUser" => "id"}).getObject # using a hash to access the property hierarchy
225
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("mask[assignedUser.id]").getObject
180
226
  => {"assignedUser"=>{"id"=>14}}
181
227
  </code></pre>
182
228
 
183
- We can identify a particular set of attributes we are interested in by combining the array and hash forms:
229
+ We can identify a particular set of attributes we are interested in by combining Object Mask forms:
184
230
 
185
- <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask({"assignedUser" => ["id", "health"]}).getObject # retrieving multiple properties
231
+ <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">an_api_service.object_mask("mask[assignedUser[id,health]]").getObject # retrieving multiple properties
186
232
  => {"assignedUser"=>{"id"=>14, "health"=>"Fantastic"}}
187
233
  </code></pre>
188
234
 
189
- Object masks are sent to the server and applied on the server side. By carefully choosing an object mask, you can limit amount of information transferred from the server which may improve bandwidth and processing time.
235
+ Object masks are sent to the server and applied on the server side. Errors in the object mask format will lead to exceptions being thrown by the SoftLayer API. By carefully choosing an Object Mask, you can limit amount of information transferred from the server which may improve bandwidth and processing time.
190
236
 
191
- You may add calls to both @object_mask@ and @object_with_id@, but only one call to each should appear in any calling sequence.
237
+ You @object_with_id@ should only be called once in any calling sequence. You may call @object_mask@ multiple times, but the server may generate a warning if the Object Masks ask for duplicate properties of some object.
192
238
 
193
239
  h2. Examples
194
240
 
195
- Here are some examples that demonstrate using the SoftLayer API Ruby Client. The authentication information, of course, is left as an exercise for the reader. The first example uses the @getObject@ method of the "SoftLayer_Account":http://sldn.softlayer.com/reference/services service:
241
+ Here are some examples that demonstrate using the SoftLayer API Ruby Client. The authentication information, of course, is left as an exercise for the reader. The first example uses the @getObject@ method of the "SoftLayer_Account":http://sldn.softlayer.com/reference/services service:
196
242
 
197
243
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">require 'rubygems'
198
244
  require 'softlayer_api'
199
245
  require 'pp'
200
246
 
201
247
  begin
202
- # use an account service to get a list of the open tickets and print their IDs and titles
203
- account_service = SoftLayer::Service.new("SoftLayer_Account",
248
+ # use an account service to get a list of the open tickets and print their IDs and titles
249
+ client = SoftLayer::Client.new(
204
250
  :username => "joecustomer", # enter your username here
205
251
  :api_key => "feeddeadbeefbadf00d...") # enter your api key here
206
252
 
207
- account = account_service.getObject
208
- pp account
253
+ account_service = client['Account']
254
+ account = account_service.getObject
255
+ pp account
209
256
  rescue Exception => exception
210
- puts "Unable to retrieve account information: #{exception}"
257
+ puts "Unable to retrieve account information: #{exception}"
211
258
  end
212
259
  </code></pre>
213
260
 
214
261
  This second example retrieves some of the information in a support ticket then adds and update to that ticket. It uses an object_with_id to create an object
215
- that references a ticket with a particular ID and reuses that reference later to refer to the same ticket. It combines that reference with an object_mask to limit the amount of information transferred from the server.
262
+ that references a ticket with a particular ID and reuses that reference later to refer to the same ticket. It combines that reference with an @object_mask@ to limit the amount of information transferred from the server.
216
263
 
217
264
  <pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">require 'rubygems'
218
265
  require 'softlayer_api'
219
266
  require 'pp'
220
267
 
221
- ticket_service = SoftLayer::Service.new("SoftLayer_Ticket",
222
- :username => "joecustomer", # enter your username here
223
- :api_key => "feeddeadbeefbadf00d...") # enter your api key here
268
+ client = SoftLayer::Client.new()
269
+ :username => "joecustomer", # enter your username here
270
+ :api_key => "feeddeadbeefbadf00d...") # enter your api key here
271
+
272
+ ticket_service = client.service_named('Ticket')
224
273
 
225
274
  begin
226
- ticket_ref = ticket_service.object_with_id(123456)
275
+ # this creates an alias to the ticket service bound to the ticket with the id 123456
276
+ ticket_ref = ticket_service.object_with_id(123456) # you'll have to substitute your own ticket ID
227
277
 
228
- ticket = ticket_ref.object_mask({"updates" => ["entry", "createDate"]},
229
- "assignedUserId",
230
- {"attachedHardware" => "datacenter"}).getObject
231
- pp ticket
278
+ ticket = ticket_ref.object_mask("mask[updates[entry,createDate],assignedUserId,attachedHardware.datacenter]").getObject
279
+ pp ticket
232
280
  rescue Exception => exception
233
- puts "Unable to retrieve the ticket"
281
+ puts "Unable to retrieve the ticket"
234
282
  end
235
283
 
236
284
  # update the ticket
237
285
  begin
238
- updates = ticket_ref.addUpdate({"entry" => "An update from the Ruby client!"})
239
- puts "Update ticket 123456. The new update's id is #{updates[0]['id']}"
286
+ updates = ticket_ref.addUpdate({"entry" => "An update from the Ruby client!"})
287
+ puts "Update ticket 123456. The new update's id is #{updates[0]['id']}"
240
288
  rescue Exception => exception
241
- puts "Unable to update the ticket: #{exception}"
289
+ puts "Unable to update the ticket: #{exception}"
242
290
  end
243
291
  </code></pre>
244
292
 
@@ -246,6 +294,8 @@ h2. Author
246
294
 
247
295
  This software is written by the SoftLayer Development Team <"sldn@softlayer.com":mailto:sldn@softlayer.com>.
248
296
 
297
+ Please join us in the "SoftLayer Developer Network forums":http://forums.softlayer.com/forum/softlayer-developer-network
298
+
249
299
  h2. Copyright
250
300
 
251
301
  This software is Copyright (c) 2010-2014 "SoftLayer Technologies, Inc":http://www.softlayer.com/. See the bundled LICENSE.textile file for more information.
@@ -25,11 +25,13 @@ require 'softlayer_api'
25
25
  require 'pp'
26
26
 
27
27
  begin
28
- # use an account service to get a list of the open tickets and print their IDs and titles
29
- account_service = SoftLayer::Service.new("SoftLayer_Account",
30
- :username => "joecustomer" # enter your username here
31
- :api_key => "feeddeadbeefbadf00d...") # enter your api key here
28
+ softlayer_client = SoftLayer::Client.new(
29
+ :username => "joecustomer" # enter your username here
30
+ :api_key => "feeddeadbeefbadf00d..." # enter your api key here
31
+ )
32
32
 
33
+ # use an account service to get a list of the open tickets and print their IDs and titles
34
+ account_service = softlayer_client['Account'];
33
35
  account = account_service.getObject
34
36
  pp account
35
37
  rescue Exception => exception
@@ -29,13 +29,16 @@ require 'pp'
29
29
  $SL_API_USERNAME = "joecustomer" # enter your username here
30
30
  $SL_API_KEY = "feeddeadbeefbadf00d..." # enter your api key here
31
31
 
32
+ softlayer_client = SoftLayer::Client.new()
32
33
  begin
33
34
  # use an account service to get the account ID of my account
34
- account_service = SoftLayer::Service.new("SoftLayer_Account")
35
+ account_service = softlayer_client.service_named("Account")
35
36
  my_account_id = account_service.getCurrentUser['id']
36
37
 
37
38
  # Use a ticket service to create a standard support ticket, assigned to me.
38
- ticket_service = SoftLayer::Service.new("SoftLayer_Ticket")
39
+ # Note: calling for the Ticket service using the brackets is entirely equivalent
40
+ # go calling service_named('Ticket')
41
+ ticket_service = softlayer_client['Ticket']
39
42
  new_ticket = ticket_service.createStandardTicket(
40
43
  {
41
44
  "assignedUserId" => my_account_id,
@@ -47,7 +50,7 @@ begin
47
50
  puts "Created a new ticket : #{new_ticket['id']} - #{new_ticket['title']}"
48
51
 
49
52
  # add an update to the newly created ticket.
50
- pp ticket_service.object_with_id(new_ticket['id']).edit(nil, "This is a ticket update sent from the Ruby library")
53
+ pp ticket_service.object_with_id(new_ticket['id']).edit({}, "This is a ticket update sent from the Ruby library")
51
54
  rescue Exception => exception
52
55
  $stderr.puts "An exception occurred while trying to complete the SoftLayer API calls #{exception}"
53
56
  end
@@ -27,9 +27,11 @@ require 'pp'
27
27
  $SL_API_USERNAME = "joecustomer" # enter your username here
28
28
  $SL_API_KEY = "feeddeadbeefbadf00d..." # enter your api key here
29
29
 
30
+ softlayer_client = SoftLayer::Client.new()
31
+
30
32
  # use an account service to get a list of the open tickets and print their
31
33
  # IDs and titles
32
- account_service = SoftLayer::Service.new("SoftLayer_Account")
34
+ account_service = softlayer_client.service_named("Account")
33
35
 
34
36
  open_tickets = account_service.getOpenTickets
35
37
  open_tickets.each { |ticket| puts "#{ticket['id']} - #{ticket['title']}" }
@@ -38,11 +40,11 @@ open_tickets.each { |ticket| puts "#{ticket['id']} - #{ticket['title']}" }
38
40
  # information known about it. We've already collected this information above,
39
41
  # but this will demonstrate using an object mask to filter the results from
40
42
  # the server.
41
- ticket_service = SoftLayer::Service.new("SoftLayer_Ticket")
43
+ ticket_service = softlayer_client["Ticket"]
42
44
  open_tickets.each do |ticket|
43
45
  begin
44
- pp ticket_service.object_with_id(ticket["id"]).object_mask( "id", "title", "createDate", "modifyDate", { "assignedUser" => ["id", "username", "email"] }).getObject
46
+ pp ticket_service.object_with_id(ticket["id"]).object_mask("mask[id,title,createDate,modifyDate,assignedUser[id,username,email]]").getObject
45
47
  rescue Exception => exception
46
- puts "exception #{e}"
48
+ puts "exception #{exception}"
47
49
  end
48
50
  end
@@ -24,19 +24,19 @@ require 'rubygems'
24
24
  require 'softlayer_api'
25
25
  require 'pp'
26
26
 
27
- ticket_service = SoftLayer::Service.new("SoftLayer_Ticket",
27
+ softlayer_client = SoftLayer::Client.new(
28
28
  :username => "joecustomer", # enter your username here
29
- :api_key => "feeddeadbeefbadf00d...") # enter your api key here
29
+ :api_key => "feeddeadbeefbadf00d..." # enter your api key here
30
+ )
30
31
 
31
32
  begin
32
- ticket_ref = ticket_service.object_with_id(1683973)
33
+ ticket_service = softlayer_client.service_named("Ticket");
34
+ ticket_ref = ticket_service.object_with_id(8172109)
33
35
 
34
- ticket = ticket_ref.object_mask({"updates" => ["entry", "createDate"]},
35
- "assignedUserId",
36
- {"attachedHardware" => "datacenter"}).getObject
36
+ ticket = ticket_ref.object_mask("mask[updates[entry,createDate],assignedUserId,attachedHardware.datacenter]".getObject
37
37
  pp ticket
38
38
  rescue Exception => exception
39
- puts "Unable to retrieve the ticket"
39
+ puts "Unable to retrieve the ticket"
40
40
  end
41
41
 
42
42
  # update the ticket
@@ -44,5 +44,5 @@ begin
44
44
  updates = ticket_ref.addUpdate({"entry" => "An update from the Ruby client!"})
45
45
  puts "Update ticket 123456. The new update's id is #{updates[0]['id']}"
46
46
  rescue Exception => exception
47
- puts "Unable to update the ticket: #{exception}"
47
+ puts "Unable to update the ticket: #{exception}"
48
48
  end