Class: BsaRestClient
- Inherits:
-
Object
- Object
- BsaRestClient
- Defined in:
- lib/bl_rest/bsa_rest_client.rb
Instance Method Summary collapse
- #get_component_by_name(component_name) ⇒ Object
-
#initialize(integration_settings = BrpmAuto.integration_settings) ⇒ BsaRestClient
constructor
A new instance of BsaRestClient.
- #run_query(query) ⇒ Object
Constructor Details
#initialize(integration_settings = BrpmAuto.integration_settings) ⇒ BsaRestClient
Returns a new instance of BsaRestClient.
2 3 4 5 6 7 8 9 |
# File 'lib/bl_rest/bsa_rest_client.rb', line 2 def initialize(integration_settings = BrpmAuto.integration_settings) @url = integration_settings.dns @username = integration_settings.username @password = integration_settings.password @role = integration_settings.details["role"] @api_url = "#{@url}/rest/api/2" end |
Instance Method Details
#get_component_by_name(component_name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bl_rest/bsa_rest_client.rb', line 11 def get_component_by_name(component_name) result = run_query("SELECT * FROM \"SystemObject/Component\" WHERE NAME equals \"#{component_name}\"") raise "BSA component '#{component_name}' not found" if result.empty? result[0] end |
#run_query(query) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bl_rest/bsa_rest_client.rb', line 19 def run_query(query) path = "query?bquery=#{query}" BrpmAuto.log "Running query #{path}..." result = bl_get(path) response = result["response"] if response.has_key? "ErrorResponse" raise "#{response["ErrorResponse"]["Error"]}" end if response["PropertySetClassChildrenResponse"] && response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"] unless response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["PropertySetInstances"]["Elements"].empty? return response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["PropertySetInstances"]["Elements"] end unless response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["Groups"]["Elements"].empty? return response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["Groups"]["Elements"] end unless response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["PropertySetClasses"]["Elements"].empty? return response["PropertySetClassChildrenResponse"]["PropertySetClassChildren"]["PropertySetClasses"]["Elements"] end end [] end |