Class: BrpdHttpClient
- Inherits:
-
Object
- Object
- BrpdHttpClient
- Defined in:
- lib/brpd_http_client.rb
Instance Method Summary collapse
- #create_package_instance(package, instance_name = nil, properties = nil, locked_status = 'No') ⇒ Object
-
#initialize(integration_settings = BrpmAuto.integration_settings) ⇒ BrpdHttpClient
constructor
A new instance of BrpdHttpClient.
- #parse_response_value(result) ⇒ Object
- #send_xml_request(command, arguments = []) ⇒ Object
Constructor Details
#initialize(integration_settings = BrpmAuto.integration_settings) ⇒ BrpdHttpClient
Returns a new instance of BrpdHttpClient.
9 10 11 12 13 |
# File 'lib/brpd_http_client.rb', line 9 def initialize(integration_settings = BrpmAuto.integration_settings) @url = integration_settings.dns @username = integration_settings.username @password = integration_settings.password end |
Instance Method Details
#create_package_instance(package, instance_name = nil, properties = nil, locked_status = 'No') ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/brpd_http_client.rb', line 15 def create_package_instance(package, instance_name = nil, properties = nil, locked_status='No') raise 'No valid package name/ID provided.' if package.nil? command = locked_status == 'No' ? 'instance create package' : 'instance create locked package' xml_to_hash_response = send_xml_request(command, ["\"#{package}\"", instance_name, properties]) xml_to_hash_response['result'][0]['response'] end |
#parse_response_value(result) ⇒ Object
49 50 51 52 |
# File 'lib/brpd_http_client.rb', line 49 def parse_response_value(result) return unless result['response'] result['response'][0]['value'] end |
#send_xml_request(command, arguments = []) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/brpd_http_client.rb', line 23 def send_xml_request(command, arguments = []) url = "#{@url}/index.php/api/processRequest.xml" request_doc_xml = Builder::XmlMarkup.new request_doc_xml.q(auth: "#{@username} #{@password}") do request_doc_xml.request(command: command) do arguments.each { |arg| request_doc_xml.arg("#{arg}") } end end xml_response = RestClient.post(url, request_doc_xml, content_type: :xml, accept: :xml) xml_to_hash_response = XmlSimple.xml_in(xml_response) result = xml_to_hash_response['result'][0] if result['rc'] != '0' || result['message'] != 'Ok' msg = "Error while posting to URL #{url}: #{result['message']}" response_value = parse_response_value(result) msg += "\nResponse value: #{response_value}" unless response_value.nil? raise msg end xml_to_hash_response end |