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.
-
.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.
29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_aem/handlers/file.rb', line 29 def Handlers.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.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_aem/handlers/html.rb', line 30 def Handlers.(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(/^\//, '') = response_spec['message'] % call_params RubyAem::Result.new(, response) end |
.json_authorizable_id(response, response_spec, call_params) ⇒ Object
Handle JSON response payload containing authorizable ID.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_aem/handlers/json.rb', line 30 def Handlers.(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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby_aem/handlers/json.rb', line 73 def Handlers.json_package_filter(response, response_spec, call_params) json = JSON.parse(response.body) filter = [] json.each do |key, value| if json[key]['root'] != nil filter.push(json[key]['root']) end 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_aem/handlers/json.rb', line 53 def Handlers.json_package_service(response, response_spec, call_params) json = JSON.parse(response.body) = json['msg'] result = RubyAem::Result.new(, response) if json['success'] == true result else raise RubyAem::Error.new(, result) end 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.
31 32 33 34 |
# File 'lib/ruby_aem/handlers/simple.rb', line 31 def Handlers.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.
78 79 80 81 |
# File 'lib/ruby_aem/handlers/simple.rb', line 78 def Handlers.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.
54 55 56 57 58 |
# File 'lib/ruby_aem/handlers/simple.rb', line 54 def Handlers.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.
66 67 68 69 70 |
# File 'lib/ruby_aem/handlers/simple.rb', line 66 def Handlers.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.
42 43 44 45 46 |
# File 'lib/ruby_aem/handlers/simple.rb', line 42 def Handlers.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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_aem/handlers/xml.rb', line 29 def Handlers.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 |