Module: RubyAem::Handlers
- Defined in:
- lib/ruby_aem/handlers/xml.rb,
lib/ruby_aem/handlers/file.rb,
lib/ruby_aem/handlers/html.rb,
lib/ruby_aem/handlers/json.rb,
lib/ruby_aem/handlers/simple.rb
Overview
Response handlers for no payload.
Class Method Summary collapse
-
.file_download(response, response_spec, call_params) ⇒ Object
Handle downloaded file by copying from temporary location to file_path call param.
-
.html_authorizable_id(response, response_spec, call_params) ⇒ Object
Parse authorizable ID from response body data.
-
.html_change_password(response, response_spec, call_params) ⇒ Object
Check response body for indicator of change password failure.
-
.html_package_service_allow_error(response, response_spec, call_params) ⇒ Object
Parse error message from response body data.
-
.json_aem_health_check(response, response_spec, call_params) ⇒ Object
Handle AEM Health Check Servlet JSON payload.
-
.json_agents(response, response_spec, call_params) ⇒ Object
Extract a list of agent names from getAgents JSON payload.
-
.json_authorizable_id(response, response_spec, call_params) ⇒ Object
Handle JSON response payload containing authorizable ID.
-
.json_package_filter(response, response_spec, call_params) ⇒ Object
Handle package filter JSON payload.
-
.json_package_service(response, _response_spec, _call_params) ⇒ Object
Handle package JSON payload.
-
.simple(response, response_spec, call_params) ⇒ Object
Simple handler by returning result that contains status and message as configured in conf/spec.yaml AS-IS.
-
.simple_error(response, response_spec, call_params) ⇒ Object
Simple handler with raised error.
-
.simple_false(response, response_spec, call_params) ⇒ Object
Simple handler with boolean false result data.
-
.simple_nil(response, response_spec, call_params) ⇒ Object
Simple handler with nil result data.
-
.simple_true(response, response_spec, call_params) ⇒ Object
Simple handler with boolean true result data.
-
.xml_package_list(response, response_spec, call_params) ⇒ Object
Handle package list XML by removing non-packages data.
Class Method Details
.file_download(response, response_spec, call_params) ⇒ Object
Handle downloaded file by copying from temporary location to file_path call param. The downloaded file in temporary location will then be deleted. data, status_code, and headers are all returned from RubyAem::Client call.
26 27 28 29 30 31 32 33 |
# File 'lib/ruby_aem/handlers/file.rb', line 26 def self.file_download(response, response_spec, call_params) FileUtils.cp(response.body.path, "#{call_params[:file_path]}/#{call_params[:package_name]}-#{call_params[:package_version]}.zip") response.body.delete = response_spec['message'] % call_params RubyAem::Result.new(, response) end |
.html_authorizable_id(response, response_spec, call_params) ⇒ Object
Parse authorizable ID from response body data. This is used to get the authorizable ID of a newly created user/group.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_aem/handlers/html.rb', line 27 def self.(response, response_spec, call_params) html = Nokogiri::HTML(response.body) = html.xpath('//title/text()').to_s .slice! "Content created #{call_params[:path]}" call_params[:authorizable_id] = .sub(%r{^/}, '') = response_spec['message'] % call_params RubyAem::Result.new(, response) end |
.html_change_password(response, response_spec, call_params) ⇒ Object
Check response body for indicator of change password failure.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby_aem/handlers/html.rb', line 68 def self.html_change_password(response, response_spec, call_params) html = Nokogiri::HTML(response.body) user = html.xpath('//body/div/table/tr/td/b/text()').to_s desc = html.xpath('//body/div/table/tr/td/font/text()').to_s if desc == 'Password successfully changed.' call_params[:user] = user = response_spec['message'] % call_params RubyAem::Result.new(, response) else = desc result = RubyAem::Result.new(, response) raise RubyAem::Error.new(, result) end end |
.html_package_service_allow_error(response, response_spec, call_params) ⇒ Object
Parse error message from response body data. This is to handle AEM hotfix, service pack, and feature pack package installation which might cause AEM to respond with error 500 but it's still processing behind the scene.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_aem/handlers/html.rb', line 47 def self.html_package_service_allow_error(response, response_spec, call_params) html = Nokogiri::HTML(response.body) title = html.xpath('//title/text()').to_s desc = html.xpath('//p/text()').to_s reason = html.xpath('//pre/text()').to_s call_params[:title] = title call_params[:desc] = desc call_params[:reason] = reason = response_spec['message'] % call_params RubyAem::Result.new(, response) end |
.json_aem_health_check(response, response_spec, call_params) ⇒ Object
Handle AEM Health Check Servlet JSON payload.
86 87 88 89 90 91 92 93 94 |
# File 'lib/ruby_aem/handlers/json.rb', line 86 def self.json_aem_health_check(response, response_spec, call_params) json = JSON.parse(response.body) = response_spec['message'] % call_params result = RubyAem::Result.new(, response) result.data = json['results'] result end |
.json_agents(response, response_spec, call_params) ⇒ Object
Extract a list of agent names from getAgents JSON payload.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ruby_aem/handlers/json.rb', line 102 def self.json_agents(response, response_spec, call_params) json = JSON.parse(response.body) agent_names = [] json.each_key do |key| if (!key.start_with? 'jcr:') && (!key.start_with? 'rep:') agent_names.push(key) end end = response_spec['message'] % call_params result = RubyAem::Result.new(, response) result.data = agent_names result end |
.json_authorizable_id(response, response_spec, call_params) ⇒ Object
Handle JSON response payload containing authorizable ID.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_aem/handlers/json.rb', line 27 def self.(response, response_spec, call_params) json = JSON.parse(response.body) = nil if json['success'] == true && json['hits'].length == 1 = json['hits'][0]['name'] call_params[:authorizable_id] = = response_spec['message'] % call_params else = "User/Group #{call_params[:name]} authorizable ID not found" end result = RubyAem::Result.new(, response) result.data = result end |
.json_package_filter(response, response_spec, call_params) ⇒ Object
Handle package filter JSON payload.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_aem/handlers/json.rb', line 65 def self.json_package_filter(response, response_spec, call_params) json = JSON.parse(response.body) filter = [] json.each_key do |key| filter.push(json[key]['root']) unless json[key]['root'].nil? end = response_spec['message'] % call_params result = RubyAem::Result.new(, response) result.data = filter result end |
.json_package_service(response, _response_spec, _call_params) ⇒ Object
Handle package JSON payload. Result status is determined directly by success field.
49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_aem/handlers/json.rb', line 49 def self.json_package_service(response, _response_spec, _call_params) json = JSON.parse(response.body) = json['msg'] result = RubyAem::Result.new(, response) return result if json['success'] == true raise RubyAem::Error.new(, result) end |
.simple(response, response_spec, call_params) ⇒ Object
Simple handler by returning result that contains status and message as configured in conf/spec.yaml AS-IS.
28 29 30 31 |
# File 'lib/ruby_aem/handlers/simple.rb', line 28 def self.simple(response, response_spec, call_params) = response_spec['message'] % call_params RubyAem::Result.new(, response) end |
.simple_error(response, response_spec, call_params) ⇒ Object
Simple handler with raised error.
75 76 77 78 |
# File 'lib/ruby_aem/handlers/simple.rb', line 75 def self.simple_error(response, response_spec, call_params) result = Handlers.simple(response, response_spec, call_params) raise RubyAem::Error.new(result., result) end |
.simple_false(response, response_spec, call_params) ⇒ Object
Simple handler with boolean false result data.
51 52 53 54 55 |
# File 'lib/ruby_aem/handlers/simple.rb', line 51 def self.simple_false(response, response_spec, call_params) result = Handlers.simple(response, response_spec, call_params) result.data = false result end |
.simple_nil(response, response_spec, call_params) ⇒ Object
Simple handler with nil result data.
63 64 65 66 67 |
# File 'lib/ruby_aem/handlers/simple.rb', line 63 def self.simple_nil(response, response_spec, call_params) result = Handlers.simple(response, response_spec, call_params) result.data = nil result end |
.simple_true(response, response_spec, call_params) ⇒ Object
Simple handler with boolean true result data.
39 40 41 42 43 |
# File 'lib/ruby_aem/handlers/simple.rb', line 39 def self.simple_true(response, response_spec, call_params) result = Handlers.simple(response, response_spec, call_params) result.data = true result end |
.xml_package_list(response, response_spec, call_params) ⇒ Object
Handle package list XML by removing non-packages data.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_aem/handlers/xml.rb', line 26 def self.xml_package_list(response, response_spec, call_params) xml = Nokogiri::XML(response.body) status_code = xml.xpath('//crx/response/status/@code').to_s status_text = xml.xpath('//crx/response/status/text()').to_s if status_code == '200' && status_text == 'ok' = response_spec['message'] % call_params result = RubyAem::Result.new(, response) result.data = xml.xpath('//crx/response/data/packages') else result = RubyAem::Result.new("Unable to retrieve package list, getting status code #{status_code} and status text #{status_text}", response) end result end |