Commit 7a825ff38c4cc0e3703b8e73637a4ca678ea28c3
Committed by
Paulo Meireles
1 parent
a6cc76e4
Exists in
master
and in
28 other branches
[Mezuro] Created Kalibro::ModuleResult from module_result client and entity,
but not fully working
Showing
1 changed file
with
54 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +class Kalibro::ModuleResult < Kalibro::Model | |
| 2 | + | |
| 3 | + attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | |
| 4 | + | |
| 5 | + def self.find_module_result(project_name, module_name, date) | |
| 6 | + result = module_result.request( | |
| 7 | + :get_module_result, | |
| 8 | + { | |
| 9 | + :project_name => project_name, | |
| 10 | + :module_name => module_name, | |
| 11 | + :date => date_with_milliseconds(date) | |
| 12 | + })[:module_result] | |
| 13 | + new result | |
| 14 | + end | |
| 15 | + | |
| 16 | + #FIXME change Kalibro::Entities::Module | |
| 17 | + def module=(value) | |
| 18 | + @module = value.kind_of?(Hash) ? Kalibro::Entities::Module.from_hash(value) : value | |
| 19 | + end | |
| 20 | + | |
| 21 | + def date=(value) | |
| 22 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
| 23 | + end | |
| 24 | + | |
| 25 | + def grade=(value) | |
| 26 | + @grade = value.to_f | |
| 27 | + end | |
| 28 | + | |
| 29 | + #FIXME change Kalibro::Entities::MetricResult | |
| 30 | + def metric_result=(value) | |
| 31 | + array = value.kind_of?(Array) ? value : [value] | |
| 32 | + @metric_result = array.each.collect { |element| element.kind_of?(Hash) ? Kalibro::Entities::MetricResult.from_hash(element) : element } | |
| 33 | + end | |
| 34 | + | |
| 35 | + private | |
| 36 | + | |
| 37 | + def self.module_result | |
| 38 | + endpoint = "ModuleResult" | |
| 39 | + service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | |
| 40 | + Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | |
| 41 | + end | |
| 42 | + | |
| 43 | + def self.request(action, request_body = nil) | |
| 44 | + response = module_result.request(:kalibro, action) { soap.body = request_body } | |
| 45 | + response.to_hash["#{action}_response".to_sym] | |
| 46 | + end | |
| 47 | + | |
| 48 | + def self.date_with_milliseconds(date) | |
| 49 | + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | |
| 50 | + date.to_s[0..18] + milliseconds + date.to_s[19..-1] | |
| 51 | + end | |
| 52 | + | |
| 53 | + | |
| 54 | +end | ... | ... |