softlayer_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.textile ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2010, "SoftLayer Technologies, Inc.":http://www.softlayer.com/ All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+ * Neither SoftLayer Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.textile ADDED
@@ -0,0 +1,251 @@
1
+ h1=. SoftLayer API Client for Ruby
2
+
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/wiki/index.php/The_SoftLayer_API from the "Ruby":http://www.ruby-lang.org programming language.
4
+
5
+ h2. Overview
6
+
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.
8
+
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.
10
+
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)
12
+
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.
14
+
15
+ h2. Requirements
16
+
17
+ The Ruby client has been tested using a wide variety of Ruby implementations using both Ruby 1.8 and Ruby 1.9.
18
+
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.
20
+
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.
22
+
23
+ h2(#installation). Installation
24
+
25
+ The Ruby client is available as the @softlayer_api@ Ruby gem. On most systems, the command:
26
+
27
+ @gem install softlayer_api@
28
+
29
+ installs the gem and makes it available to Ruby scripts. Where the gem is installed on your computer will depend on your particular distribution of Ruby. Refer to the gem documentation for your distribution for more information.
30
+
31
+ h2. Usage
32
+
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/wiki/index.php/Category:API_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.
36
+
37
+ h3. Authentication
38
+
39
+ That instance will have to know your "API authentication information":http://sldn.softlayer.com/wiki/index.php/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.
40
+
41
+ h4. Providing authentication information through Globals
42
+
43
+ The SoftLayer Ruby Client makes use of three global variables, in the @SoftLayer@ name space, related to creating instances of the @SoftLayer::Service@ class:
44
+
45
+ table{position:relative;left:2em;width:80%}.
46
+ |{vertical-align:baseline;width:30%}.@$SL_API_USERNAME@|A string used as the default username used when creating @Service@ objects|
47
+ |{vertical-align:baseline}.@$SL_API_KEY@|A string used as the default API key used when creating @Service@ objects.|
48
+ |{vertical-align:baseline}.@$SL_API_BASE_URL@|The endpoint base URL used by the service. This variable defaults to @API_PUBLIC_ENDPOINT@ |
49
+
50
+ If you are going to create a lot of different @Service@ objects and they are all going to use the same authentication information it may be convenient to set the values in these globals.
51
+
52
+ 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
+
54
+ 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/@|
57
+
58
+ For more information about the two networks see "Choosing_the_Public_or_Private_Network":http://sldn.softlayer.com/wiki/index.php/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
+
60
+ Here is an example of using these globals to create a service:
61
+
62
+ <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
+ $SL_API_KEY = "omitted_for_brevity"
64
+
65
+ account_service = SoftLayer::Service.new("SoftLayer_Account")
66
+ </code></pre>
67
+
68
+ Note that the endpoint URL is not specified. The default endpoint URL is set to the @API_PUBLIC_ENDPOINT@
69
+
70
+ h4. Providing authentication information through the Constructor
71
+
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:
73
+
74
+ table{position:relative;left:2em;width:80%}.
75
+ |{vertical-align:baseline;width:30%}.@:username@|The username used to authenticate with the server.|
76
+ |{vertical-align:baseline}.@:api_key@|The API key used to authenticate with the server.|
77
+ |{vertical-align:baseline}.@:endpoint_url@|The endpoint address that will receive the method calls.|
78
+
79
+ 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
+
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",
83
+ :api_key => "omitted_for_brevity",
84
+ :endpoint_url => API_PRIVATE_ENDPOINT)
85
+ </code></pre>
86
+
87
+ h3. Calling Service Methods
88
+
89
+ With an instance of @SoftLayer::Service@ in hand, you can call the methods provided by that service. Calling a API method on a service is as easy as calling a Ruby method on the service object. For example, given the @account_service@ objects created above, a call to get a list of the open tickets on an account using the @SoftLayer_Account@ service's @getOpenTickets@ method would look like this:
90
+
91
+ <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
+ </code></pre>
93
+
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:
95
+
96
+ <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")
98
+ new_ticket = ticket_service.createStandardTicket(
99
+ {
100
+ "assignedUserId" => my_account_id,
101
+ "subjectId" => 1022,
102
+ "notifyUserOnUpdateFlag" => true
103
+ },
104
+ "This is a test ticket created from a Ruby client")
105
+ </code></pre>
106
+
107
+ h4. Identifying Particular Objects
108
+
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:
110
+
111
+ <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
+ </code></pre>
113
+
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:
115
+
116
+ <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
+ ticket_ref = ticket_service.object_with_id(98765)
118
+ ticket = ticket_ref.object_mask("assignedUserId").getObject
119
+ if ticket['assignedUserId'] == 123456
120
+ updates = ticket_ref.addUpdate({"entry" => "Get to work on these tickets!"})
121
+ end
122
+ rescue Exception => exception
123
+ puts "An error occurred while updating the ticket: #{exception}"
124
+ end
125
+ </code></pre>
126
+
127
+ 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
+
129
+ h4. Adding an object mask
130
+
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.
132
+
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.
134
+
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.
138
+
139
+ <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
+ "id"=>1736473,
141
+ "title"=>"VM Polling Failure - unable to login",
142
+ "createDate"=>"2010-04-22T00:12:36-05:00",
143
+ "modifyDate"=>"2010-06-09T06:44:18-05:00"
144
+ "assignedUser"=> {
145
+ "id"=>14
146
+ "username"=>"AlfredQHacker",
147
+ "health"=>"Fantastic"
148
+ },
149
+ }
150
+ </code></pre>
151
+
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:
153
+
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
155
+ => {"id"=>1736473}
156
+ </code></pre>
157
+
158
+ If we want more than one property back from the server the call to @object_mask@ can identify multiple properties as separate argumnents:
159
+
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
167
+ => {"id"=>1736473, "createDate"=>"2010-04-22T00:12:36-05:00"}
168
+ </code></pre>
169
+
170
+ If we ask for the assignedUser we get back that entire entity:
171
+
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
173
+ => {"assignedUser"=> {"id"=>14, "username"=>"AlfredQHacker", "health"=>"Fantastic"}}
174
+ </code></pre>
175
+
176
+ 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
178
+
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
180
+ => {"assignedUser"=>{"id"=>14}}
181
+ </code></pre>
182
+
183
+ We can identify a particular set of attributes we are interested in by combining the array and hash forms:
184
+
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
186
+ => {"assignedUser"=>{"id"=>14, "health"=>"Fantastic"}}
187
+ </code></pre>
188
+
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.
190
+
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.
192
+
193
+ h2. Examples
194
+
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/wiki/index.php/SoftLayer_Account service:
196
+
197
+ <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
+ require 'softlayer_api'
199
+ require 'pp'
200
+
201
+ 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",
204
+ :username => "joecustomer" # enter your username here
205
+ :api_key => "feeddeadbeefbadf00d...") # enter your api key here
206
+
207
+ account = account_service.getObject
208
+ pp account
209
+ rescue Exception => exception
210
+ puts "Unable to retrieve account information: #{exception}"
211
+ end
212
+ </code></pre>
213
+
214
+ 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.
216
+
217
+ <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
+ require 'softlayer_api'
219
+ require 'pp'
220
+
221
+ ticket_service = SoftLayer::Service.new("SoftLayer_Ticket",
222
+ :username => "joecustomer", # enter your username here
223
+ :api_key => "feeddeadbeefbadf00d...") # enter your api key here
224
+
225
+ begin
226
+ ticket_ref = ticket_service.object_with_id(1683973)
227
+
228
+ ticket = ticket_ref.object_mask({"updates" => ["entry", "createDate"]},
229
+ "assignedUserId",
230
+ {"attachedHardware" => "datacenter"}).getObject
231
+ pp ticket
232
+ rescue Exception => exception
233
+ puts "Unable to retrieve the ticket"
234
+ end
235
+
236
+ # update the ticket
237
+ 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']}"
240
+ rescue Exception => exception
241
+ puts "Unable to update the ticket: #{exception}"
242
+ end
243
+ </code></pre>
244
+
245
+ h2. Author
246
+
247
+ This software is written by the SoftLayer Development Team <"sldn@softlayer.com":mailto:sldn@softlayer.com>.
248
+
249
+ h2. Copyright
250
+
251
+ This software is Copyright (c) 2010 "SoftLayer Technologies, Inc":http://www.softlayer.com/. See the bundled LICENSE.textile file for more information.
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2010, SoftLayer Technologies, Inc. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
5
+ #
6
+ # * Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # * Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ # * Neither SoftLayer Technologies, Inc. nor the names of its contributors may
12
+ # be used to endorse or promote products derived from this software without
13
+ # specific prior written permission.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ # POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ require 'rubygems'
28
+ require 'softlayer_api'
29
+ require 'pp'
30
+
31
+ begin
32
+ # use an account service to get a list of the open tickets and print their IDs and titles
33
+ account_service = SoftLayer::Service.new("SoftLayer_Account",
34
+ :username => "joecustomer" # enter your username here
35
+ :api_key => "feeddeadbeefbadf00d...") # enter your api key here
36
+
37
+ account = account_service.getObject
38
+ pp account
39
+ rescue Exception => exception
40
+ puts "Unable to retrieve account information: #{exception}"
41
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright (c) 2010, SoftLayer Technologies, Inc. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
5
+ #
6
+ # * Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # * Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ # * Neither SoftLayer Technologies, Inc. nor the names of its contributors may
12
+ # be used to endorse or promote products derived from this software without
13
+ # specific prior written permission.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ # POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ require 'rubygems'
28
+ require 'softlayer_api'
29
+ require 'pp'
30
+
31
+ # We're creating more than one service so we'll use the globals to establish
32
+ # the username and API key.
33
+ $SL_API_USERNAME = "joecustomer" # enter your username here
34
+ $SL_API_KEY = "feeddeadbeefbadf00d..." # enter your api key here
35
+
36
+ begin
37
+ # use an account service to get the account ID of my account
38
+ account_service = SoftLayer::Service.new("SoftLayer_Account")
39
+ my_account_id = account_service.getCurrentUser['id']
40
+
41
+ # Use a ticket service to create a standard support ticket, assigned to me.
42
+ ticket_service = SoftLayer::Service.new("SoftLayer_Ticket")
43
+ new_ticket = ticket_service.createStandardTicket(
44
+ {
45
+ "assignedUserId" => my_account_id,
46
+ "subjectId" => 1022,
47
+ "notifyUserOnUpdateFlag" => true
48
+ },
49
+ "This is a test ticket created from a Ruby client")
50
+
51
+ puts "Created a new ticket : #{new_ticket['id']} - #{new_ticket['title']}"
52
+
53
+ # add an update to the newly created ticket.
54
+ pp ticket_service.object_with_id(new_ticket['id']).edit(nil, "This is a ticket update sent from the Ruby library")
55
+ rescue Exception => exception
56
+ $stderr.puts "An exception occurred while trying to complete the SoftLayer API calls #{exception}"
57
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2010, SoftLayer Technologies, Inc. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
5
+ #
6
+ # * Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # * Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ # * Neither SoftLayer Technologies, Inc. nor the names of its contributors may
12
+ # be used to endorse or promote products derived from this software without
13
+ # specific prior written permission.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ # POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ require 'rubygems'
28
+ require 'softlayer_api'
29
+ require 'pp'
30
+
31
+ $SL_API_USERNAME = "joecustomer" # enter your username here
32
+ $SL_API_KEY = "feeddeadbeefbadf00d..." # enter your api key here
33
+
34
+ # use an account service to get a list of the open tickets and print their
35
+ # IDs and titles
36
+ account_service = SoftLayer::Service.new("SoftLayer_Account")
37
+
38
+ open_tickets = account_service.getOpenTickets
39
+ open_tickets.each { |ticket| puts "#{ticket['id']} - #{ticket['title']}" }
40
+
41
+ # Now use the ticket service to get a each ticket (by ID) and a subset of the
42
+ # information known about it. We've already collected this information above,
43
+ # but this will demonstrate using an object mask to filter the results from
44
+ # the server.
45
+ ticket_service = SoftLayer::Service.new("SoftLayer_Ticket")
46
+ open_tickets.each do |ticket|
47
+ begin
48
+ pp ticket_service.object_with_id(ticket["id"]).object_mask( "id", "title", "createDate", "modifyDate", { "assignedUser" => ["id", "username", "email"] }).getObject
49
+ rescue Exception => exception
50
+ puts "exception #{e}"
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2010, SoftLayer Technologies, Inc. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
5
+ #
6
+ # * Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # * Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ # * Neither SoftLayer Technologies, Inc. nor the names of its contributors may
12
+ # be used to endorse or promote products derived from this software without
13
+ # specific prior written permission.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ # POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ require 'rubygems'
28
+ require 'softlayer_api'
29
+ require 'pp'
30
+
31
+ ticket_service = SoftLayer::Service.new("SoftLayer_Ticket",
32
+ :username => "joecustomer", # enter your username here
33
+ :api_key => "feeddeadbeefbadf00d...") # enter your api key here
34
+
35
+ begin
36
+ ticket_ref = ticket_service.object_with_id(1683973)
37
+
38
+ ticket = ticket_ref.object_mask({"updates" => ["entry", "createDate"]},
39
+ "assignedUserId",
40
+ {"attachedHardware" => "datacenter"}).getObject
41
+ pp ticket
42
+ rescue Exception => exception
43
+ puts "Unable to retrieve the ticket"
44
+ end
45
+
46
+ # update the ticket
47
+ begin
48
+ updates = ticket_ref.addUpdate({"entry" => "An update from the Ruby client!"})
49
+ puts "Update ticket 123456. The new update's id is #{updates[0]['id']}"
50
+ rescue Exception => exception
51
+ puts "Unable to update the ticket: #{exception}"
52
+ end