Module: StudioApi::StudioResource
- Included in:
- Appliance, Appliance::Configuration, Appliance::Configuration::Firewall, Appliance::GpgKey, Appliance::Repository, Appliance::Status, Build, File, Gallery, Gallery::Appliance, Repository, Rpm, RunningBuild, TemplateSet, Testdrive
- Defined in:
- lib/studio_api/studio_resource.rb
Overview
Adds ability to ActiveResource::Base (short as ARes) to easy set connection to studio in dynamic way, which is not so easy as ARes is designed for static values. Also modify a few expectation of ActiveResource to fit studio API ( like missing xml suffix in calls ).
Class Method Summary collapse
-
.extended(base) ⇒ Object
hooks when module extend and ActiveResource based class.
Instance Method Summary collapse
-
#collection_path(prefix_options = {}, query_options = nil) ⇒ Object
We need to overwrite the paths methods because susestudio doesn’t use the standard .xml filename extension which is expected by ActiveResource.
-
#element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
We need to overwrite the paths methods because susestudio doesn’t use the standard .xml filename extension which is expected by ActiveResource.
-
#studio_connection ⇒ StudioApi::Connection?
Gets studio connection.
-
#studio_connection=(connection) ⇒ StudioApi::Connection
Takes information from connection and sets it to ActiveResource::Base.
Class Method Details
.extended(base) ⇒ Object
hooks when module extend and ActiveResource based class
30 31 32 |
# File 'lib/studio_api/studio_resource.rb', line 30 def self.extended(base) base.format = :xml #fix ARes 3.1 default ( json ) end |
Instance Method Details
#collection_path(prefix_options = {}, query_options = nil) ⇒ Object
We need to overwrite the paths methods because susestudio doesn’t use the standard .xml filename extension which is expected by ActiveResource.
71 72 73 74 |
# File 'lib/studio_api/studio_resource.rb', line 71 def collection_path( = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}#{query_string()}" end |
#element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
We need to overwrite the paths methods because susestudio doesn’t use the standard .xml filename extension which is expected by ActiveResource.
64 65 66 67 |
# File 'lib/studio_api/studio_resource.rb', line 64 def element_path(id, = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}/#{id}#{query_string()}" end |
#studio_connection ⇒ StudioApi::Connection?
Gets studio connection. Mostly useful internally. yet set
24 25 26 |
# File 'lib/studio_api/studio_resource.rb', line 24 def studio_connection @studio_connection end |
#studio_connection=(connection) ⇒ StudioApi::Connection
Takes information from connection and sets it to ActiveResource::Base. Also take care properly of prefix as it need to join path from site with api prefix like appliance/:appliance_id .
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/studio_api/studio_resource.rb', line 40 def studio_connection= connection self.site = connection.uri.to_s # there is general problem, that when specified prefix in model, it doesn't # contain uri.path as it is not know and uri is set during runtime, so we # must add here manually adapt prefix otherwise site.path is ommitted in # models which has own prefix in API unless @original_prefix if self.prefix_source == Util.join_relative_url(connection.uri.path,'/') @original_prefix = "/" else @original_prefix = self.prefix_source end end self.prefix = Util.join_relative_url connection.uri.path, @original_prefix self.user = connection.user self.password = connection.password self.timeout = connection.timeout self.proxy = connection.proxy.to_s if connection.proxy self. = connection.ssl @studio_connection = connection end |