kalibro_client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/AUTHORS +4 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/cucumber.yml +1 -0
- data/features/kalibro_configuration/all.feature +10 -0
- data/features/kalibro_configuration/creation.feature +9 -0
- data/features/kalibro_configuration/destroy.feature +10 -0
- data/features/kalibro_configuration/metric_configurations.feature +12 -0
- data/features/metric_collector_details/all_names.feature +8 -0
- data/features/metric_collector_details/find_by_name.feature +12 -0
- data/features/metric_configuration/creation.feature +11 -0
- data/features/metric_configuration/destroy.feature +12 -0
- data/features/metric_configuration/find.feature +18 -0
- data/features/metric_configuration/metric_configurations_of.feature +18 -0
- data/features/metric_result/descendant_values.feature +19 -0
- data/features/metric_result/history_of.feature +20 -0
- data/features/metric_result/metric_results_of.feature +20 -0
- data/features/module_result/children.feature +19 -0
- data/features/module_result/find.feature +22 -0
- data/features/module_result/history_of.feature +19 -0
- data/features/processing/first_processing_after.feature +18 -0
- data/features/processing/first_processing_of.feature +18 -0
- data/features/processing/has_processing.feature +18 -0
- data/features/processing/has_processing_after.feature +18 -0
- data/features/processing/has_processing_before.feature +18 -0
- data/features/processing/has_ready_processing.feature +18 -0
- data/features/processing/last_processing_before.feature +18 -0
- data/features/processing/last_processing_of.feature +18 -0
- data/features/processing/last_processing_state_of.feature +18 -0
- data/features/processing/last_ready_processing_of.feature +19 -0
- data/features/processing/processing_of.feature +32 -0
- data/features/processing/processing_with_date_of.feature +32 -0
- data/features/project/all.feature +10 -0
- data/features/project/creation.feature +9 -0
- data/features/project/destroy.feature +10 -0
- data/features/project/exists.feature +9 -0
- data/features/project/find.feature +10 -0
- data/features/range/destroy.feature +14 -0
- data/features/range/exists.feature +13 -0
- data/features/range/find.feature +14 -0
- data/features/range/ranges_of.feature +22 -0
- data/features/range/save.feature +14 -0
- data/features/reading/destroy.feature +13 -0
- data/features/reading/exists.feature +13 -0
- data/features/reading/find.feature +11 -0
- data/features/reading/readings_of.feature +11 -0
- data/features/reading_group/all.feature +10 -0
- data/features/reading_group/creation.feature +9 -0
- data/features/reading_group/destroy.feature +11 -0
- data/features/repository/all.feature +14 -0
- data/features/repository/cancel_processing.feature +14 -0
- data/features/repository/destroy.feature +14 -0
- data/features/repository/exists.feature +14 -0
- data/features/repository/find.feature +14 -0
- data/features/repository/of.feature +15 -0
- data/features/repository/process.feature +16 -0
- data/features/repository/types.feature +8 -0
- data/features/step_definitions/configuration_steps.rb +40 -0
- data/features/step_definitions/metric_collector_details_steps.rb +28 -0
- data/features/step_definitions/metric_configuration_steps.rb +61 -0
- data/features/step_definitions/metric_result_steps.rb +33 -0
- data/features/step_definitions/metric_steps.rb +3 -0
- data/features/step_definitions/module_result_steps.rb +46 -0
- data/features/step_definitions/processing_steps.rb +95 -0
- data/features/step_definitions/project_steps.rb +48 -0
- data/features/step_definitions/range_steps.rb +72 -0
- data/features/step_definitions/reading_group_steps.rb +36 -0
- data/features/step_definitions/reading_steps.rb +47 -0
- data/features/step_definitions/repository_steps.rb +71 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
- data/kalibro_client.gemspec +49 -0
- data/lib/kalibro_client.rb +62 -0
- data/lib/kalibro_client/entities.rb +40 -0
- data/lib/kalibro_client/entities/base.rb +196 -0
- data/lib/kalibro_client/entities/configurations/base.rb +13 -0
- data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
- data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
- data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
- data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
- data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
- data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
- data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
- data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
- data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
- data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
- data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
- data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
- data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
- data/lib/kalibro_client/entities/processor/base.rb +16 -0
- data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
- data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
- data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
- data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
- data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
- data/lib/kalibro_client/entities/processor/processing.rb +109 -0
- data/lib/kalibro_client/entities/processor/project.rb +34 -0
- data/lib/kalibro_client/entities/processor/repository.rb +75 -0
- data/lib/kalibro_client/errors.rb +18 -0
- data/lib/kalibro_client/errors/record_not_found.rb +22 -0
- data/lib/kalibro_client/errors/standard.rb +24 -0
- data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_client/helpers/request_methods.rb +55 -0
- data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
- data/lib/kalibro_client/version.rb +19 -0
- data/lib/rake/test_task.rb +57 -0
- data/spec/entities/base_spec.rb +313 -0
- data/spec/entities/configurations/base_spec.rb +26 -0
- data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
- data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
- data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
- data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
- data/spec/entities/configurations/reading_group_spec.rb +60 -0
- data/spec/entities/configurations/reading_spec.rb +87 -0
- data/spec/entities/miscellaneous/base_spec.rb +49 -0
- data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
- data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
- data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
- data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
- data/spec/entities/miscellaneous/metric_spec.rb +15 -0
- data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
- data/spec/entities/processor/base_spec.rb +26 -0
- data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
- data/spec/entities/processor/metric_result_spec.rb +209 -0
- data/spec/entities/processor/module_result_spec.rb +178 -0
- data/spec/entities/processor/process_time_spec.rb +33 -0
- data/spec/entities/processor/processing_spec.rb +333 -0
- data/spec/entities/processor/project_spec.rb +68 -0
- data/spec/entities/processor/repository_spec.rb +140 -0
- data/spec/factories/date_metric_results.rb +30 -0
- data/spec/factories/date_module_results.rb +24 -0
- data/spec/factories/granularities.rb +23 -0
- data/spec/factories/kalibro_configurations.rb +34 -0
- data/spec/factories/kalibro_module.rb +28 -0
- data/spec/factories/kalibro_ranges.rb +40 -0
- data/spec/factories/metric_collector_details.rb +30 -0
- data/spec/factories/metric_configurations.rb +31 -0
- data/spec/factories/metric_results.rb +24 -0
- data/spec/factories/metrics.rb +48 -0
- data/spec/factories/models.rb +23 -0
- data/spec/factories/module_results.rb +43 -0
- data/spec/factories/process_times.rb +27 -0
- data/spec/factories/processings.rb +24 -0
- data/spec/factories/projects.rb +35 -0
- data/spec/factories/ranges_snapshot.rb +26 -0
- data/spec/factories/reading_groups.rb +28 -0
- data/spec/factories/readings.rb +30 -0
- data/spec/factories/repositories.rb +39 -0
- data/spec/helpers/aggregation_options_spec.rb +31 -0
- data/spec/helpers/hash_converters_spec.rb +111 -0
- data/spec/helpers/xml_converters_spec.rb +64 -0
- data/spec/kalibro_entities_spec.rb +112 -0
- data/spec/savon/fixtures/config.yml +2 -0
- data/spec/savon/fixtures/invalid_config.yml +2 -0
- data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
- data/spec/savon/savon_test_helper.rb +14 -0
- data/spec/spec_helper.rb +111 -0
- metadata +479 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
require 'yaml'
|
|
18
|
+
require 'logger'
|
|
19
|
+
require "kalibro_client/version"
|
|
20
|
+
require "kalibro_client/errors"
|
|
21
|
+
require "kalibro_client/entities"
|
|
22
|
+
|
|
23
|
+
module KalibroClient
|
|
24
|
+
@config = {
|
|
25
|
+
processor_address: "http://localhost:8082",
|
|
26
|
+
configurations_address: "http://localhost:8083"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@valid_config_keys = @config.keys
|
|
30
|
+
|
|
31
|
+
@logger = Logger.new(STDOUT)
|
|
32
|
+
|
|
33
|
+
# Configure through hash
|
|
34
|
+
def KalibroClient.configure(opts = {})
|
|
35
|
+
opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Configure through yaml file
|
|
39
|
+
def KalibroClient.configure_with(path_to_yaml_file)
|
|
40
|
+
begin
|
|
41
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
|
42
|
+
rescue Errno::ENOENT
|
|
43
|
+
logger.warn("YAML configuration file couldn't be found. Using defaults."); return
|
|
44
|
+
rescue Psych::SyntaxError
|
|
45
|
+
logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
configure(config)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def KalibroClient.config
|
|
52
|
+
@config
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def KalibroClient.logger
|
|
56
|
+
@logger
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def KalibroClient.logger=(logger)
|
|
60
|
+
@logger = logger
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
require 'kalibro_client/entities/base'
|
|
18
|
+
require 'kalibro_client/entities/configurations/base'
|
|
19
|
+
require 'kalibro_client/entities/configurations/kalibro_configuration'
|
|
20
|
+
require 'kalibro_client/entities/configurations/metric_configuration'
|
|
21
|
+
require 'kalibro_client/entities/configurations/kalibro_range'
|
|
22
|
+
require 'kalibro_client/entities/configurations/range_snapshot'
|
|
23
|
+
require 'kalibro_client/entities/configurations/reading'
|
|
24
|
+
require 'kalibro_client/entities/configurations/reading_group'
|
|
25
|
+
require 'kalibro_client/entities/miscellaneous/base'
|
|
26
|
+
require 'kalibro_client/entities/miscellaneous/date_metric_result'
|
|
27
|
+
require 'kalibro_client/entities/miscellaneous/date_module_result'
|
|
28
|
+
require 'kalibro_client/entities/miscellaneous/metric'
|
|
29
|
+
require 'kalibro_client/entities/miscellaneous/granularity'
|
|
30
|
+
require 'kalibro_client/entities/miscellaneous/native_metric'
|
|
31
|
+
require 'kalibro_client/entities/miscellaneous/compound_metric'
|
|
32
|
+
require 'kalibro_client/entities/processor/base'
|
|
33
|
+
require 'kalibro_client/entities/processor/metric_collector_details'
|
|
34
|
+
require 'kalibro_client/entities/processor/metric_result'
|
|
35
|
+
require 'kalibro_client/entities/processor/kalibro_module'
|
|
36
|
+
require 'kalibro_client/entities/processor/module_result'
|
|
37
|
+
require 'kalibro_client/entities/processor/process_time'
|
|
38
|
+
require 'kalibro_client/entities/processor/processing'
|
|
39
|
+
require 'kalibro_client/entities/processor/project'
|
|
40
|
+
require 'kalibro_client/entities/processor/repository'
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
require 'faraday_middleware'
|
|
18
|
+
require 'kalibro_client/helpers/hash_converters'
|
|
19
|
+
require 'kalibro_client/helpers/request_methods'
|
|
20
|
+
|
|
21
|
+
module KalibroClient
|
|
22
|
+
module Entities
|
|
23
|
+
class Base
|
|
24
|
+
attr_accessor :kalibro_errors
|
|
25
|
+
|
|
26
|
+
def initialize(attributes={})
|
|
27
|
+
attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
|
|
28
|
+
@kalibro_errors = []
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_hash(options={})
|
|
32
|
+
hash = Hash.new
|
|
33
|
+
excepts = options[:except].nil? ? [] : options[:except]
|
|
34
|
+
excepts << "kalibro_errors"
|
|
35
|
+
fields.each do |field|
|
|
36
|
+
hash = field_to_hash(field).merge(hash) if !excepts.include?(field)
|
|
37
|
+
end
|
|
38
|
+
hash
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.request(action, params = {}, method = :post, prefix="")
|
|
42
|
+
response = client.send(method) do |request|
|
|
43
|
+
url = "/#{endpoint}/#{action}".gsub(":id", params[:id].to_s)
|
|
44
|
+
url = "/#{prefix}#{url}" unless prefix.empty?
|
|
45
|
+
request.url url
|
|
46
|
+
request.body = params unless params.empty?
|
|
47
|
+
request.options.timeout = 300
|
|
48
|
+
request.options.open_timeout = 300
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
response.body
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.to_object value
|
|
55
|
+
value.kind_of?(Hash) ? new(value) : value
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.to_objects_array value
|
|
59
|
+
array = value.kind_of?(Array) ? value : [value]
|
|
60
|
+
array.each.map { |element| to_object(element) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def save
|
|
64
|
+
begin
|
|
65
|
+
response = self.class.request(save_action, save_params, :post, save_prefix)
|
|
66
|
+
self.id = response[instance_class_name]["id"]
|
|
67
|
+
self.kalibro_errors = response["kalibro_errors"] unless response["kalibro_errors"].nil?
|
|
68
|
+
self.created_at = response[instance_class_name]["created_at"] unless response[instance_class_name]["created_at"].nil?
|
|
69
|
+
self.updated_at = response[instance_class_name]["updated_at"] unless response[instance_class_name]["updated_at"].nil?
|
|
70
|
+
|
|
71
|
+
self.kalibro_errors.empty? ? true : false
|
|
72
|
+
rescue Exception => exception
|
|
73
|
+
add_error exception
|
|
74
|
+
false
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def save!
|
|
79
|
+
save
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def self.create(attributes={})
|
|
83
|
+
new_model = new attributes
|
|
84
|
+
new_model.save
|
|
85
|
+
new_model
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def ==(another)
|
|
89
|
+
unless self.class == another.class
|
|
90
|
+
return false
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
self.variable_names.each do |name|
|
|
94
|
+
next if name == "created_at" or name == "updated_at"
|
|
95
|
+
unless self.send("#{name}") == another.send("#{name}") then
|
|
96
|
+
return false
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
return true
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.exists?(id)
|
|
104
|
+
request(exists_action, id_params(id), :get)['exists']
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def self.find(id)
|
|
108
|
+
if(exists?(id))
|
|
109
|
+
response = request(find_action, id_params(id), :get)
|
|
110
|
+
new response[entity_name]
|
|
111
|
+
else
|
|
112
|
+
raise KalibroClient::Errors::RecordNotFound
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def destroy
|
|
117
|
+
begin
|
|
118
|
+
self.class.request(destroy_action, destroy_params, :delete, destroy_prefix)
|
|
119
|
+
self.kalibro_errors.empty? ? true : false
|
|
120
|
+
rescue Exception => exception
|
|
121
|
+
add_error exception
|
|
122
|
+
false
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def self.create_objects_array_from_hash (response)
|
|
127
|
+
create_array_from_hash(response[entity_name.pluralize]).map { |hash| new hash }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.create_array_from_hash (response)
|
|
131
|
+
response = [] if response.nil?
|
|
132
|
+
response = [response] if response.is_a?(Hash)
|
|
133
|
+
response
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
protected
|
|
137
|
+
|
|
138
|
+
def instance_variable_names
|
|
139
|
+
instance_variables.map { |var| var.to_s }
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def fields
|
|
143
|
+
instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def variable_names
|
|
147
|
+
instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.address
|
|
151
|
+
raise NotImplementedError
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# TODO: probably the connection could be a class static variable.
|
|
155
|
+
def self.client
|
|
156
|
+
Faraday.new(:url => KalibroClient.config[address]) do |conn|
|
|
157
|
+
conn.request :json
|
|
158
|
+
conn.response :json, :content_type => /\bjson$/
|
|
159
|
+
conn.adapter Faraday.default_adapter # make requests with Net::HTTP
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def self.is_valid?(field)
|
|
164
|
+
field.to_s[0] != '@' and field != :attributes! and (field =~ /attributes!/).nil? and (field.to_s =~ /xsi/).nil? and (field.to_s =~ /errors/).nil?
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# TODO rename to instance_entity_name
|
|
168
|
+
def instance_class_name
|
|
169
|
+
self.class.entity_name
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
include RequestMethods
|
|
173
|
+
extend RequestMethods::ClassMethods
|
|
174
|
+
|
|
175
|
+
def add_error(exception)
|
|
176
|
+
@kalibro_errors << exception
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def self.endpoint
|
|
180
|
+
entity_name.pluralize
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def self.entity_name
|
|
184
|
+
# This loop is a generic way to make this work even when the children class has a different name
|
|
185
|
+
entity_class = self
|
|
186
|
+
until entity_class.name.include?("KalibroClient::Entities::") do
|
|
187
|
+
entity_class = entity_class.superclass
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
return entity_class.name.split("::").last.underscore.downcase
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
include HashConverters
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
module KalibroClient
|
|
18
|
+
module Entities
|
|
19
|
+
module Configurations
|
|
20
|
+
class KalibroConfiguration < KalibroClient::Entities::Configurations::Base
|
|
21
|
+
attr_accessor :id, :name, :description
|
|
22
|
+
|
|
23
|
+
def id=(value)
|
|
24
|
+
@id = value.to_i
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.all
|
|
28
|
+
create_objects_array_from_hash(request('', {}, :get))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def metric_configurations
|
|
32
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.create_objects_array_from_hash(self.class.request(':id/metric_configurations', {id: id}, :get))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
module KalibroClient
|
|
18
|
+
module Entities
|
|
19
|
+
module Configurations
|
|
20
|
+
class KalibroRange < KalibroClient::Entities::Configurations::Base
|
|
21
|
+
|
|
22
|
+
attr_accessor :id, :beginning, :end, :reading_id, :comments, :metric_configuration_id
|
|
23
|
+
|
|
24
|
+
def id=(value)
|
|
25
|
+
@id = value.to_i
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reading_id=(value)
|
|
29
|
+
@reading_id = value.to_i
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def beginning=(value)
|
|
33
|
+
@beginning = value == "-INF" ? value : value.to_f
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def end=(value)
|
|
37
|
+
@end = value == "INF" ? value : value.to_f
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def label
|
|
41
|
+
reading.label
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def grade
|
|
45
|
+
reading.grade
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def color
|
|
49
|
+
reading.color
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.ranges_of(metric_configuration_id)
|
|
53
|
+
self.create_objects_array_from_hash(request('', {}, :get, "metric_configurations/#{metric_configuration_id}"))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def reading
|
|
57
|
+
@reading ||= KalibroClient::Entities::Configurations::Reading.find(reading_id)
|
|
58
|
+
@reading
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def save_params
|
|
64
|
+
{kalibro_range: self.to_hash, metric_configuration_id: self.metric_configuration_id}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def save_prefix
|
|
68
|
+
"metric_configurations/#{metric_configuration_id}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def destroy_prefix
|
|
72
|
+
"metric_configurations/#{metric_configuration_id}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
module KalibroClient
|
|
18
|
+
module Entities
|
|
19
|
+
module Configurations
|
|
20
|
+
class MetricConfiguration < KalibroClient::Entities::Configurations::Base
|
|
21
|
+
|
|
22
|
+
attr_accessor :id, :metric, :weight, :aggregation_form, :reading_group_id, :kalibro_configuration_id
|
|
23
|
+
|
|
24
|
+
def id=(value)
|
|
25
|
+
@id = value.to_i
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reading_group_id=(value)
|
|
29
|
+
@reading_group_id = value.to_i
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def kalibro_configuration_id=(value)
|
|
33
|
+
@kalibro_configuration_id = value.to_i
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def metric=(value)
|
|
37
|
+
if value.is_a?(Hash)
|
|
38
|
+
if value['type'] == "NativeMetricSnapshot" || value[:type] == "NativeMetricSnapshot"
|
|
39
|
+
@metric = KalibroClient::Entities::Miscellaneous::NativeMetric.to_object(value)
|
|
40
|
+
elsif value['type'] == "CompoundMetricSnapshot" || value[:type] == "CompoundMetricSnapshot"
|
|
41
|
+
@metric = KalibroClient::Entities::Miscellaneous::CompoundMetric.to_object(value)
|
|
42
|
+
else
|
|
43
|
+
@metric = KalibroClient::Entities::Miscellaneous::Metric.to_object(value)
|
|
44
|
+
end
|
|
45
|
+
elsif value.is_a?(KalibroClient::Entities::Miscellaneous::Metric)
|
|
46
|
+
@metric = value
|
|
47
|
+
else
|
|
48
|
+
raise TypeError.new("Cannot cast #{value.inspect} into Metric")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
return @metric
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def weight=(value)
|
|
55
|
+
@weight = value.to_f
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def update_attributes(attributes={})
|
|
59
|
+
attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
|
|
60
|
+
save
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def to_hash
|
|
64
|
+
super :except => [:configuration_id]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.metric_configurations_of(configuration_id)
|
|
68
|
+
create_objects_array_from_hash(request('', {}, :get, "kalibro_configurations/#{configuration_id}"))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.find(id)
|
|
72
|
+
metric_configuration = request(':id', {id: id}, :get)
|
|
73
|
+
raise KalibroClient::Errors::RecordNotFound unless metric_configuration['error'].nil?
|
|
74
|
+
return new(metric_configuration['metric_configuration'])
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.exists?(id)
|
|
78
|
+
begin
|
|
79
|
+
return true unless find(id).nil?
|
|
80
|
+
rescue KalibroClient::Errors::RecordNotFound
|
|
81
|
+
return false
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def save_params
|
|
88
|
+
{:metric_configuration => self.to_hash, :kalibro_configuration_id => self.kalibro_configuration_id}
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|