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(data, status_code, headers, response_spec, info) ⇒ Object
Handle downloaded file by copying from temporary location to file_path info.
-
.html_authorizable_id(data, status_code, headers, response_spec, info) ⇒ Object
Parse authorizable ID from response body data.
-
.json_authorizable_id(data, status_code, headers, response_spec, info) ⇒ Object
Handle JSON response payload containing authorizable ID.
-
.json_package_filter(data, status_code, headers, response_spec, info) ⇒ Object
Handle package filter JSON payload.
-
.json_package_service(data, status_code, headers, response_spec, info) ⇒ Object
Handle package JSON payload.
-
.simple(data, status_code, headers, response_spec, info) ⇒ Object
Simple handler by returning result that contains status and message as configured in conf/spec.yaml AS-IS.
-
.xml_package_list(data, status_code, headers, response_spec, info) ⇒ Object
Handle package list XML by removing non-packages data.
Class Method Details
.file_download(data, status_code, headers, response_spec, info) ⇒ Object
Handle downloaded file by copying from temporary location to file_path info. The downloaded file in temporary location will then be deleted. data, status_code, and headers are all returned from RubyAem::Client call.
31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_aem/handlers/file.rb', line 31 def Handlers.file_download(data, status_code, headers, response_spec, info) FileUtils.cp(data.path, "#{info[:file_path]}/#{info[:package_name]}-#{info[:package_version]}.zip") data.delete = response_spec['message'] % info RubyAem::Result.new('success', ) end |
.html_authorizable_id(data, status_code, headers, response_spec, info) ⇒ Object
Parse authorizable ID from response body data. This is used to get the authorizable ID of a newly created user/group.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_aem/handlers/html.rb', line 32 def Handlers.(data, status_code, headers, response_spec, info) html = Nokogiri::HTML(data) = html.xpath('//title/text()').to_s .slice! "Content created #{info[:path]}" info[:authorizable_id] = .sub(/^\//, '') status = response_spec['status'] = response_spec['message'] % info RubyAem::Result.new(status, ) end |
.json_authorizable_id(data, status_code, headers, response_spec, info) ⇒ Object
Handle JSON response payload containing authorizable ID.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_aem/handlers/json.rb', line 31 def Handlers.(data, status_code, headers, response_spec, info) json = JSON.parse(data) = nil if json['success'] == true && json['hits'].length == 1 = json['hits'][0]['name'] info[:authorizable_id] = = response_spec['message'] % info else = "User/Group #{info[:name]} authorizable ID not found" end status = response_spec['status'] result = RubyAem::Result.new(status, ) result.data = result end |
.json_package_filter(data, status_code, headers, response_spec, info) ⇒ Object
Handle package filter JSON payload.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruby_aem/handlers/json.rb', line 76 def Handlers.json_package_filter(data, status_code, headers, response_spec, info) json = JSON.parse(data) filter = [] json.each do |key, value| if json[key]['root'] != nil filter.push(json[key]['root']) end end = response_spec['message'] % info result = RubyAem::Result.new('success', ) result.data = filter result end |
.json_package_service(data, status_code, headers, response_spec, info) ⇒ Object
Handle package JSON payload. Result status is determined directly by success field.
58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_aem/handlers/json.rb', line 58 def Handlers.json_package_service(data, status_code, headers, response_spec, info) json = JSON.parse(data) status = json['success'] == true ? 'success' : 'failure' = json['msg'] RubyAem::Result.new(status, ) end |
.simple(data, status_code, headers, response_spec, info) ⇒ Object
Simple handler by returning result that contains status and message as configured in conf/spec.yaml AS-IS.
32 33 34 35 36 37 38 |
# File 'lib/ruby_aem/handlers/simple.rb', line 32 def Handlers.simple(data, status_code, headers, response_spec, info) status = response_spec['status'] = response_spec['message'] % info RubyAem::Result.new(status, ) end |
.xml_package_list(data, status_code, headers, response_spec, info) ⇒ Object
Handle package list XML by removing non-packages data.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_aem/handlers/xml.rb', line 31 def Handlers.xml_package_list(data, status_code, headers, response_spec, info) xml = Nokogiri::XML(data) 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'] % info result = RubyAem::Result.new('success', ) result.data = xml.xpath('//crx/response/data/packages') else result = RubyAem::Result.new('failure', "Unable to retrieve package list, getting status code #{status_code} and status text #{status_text}") end result end |