Class: StudioApi::Gallery

Inherits:
ActiveResource::Base
  • Object
show all
Extended by:
StudioResource
Defined in:
lib/studio_api/gallery.rb

Defined Under Namespace

Classes: Appliance

Class Method Summary collapse

Methods included from StudioResource

collection_path, element_path, extended, studio_connection, studio_connection=

Class Method Details

.appliance(id, version = nil) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/studio_api/gallery.rb', line 127

def self.appliance id, version = nil
  request_str = "/gallery/appliances/#{id.to_i}"
  request_str << "/version/#{CGI.escape version.to_s}" if version
  response = GenericRequest.new(studio_connection).get request_str
  tree = XmlSimple.xml_in(response,"ForceArray" => ["format","account"])["appliance"]
  Gallery::Appliance.new tree
end

.find_appliance(type, options = {}) ⇒ Object

Searches for appliance with options specified in API help

Parameters:

  • type (#to_s)

    type of search

  • options (Hash[#to_s,#to_s]) (defaults to: {})

    additional options

Returns:

  • TODO

See Also:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/studio_api/gallery.rb', line 111

def self.find_appliance type,options={}
  request_str = "/gallery/appliances?#{CGI.escape type.to_s}"
  request_str = Util.add_options request_str, options, false
  response = GenericRequest.new(studio_connection).get request_str
  tree = XmlSimple.xml_in(response,"ForceArray" => ["appliance"])["appliances"]
  count = tree["pages"].to_i
  page = tree["current_page"].to_i
  appliances = tree["appliance"].reduce([]) do |acc,appl|
    appl.each { |k,v| appl[k] = nil if v.empty? } #avoid empty string, array or hash
    gappl = Gallery::Appliance.dup
    gappl.studio_connection = studio_connection
    acc << gappl.new(appl)
  end
  return :count => count, :page => page, :appliances => appliances
end

.publish_appliance(id, version, release_notes) ⇒ Object



135
136
137
138
# File 'lib/studio_api/gallery.rb', line 135

def self.publish_appliance id, version, release_notes
  request_str = "/gallery/appliances/#{id.to_i}/version/#{CGI.escape version.to_s}"
  response = GenericRequest.new(studio_connection).post request_str, :__raw => release_notes
end