Module: RightScale::Api::GatewayExtend
- Includes:
- BaseExtend, GatewayConnection
- Included in:
- Account, Backup, ChildAccount, Cloud, CloudAccount, InstanceType, McAuditEntry, McDatacenter, McDeployment, McImage, McInstance, McInstanceType, McMultiCloudImage, McMultiCloudImageSetting, McSecurityGroup, McServer, McServerArray, McServerTemplate, McServerTemplateMultiCloudImage, McSshKey, McTag, McVolume, McVolumeAttachment, McVolumeSnapshot, McVolumeType, MonitoringMetric, Permission, SecurityGroupRule, Session, Task, User
- Defined in:
- lib/rest_connection/rightscale/rightscale_api_gateway.rb
Instance Method Summary
collapse
#connection
Methods included from BaseExtend
#[], #deny_methods, #find_by_cloud_id, #find_by_id, #find_by_nickname, #find_by_nickname_speed, #resource_plural_name, #resource_singular_name
#connection
Instance Method Details
#create(*args) ⇒ Object
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 300
def create(*args)
if args.last.is_a?(Hash)
opts = args.pop
else
raise ArgumentError.new("create requires the last argument to be a Hash")
end
url = "#{parse_args(*args)}#{self.resource_plural_name}"
location = connection.post(url, self.resource_post_name.to_sym => opts)
newrecord = self.new('links' => [ {'rel' => 'self', 'href' => location } ])
newrecord.reload
newrecord
end
|
#filters ⇒ Object
291
292
293
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 291
def filters()
[]
end
|
#find(*args) ⇒ Object
238
239
240
241
242
243
244
245
246
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 238
def find(*args)
if args.length > 1
id = args.pop
url = "#{parse_args(*args)}#{self.resource_plural_name}/#{id}"
return self.new(connection.get(url))
else
return super(*args)
end
end
|
#find_all(*args) ⇒ Object
248
249
250
251
252
253
254
255
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 248
def find_all(*args)
a = Array.new
url = "#{parse_args(*args)}#{self.resource_plural_name}"
connection.get(url).each do |object|
a << self.new(object)
end
return a
end
|
#find_by(attrib, *args, &block) ⇒ Object
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 227
def find_by(attrib, *args, &block)
attrib = attrib.to_sym
attrib = :name if attrib == :nickname
if self.filters.include?(attrib)
connection.logger("#{self} includes the filter '#{attrib}', you might be able to speed up this API call")
end
self.find_all(*args).select do |s|
yield(s[attrib.to_s])
end
end
|
#find_with_filter(*args) ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 257
def find_with_filter(*args)
filter_params = []
filter = {}
filter = args.pop if args.last.is_a?(Hash)
filter.each { |key,val|
unless self.filters.include?(key.to_sym)
raise ArgumentError.new("#{key} is not a valid filter for resource #{self.resource_singular_name}")
end
filter_params << "#{key}==#{val}"
}
a = Array.new
url = "#{parse_args(*args)}#{self.resource_plural_name}"
connection.get(url, :filter => filter_params).each do |object|
a << self.new(object)
end
return a
end
|
#load(url) ⇒ Object
275
276
277
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 275
def load(url)
return self.new(connection.get(url))
end
|
#load_all(url) ⇒ Object
279
280
281
282
283
284
285
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 279
def load_all(url)
a = Array.new
connection.get(url).each do |object|
a << self.new(object)
end
return a
end
|
#parse_args ⇒ Object
287
288
289
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 287
def parse_args()
nil
end
|
#resource_post_name ⇒ Object
Hack for McMultiCloudImageSetting class to fix a API quirk
296
297
298
|
# File 'lib/rest_connection/rightscale/rightscale_api_gateway.rb', line 296
def resource_post_name
self.resource_singular_name
end
|