dhis2 2.3.8 → 3.0.0
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 +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/Gemfile +2 -1
- data/README.md +208 -68
- data/Rakefile +4 -2
- data/bin/console +1 -0
- data/changelog.md +7 -0
- data/dhis2.gemspec +8 -8
- data/lib/dhis2/api/base.rb +5 -94
- data/lib/dhis2/api/bulk_creatable.rb +28 -0
- data/lib/dhis2/api/constants.rb +13 -0
- data/lib/dhis2/api/creatable.rb +47 -0
- data/lib/dhis2/api/deletable.rb +12 -0
- data/lib/dhis2/api/event_creation_status.rb +58 -0
- data/lib/dhis2/api/findable.rb +52 -0
- data/lib/dhis2/api/import_summary.rb +61 -0
- data/lib/dhis2/api/listable.rb +78 -0
- data/lib/dhis2/api/query_parameters_formatter.rb +50 -0
- data/lib/dhis2/api/shared/analytic.rb +20 -0
- data/lib/dhis2/api/shared/category_combo.rb +29 -0
- data/lib/dhis2/api/shared/category_option_combo.rb +23 -0
- data/lib/dhis2/api/shared/constants.rb +35 -0
- data/lib/dhis2/api/shared/data_element_group.rb +25 -0
- data/lib/dhis2/api/shared/data_set.rb +22 -0
- data/lib/dhis2/api/shared/data_value.rb +26 -0
- data/lib/dhis2/api/shared/data_value_set.rb +58 -0
- data/lib/dhis2/api/shared/event.rb +54 -0
- data/lib/dhis2/api/shared/organisation_unit.rb +17 -0
- data/lib/dhis2/api/shared/organisation_unit_group.rb +21 -0
- data/lib/dhis2/api/shared/report_tables.rb +32 -0
- data/lib/dhis2/api/shared/resource_table.rb +19 -0
- data/lib/dhis2/api/shared/save_validator.rb +47 -0
- data/lib/dhis2/api/shared/system_info.rb +19 -0
- data/lib/dhis2/api/updatable.rb +33 -0
- data/lib/dhis2/api/version224/analytic.rb +10 -0
- data/lib/dhis2/api/version224/attribute.rb +23 -0
- data/lib/dhis2/api/version224/category_combo.rb +25 -0
- data/lib/dhis2/api/version224/category_option_combo.rb +23 -0
- data/lib/dhis2/api/version224/constants.rb +22 -0
- data/lib/dhis2/api/version224/data_element.rb +45 -0
- data/lib/dhis2/api/version224/data_element_group.rb +22 -0
- data/lib/dhis2/api/version224/data_set.rb +53 -0
- data/lib/dhis2/api/version224/data_value.rb +11 -0
- data/lib/dhis2/api/version224/data_value_set.rb +25 -0
- data/lib/dhis2/api/version224/event.rb +31 -0
- data/lib/dhis2/api/version224/index.rb +27 -0
- data/lib/dhis2/api/version224/indicator.rb +24 -0
- data/lib/dhis2/api/version224/indicator_group.rb +20 -0
- data/lib/dhis2/api/version224/indicator_type.rb +20 -0
- data/lib/dhis2/api/version224/organisation_unit.rb +24 -0
- data/lib/dhis2/api/version224/organisation_unit_group.rb +22 -0
- data/lib/dhis2/api/version224/organisation_unit_group_set.rb +20 -0
- data/lib/dhis2/api/version224/organisation_unit_level.rb +21 -0
- data/lib/dhis2/api/version224/program.rb +26 -0
- data/lib/dhis2/api/version224/report.rb +20 -0
- data/lib/dhis2/api/version224/report_table.rb +21 -0
- data/lib/dhis2/api/version224/resource_table.rb +11 -0
- data/lib/dhis2/api/version224/save_validator.rb +48 -0
- data/lib/dhis2/api/version224/system_info.rb +11 -0
- data/lib/dhis2/api/version224/user.rb +15 -0
- data/lib/dhis2/api/version225/analytic.rb +10 -0
- data/lib/dhis2/api/version225/attribute.rb +23 -0
- data/lib/dhis2/api/version225/category_combo.rb +25 -0
- data/lib/dhis2/api/version225/category_option_combo.rb +23 -0
- data/lib/dhis2/api/version225/constants.rb +22 -0
- data/lib/dhis2/api/version225/data_element.rb +45 -0
- data/lib/dhis2/api/version225/data_element_group.rb +22 -0
- data/lib/dhis2/api/version225/data_set.rb +35 -0
- data/lib/dhis2/api/version225/data_value.rb +11 -0
- data/lib/dhis2/api/version225/data_value_set.rb +25 -0
- data/lib/dhis2/api/version225/event.rb +31 -0
- data/lib/dhis2/api/version225/index.rb +26 -0
- data/lib/dhis2/api/version225/indicator.rb +24 -0
- data/lib/dhis2/api/version225/indicator_group.rb +20 -0
- data/lib/dhis2/api/version225/indicator_type.rb +20 -0
- data/lib/dhis2/api/version225/organisation_unit.rb +24 -0
- data/lib/dhis2/api/version225/organisation_unit_group.rb +22 -0
- data/lib/dhis2/api/version225/organisation_unit_group_set.rb +20 -0
- data/lib/dhis2/api/version225/organisation_unit_level.rb +21 -0
- data/lib/dhis2/api/version225/program.rb +26 -0
- data/lib/dhis2/api/version225/report.rb +20 -0
- data/lib/dhis2/api/version225/report_table.rb +21 -0
- data/lib/dhis2/api/version225/resource_table.rb +11 -0
- data/lib/dhis2/api/version225/system_info.rb +11 -0
- data/lib/dhis2/api/version225/user.rb +15 -0
- data/lib/dhis2/api/version226/analytic.rb +10 -0
- data/lib/dhis2/api/version226/attribute.rb +23 -0
- data/lib/dhis2/api/version226/category_combo.rb +25 -0
- data/lib/dhis2/api/version226/category_option_combo.rb +23 -0
- data/lib/dhis2/api/version226/constants.rb +22 -0
- data/lib/dhis2/api/version226/data_element.rb +42 -0
- data/lib/dhis2/api/version226/data_element_group.rb +22 -0
- data/lib/dhis2/api/version226/data_set.rb +32 -0
- data/lib/dhis2/api/version226/data_value.rb +11 -0
- data/lib/dhis2/api/version226/data_value_set.rb +25 -0
- data/lib/dhis2/api/version226/event.rb +31 -0
- data/lib/dhis2/api/version226/index.rb +26 -0
- data/lib/dhis2/api/version226/indicator.rb +24 -0
- data/lib/dhis2/api/version226/indicator_group.rb +20 -0
- data/lib/dhis2/api/version226/indicator_type.rb +20 -0
- data/lib/dhis2/api/version226/organisation_unit.rb +24 -0
- data/lib/dhis2/api/version226/organisation_unit_group.rb +22 -0
- data/lib/dhis2/api/version226/organisation_unit_group_set.rb +20 -0
- data/lib/dhis2/api/version226/organisation_unit_level.rb +21 -0
- data/lib/dhis2/api/version226/program.rb +24 -0
- data/lib/dhis2/api/version226/report.rb +20 -0
- data/lib/dhis2/api/version226/report_table.rb +21 -0
- data/lib/dhis2/api/version226/resource_table.rb +11 -0
- data/lib/dhis2/api/version226/system_info.rb +11 -0
- data/lib/dhis2/api/version226/user.rb +15 -0
- data/lib/dhis2/api/version227/analytic.rb +10 -0
- data/lib/dhis2/api/version227/attribute.rb +23 -0
- data/lib/dhis2/api/version227/category_combo.rb +25 -0
- data/lib/dhis2/api/version227/category_option_combo.rb +23 -0
- data/lib/dhis2/api/version227/constants.rb +22 -0
- data/lib/dhis2/api/version227/data_element.rb +42 -0
- data/lib/dhis2/api/version227/data_element_group.rb +22 -0
- data/lib/dhis2/api/version227/data_set.rb +32 -0
- data/lib/dhis2/api/version227/data_value.rb +11 -0
- data/lib/dhis2/api/version227/data_value_set.rb +25 -0
- data/lib/dhis2/api/version227/event.rb +31 -0
- data/lib/dhis2/api/version227/index.rb +26 -0
- data/lib/dhis2/api/version227/indicator.rb +24 -0
- data/lib/dhis2/api/version227/indicator_group.rb +20 -0
- data/lib/dhis2/api/version227/indicator_type.rb +20 -0
- data/lib/dhis2/api/version227/organisation_unit.rb +24 -0
- data/lib/dhis2/api/version227/organisation_unit_group.rb +22 -0
- data/lib/dhis2/api/version227/organisation_unit_group_set.rb +20 -0
- data/lib/dhis2/api/version227/organisation_unit_level.rb +21 -0
- data/lib/dhis2/api/version227/program.rb +24 -0
- data/lib/dhis2/api/version227/report.rb +20 -0
- data/lib/dhis2/api/version227/report_table.rb +21 -0
- data/lib/dhis2/api/version227/resource_table.rb +11 -0
- data/lib/dhis2/api/version227/system_info.rb +11 -0
- data/lib/dhis2/api/version227/user.rb +15 -0
- data/lib/dhis2/api/version228/analytic.rb +10 -0
- data/lib/dhis2/api/version228/attribute.rb +23 -0
- data/lib/dhis2/api/version228/category_combo.rb +25 -0
- data/lib/dhis2/api/version228/category_option_combo.rb +23 -0
- data/lib/dhis2/api/version228/constants.rb +22 -0
- data/lib/dhis2/api/version228/data_element.rb +41 -0
- data/lib/dhis2/api/version228/data_element_group.rb +22 -0
- data/lib/dhis2/api/version228/data_set.rb +32 -0
- data/lib/dhis2/api/version228/data_value.rb +11 -0
- data/lib/dhis2/api/version228/data_value_set.rb +25 -0
- data/lib/dhis2/api/version228/event.rb +31 -0
- data/lib/dhis2/api/version228/index.rb +26 -0
- data/lib/dhis2/api/version228/indicator.rb +24 -0
- data/lib/dhis2/api/version228/indicator_group.rb +20 -0
- data/lib/dhis2/api/version228/indicator_type.rb +20 -0
- data/lib/dhis2/api/version228/organisation_unit.rb +24 -0
- data/lib/dhis2/api/version228/organisation_unit_group.rb +22 -0
- data/lib/dhis2/api/version228/organisation_unit_group_set.rb +20 -0
- data/lib/dhis2/api/version228/organisation_unit_level.rb +21 -0
- data/lib/dhis2/api/version228/program.rb +24 -0
- data/lib/dhis2/api/version228/report.rb +20 -0
- data/lib/dhis2/api/version228/report_table.rb +21 -0
- data/lib/dhis2/api/version228/resource_table.rb +11 -0
- data/lib/dhis2/api/version228/system_info.rb +11 -0
- data/lib/dhis2/api/version228/user.rb +15 -0
- data/lib/dhis2/case.rb +46 -0
- data/lib/dhis2/classes.rb +44 -0
- data/lib/dhis2/client.rb +152 -89
- data/lib/dhis2/collection_wrapper.rb +13 -3
- data/lib/dhis2/configuration.rb +55 -1
- data/lib/dhis2/error.rb +19 -0
- data/lib/dhis2/pager.rb +8 -3
- data/lib/dhis2/version.rb +1 -1
- data/lib/dhis2.rb +51 -42
- metadata +168 -50
- data/lib/dhis2/api/analytic.rb +0 -20
- data/lib/dhis2/api/attribute.rb +0 -8
- data/lib/dhis2/api/category_combo.rb +0 -28
- data/lib/dhis2/api/category_option_combo.rb +0 -8
- data/lib/dhis2/api/data_element.rb +0 -34
- data/lib/dhis2/api/data_element_group.rb +0 -32
- data/lib/dhis2/api/data_set.rb +0 -33
- data/lib/dhis2/api/data_value.rb +0 -15
- data/lib/dhis2/api/data_value_set.rb +0 -71
- data/lib/dhis2/api/event.rb +0 -36
- data/lib/dhis2/api/indicator.rb +0 -8
- data/lib/dhis2/api/indicator_group.rb +0 -8
- data/lib/dhis2/api/organisation_unit.rb +0 -66
- data/lib/dhis2/api/organisation_unit_group.rb +0 -38
- data/lib/dhis2/api/organisation_unit_group_set.rb +0 -6
- data/lib/dhis2/api/organisation_unit_level.rb +0 -8
- data/lib/dhis2/api/program.rb +0 -8
- data/lib/dhis2/api/report.rb +0 -8
- data/lib/dhis2/api/report_table.rb +0 -8
- data/lib/dhis2/api/resource_table.rb +0 -14
- data/lib/dhis2/api/system_info.rb +0 -13
- data/lib/dhis2/api/user.rb +0 -8
- data/lib/dhis2/import_error.rb +0 -6
- data/lib/dhis2/status.rb +0 -42
data/lib/dhis2/client.rb
CHANGED
|
@@ -2,126 +2,189 @@
|
|
|
2
2
|
|
|
3
3
|
module Dhis2
|
|
4
4
|
class Client
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
attr_reader :version
|
|
6
|
+
|
|
7
|
+
def initialize(options)
|
|
8
|
+
@base_url = options.fetch(:url)
|
|
9
|
+
@version = options.fetch(:version)
|
|
10
|
+
@verify_ssl = options.fetch(:verify_ssl, OpenSSL::SSL::VERIFY_PEER)
|
|
11
|
+
@timeout = options.fetch(:timeout, 120)
|
|
12
|
+
@debug = options.fetch(:debug, false)
|
|
11
13
|
end
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
raise "unsupported case changes #{type} vs #{SUPPORTER_CASE_CHANGES}" unless SUPPORTER_CASE_CHANGES.include?(type)
|
|
16
|
-
case hash
|
|
17
|
-
when Array
|
|
18
|
-
hash.map { |v| deep_change_case(v, type) }
|
|
19
|
-
when Hash
|
|
20
|
-
new_hash = {}
|
|
21
|
-
hash.each do |k, v|
|
|
22
|
-
new_key = type == :underscore ? underscore(k.to_s) : camelize(k.to_s, false)
|
|
23
|
-
new_hash[new_key] = deep_change_case(v, type)
|
|
24
|
-
end
|
|
25
|
-
new_hash
|
|
26
|
-
else
|
|
27
|
-
hash
|
|
28
|
-
end
|
|
14
|
+
|
|
15
|
+
def post(path:, payload: nil, query_params: {}, raw: false, raw_input: false)
|
|
16
|
+
execute(method_name: :post, url: uri(path), query_params: query_params, payload: payload, raw: raw, raw_input: raw_input)
|
|
29
17
|
end
|
|
30
18
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
-
string.sub(/^[a-z\d]*/) { $&.capitalize }
|
|
34
|
-
else
|
|
35
|
-
string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
|
36
|
-
end
|
|
37
|
-
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }.gsub("/", "::")
|
|
19
|
+
def get(path:, query_params: {}, raw: false)
|
|
20
|
+
execute(method_name: :get, url: uri(path), query_params: query_params, raw: raw)
|
|
38
21
|
end
|
|
39
22
|
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
word = camel_cased_word.to_s.gsub(/::/, "/")
|
|
43
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
|
44
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
|
45
|
-
word.tr!("-", "_")
|
|
46
|
-
word.downcase!
|
|
47
|
-
word
|
|
23
|
+
def delete(path:, query_params: {}, raw: false)
|
|
24
|
+
execute(method_name: :delete, url: uri(path), query_params: query_params, raw: raw)
|
|
48
25
|
end
|
|
49
26
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
@base_url = options
|
|
53
|
-
else
|
|
54
|
-
raise "Missing :url attribute" unless options[:url]
|
|
55
|
-
raise "Missing :user attribute" unless options[:user]
|
|
56
|
-
raise "Missing :password attribute" unless options[:password]
|
|
57
|
-
url = URI.parse(options[:url])
|
|
58
|
-
url.user = CGI.escape(options[:user])
|
|
59
|
-
url.password = CGI.escape(options[:password])
|
|
60
|
-
@base_url = url.to_s
|
|
61
|
-
@verify_ssl = options[:no_ssl_verification] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
|
|
62
|
-
@timeout = options[:timeout] ? options[:timeout].to_i : 120
|
|
63
|
-
@debug = options[:debug] && options[:debug] == true
|
|
64
|
-
end
|
|
27
|
+
def put(path:, payload:, query_params: {}, raw: false)
|
|
28
|
+
execute(method_name: :put, url: uri(path), query_params: query_params, payload: payload, raw: raw)
|
|
65
29
|
end
|
|
66
30
|
|
|
67
|
-
def
|
|
68
|
-
execute(:
|
|
31
|
+
def patch(path:, payload:, query_params: {}, raw: false)
|
|
32
|
+
execute(method_name: :patch, url: uri(path), query_params: query_params, payload: payload, raw: raw)
|
|
69
33
|
end
|
|
70
34
|
|
|
71
|
-
def
|
|
72
|
-
|
|
35
|
+
def analytics
|
|
36
|
+
@analytics ||= CollectionWrapper.new("Analytic", self)
|
|
73
37
|
end
|
|
74
38
|
|
|
75
|
-
def
|
|
76
|
-
|
|
39
|
+
def attributes
|
|
40
|
+
@attributes ||= CollectionWrapper.new("Attribute", self)
|
|
77
41
|
end
|
|
78
42
|
|
|
79
|
-
def
|
|
80
|
-
|
|
43
|
+
def category_combos
|
|
44
|
+
@category_combos ||= CollectionWrapper.new("CategoryCombo", self)
|
|
81
45
|
end
|
|
82
46
|
|
|
83
|
-
def
|
|
84
|
-
|
|
47
|
+
def category_option_combos
|
|
48
|
+
@category_option_combos ||= CollectionWrapper.new("CategoryOptionCombo", self)
|
|
85
49
|
end
|
|
86
50
|
|
|
87
|
-
|
|
51
|
+
def data_elements
|
|
52
|
+
@data_elements ||= CollectionWrapper.new("DataElement", self)
|
|
53
|
+
end
|
|
88
54
|
|
|
89
|
-
def
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
url: url,
|
|
93
|
-
headers: { params: query_params }.merge(headers),
|
|
94
|
-
payload: payload ? self.class.deep_change_case(payload, :camelize).to_json : nil,
|
|
95
|
-
verify_ssl: @verify_ssl,
|
|
96
|
-
timeout: @timeout
|
|
97
|
-
}
|
|
55
|
+
def data_element_groups
|
|
56
|
+
@data_element_groups ||= CollectionWrapper.new("DataElementGroup", self)
|
|
57
|
+
end
|
|
98
58
|
|
|
99
|
-
|
|
59
|
+
def data_sets
|
|
60
|
+
@data_sets ||= CollectionWrapper.new("DataSet", self)
|
|
61
|
+
end
|
|
100
62
|
|
|
101
|
-
|
|
63
|
+
def data_values
|
|
64
|
+
@data_values ||= CollectionWrapper.new("DataValue", self)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def data_value_sets
|
|
68
|
+
@data_value_sets ||= CollectionWrapper.new("DataValueSet", self)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def events
|
|
72
|
+
@events ||= CollectionWrapper.new("Event", self)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def indicators
|
|
76
|
+
@indicators ||= CollectionWrapper.new("Indicator", self)
|
|
77
|
+
end
|
|
102
78
|
|
|
103
|
-
|
|
79
|
+
def indicator_groups
|
|
80
|
+
@indicator_groups ||= CollectionWrapper.new("IndicatorGroup", self)
|
|
81
|
+
end
|
|
104
82
|
|
|
105
|
-
|
|
83
|
+
def indicator_types
|
|
84
|
+
@indicator_types ||= CollectionWrapper.new("IndicatorType", self)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def organisation_units
|
|
88
|
+
@organisation_units ||= CollectionWrapper.new("OrganisationUnit", self)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def organisation_unit_groups
|
|
92
|
+
@organisation_unit_groups ||= CollectionWrapper.new("OrganisationUnitGroup", self)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def organisation_unit_group_sets
|
|
96
|
+
@organisation_unit_group_sets ||= CollectionWrapper.new("OrganisationUnitGroupSet", self)
|
|
97
|
+
end
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
def organisation_unit_levels
|
|
100
|
+
@organisation_unit_levels ||= CollectionWrapper.new("OrganisationUnitLevel", self)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def programs
|
|
104
|
+
@programs ||= CollectionWrapper.new("Program", self)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def reports
|
|
108
|
+
@reports ||= CollectionWrapper.new("Report", self)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def report_tables
|
|
112
|
+
@report_tables ||= CollectionWrapper.new("ReportTable", self)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def resource_tables
|
|
116
|
+
@resource_tables ||= CollectionWrapper.new("ResourceTable", self)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def system_infos
|
|
120
|
+
@system_infos ||= CollectionWrapper.new("SystemInfo", self)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def users
|
|
124
|
+
@users ||= CollectionWrapper.new("User", self)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def can_connect?
|
|
128
|
+
system_infos.get
|
|
129
|
+
true
|
|
130
|
+
rescue ::Dhis2::Error
|
|
131
|
+
false
|
|
132
|
+
rescue StandardError
|
|
133
|
+
false
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def self.uri(base_url, path)
|
|
137
|
+
File.join(base_url, API, path)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
EMPTY_RESPONSES = [nil, ""]
|
|
143
|
+
API = "api"
|
|
144
|
+
TAB = "\t"
|
|
145
|
+
|
|
146
|
+
def execute(method_name:, url:, query_params: {}, payload: nil, raw: false, raw_input: false)
|
|
147
|
+
raw_response = RestClient::Request.execute(
|
|
148
|
+
method: method_name,
|
|
149
|
+
url: url,
|
|
150
|
+
headers: headers(method_name, query_params),
|
|
151
|
+
payload: compute_payload(payload, raw_input),
|
|
152
|
+
verify_ssl: @verify_ssl,
|
|
153
|
+
timeout: @timeout
|
|
154
|
+
)
|
|
155
|
+
response = EMPTY_RESPONSES.include?(raw_response) ? {} : JSON.parse(raw_response)
|
|
156
|
+
log(raw_response.request, response)
|
|
157
|
+
if raw
|
|
158
|
+
response
|
|
159
|
+
else
|
|
160
|
+
Dhis2::Case.deep_change(response, :underscore)
|
|
112
161
|
end
|
|
113
|
-
|
|
162
|
+
rescue RestClient::RequestFailed => e
|
|
163
|
+
exception = ::Dhis2::RequestError.new(e.message)
|
|
164
|
+
exception.response = e.response if e.respond_to?(:response)
|
|
165
|
+
exception.http_code = e.http_code if e.respond_to?(:http_code)
|
|
166
|
+
exception.http_body = e.http_body if e.respond_to?(:http_body)
|
|
167
|
+
raise exception
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def compute_payload(payload, raw_input)
|
|
171
|
+
return nil unless payload
|
|
172
|
+
return payload.to_json if raw_input
|
|
173
|
+
Dhis2::Case.deep_change(payload, :camelize).to_json
|
|
114
174
|
end
|
|
115
175
|
|
|
116
176
|
def uri(path)
|
|
117
|
-
|
|
177
|
+
self.class.uri(@base_url, path)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def headers(method_name, query_params)
|
|
181
|
+
{ params: query_params, accept: :json }.tap do |hash|
|
|
182
|
+
hash[:content_type] = :json unless method_name == :get
|
|
183
|
+
end
|
|
118
184
|
end
|
|
119
185
|
|
|
120
|
-
def
|
|
121
|
-
|
|
122
|
-
content_type: :json,
|
|
123
|
-
accept: :json
|
|
124
|
-
}
|
|
186
|
+
def log(request, response)
|
|
187
|
+
puts [request.url, request.args[:payload], response].join(TAB) if @debug
|
|
125
188
|
end
|
|
126
189
|
end
|
|
127
190
|
end
|
|
@@ -2,14 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module Dhis2
|
|
4
4
|
class CollectionWrapper
|
|
5
|
-
def initialize(
|
|
6
|
-
@klass =
|
|
5
|
+
def initialize(resource_name, client)
|
|
6
|
+
@klass = get_resource_klass(resource_name)[client.version]
|
|
7
7
|
@client = client
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def method_missing(method_name, *args, &block)
|
|
11
11
|
args = args.unshift(@client)
|
|
12
|
-
@klass.
|
|
12
|
+
@klass.public_send(method_name, *args, &block)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def respond_to_missing?(method_name)
|
|
16
|
+
@klass.respond_to? method_name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def get_resource_klass(resource_name)
|
|
22
|
+
Object.const_get "Dhis2::#{resource_name}"
|
|
13
23
|
end
|
|
14
24
|
end
|
|
15
25
|
end
|
data/lib/dhis2/configuration.rb
CHANGED
|
@@ -2,6 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
module Dhis2
|
|
4
4
|
class Configuration
|
|
5
|
-
|
|
5
|
+
ALLOWED_VERSIONS = %w(2.24 2.25 2.26 2.27 2.28).freeze
|
|
6
|
+
|
|
7
|
+
attr_accessor :url, :user, :password, :debug, :no_ssl_verification, :timeout
|
|
8
|
+
|
|
9
|
+
def client_params
|
|
10
|
+
{
|
|
11
|
+
url: no_credentials? ? url : build_url,
|
|
12
|
+
debug: debug,
|
|
13
|
+
version: version,
|
|
14
|
+
timeout: timeout,
|
|
15
|
+
verify_ssl: verify_ssl
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def play_params(with_debug)
|
|
20
|
+
{
|
|
21
|
+
url: "https://admin:district@play.dhis2.org/2.28/",
|
|
22
|
+
debug: with_debug,
|
|
23
|
+
version: "2.28"
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def version=(version)
|
|
28
|
+
raise Dhis2::InvalidVersionError, version.to_s unless ALLOWED_VERSIONS.include?(version)
|
|
29
|
+
@version = version
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def verify_ssl
|
|
35
|
+
if no_ssl_verification
|
|
36
|
+
OpenSSL::SSL::VERIFY_NONE
|
|
37
|
+
else
|
|
38
|
+
OpenSSL::SSL::VERIFY_PEER
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def version
|
|
43
|
+
@version || default_version
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def default_version
|
|
47
|
+
ALLOWED_VERSIONS.last
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def no_credentials?
|
|
51
|
+
user.nil? && password.nil?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def build_url
|
|
55
|
+
URI.parse(url).tap do |url|
|
|
56
|
+
url.user = CGI.escape(user)
|
|
57
|
+
url.password = CGI.escape(password)
|
|
58
|
+
end.to_s
|
|
59
|
+
end
|
|
6
60
|
end
|
|
7
61
|
end
|
data/lib/dhis2/error.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dhis2
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
class BulkCreationError < Error
|
|
6
|
+
attr_accessor :import_summary
|
|
7
|
+
end
|
|
8
|
+
class CreationError < Error; end
|
|
9
|
+
class UpdateError < Error; end
|
|
10
|
+
class PrimaryKeyMissingError < Error; end
|
|
11
|
+
class InvalidRequestError < Error; end
|
|
12
|
+
class CaseError < Error; end
|
|
13
|
+
class InvalidVersionError < Error; end
|
|
14
|
+
class InvalidMethodError < Error; end
|
|
15
|
+
class DataElementAdditionError < Error; end
|
|
16
|
+
class RequestError < Error
|
|
17
|
+
attr_accessor :response, :http_code, :http_body
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/dhis2/pager.rb
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
module Dhis2
|
|
4
4
|
class Pager
|
|
5
|
-
attr_reader :page, :page_count, :total, :next_page
|
|
5
|
+
attr_reader :page, :page_count, :total, :next_page, :page_size
|
|
6
6
|
|
|
7
7
|
def initialize(hash)
|
|
8
8
|
@page = hash["page"]
|
|
9
|
-
@page_count = hash["page_count"]
|
|
9
|
+
@page_count = hash["page_count"] || hash["pageCount"]
|
|
10
10
|
@total = hash["total"]
|
|
11
|
-
@next_page = hash["next_page"]
|
|
11
|
+
@next_page = hash["next_page"] || hash["nextPage"]
|
|
12
|
+
@page_size = hash["page_size"] || hash["pageSize"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def last_page?
|
|
16
|
+
page * page_size >= total
|
|
12
17
|
end
|
|
13
18
|
end
|
|
14
19
|
end
|
data/lib/dhis2/version.rb
CHANGED
data/lib/dhis2.rb
CHANGED
|
@@ -6,64 +6,60 @@ require "ostruct"
|
|
|
6
6
|
require "uri"
|
|
7
7
|
require "delegate"
|
|
8
8
|
require "cgi"
|
|
9
|
+
require "dry-validation"
|
|
9
10
|
|
|
10
11
|
require_relative "dhis2/version"
|
|
12
|
+
require_relative "dhis2/case"
|
|
13
|
+
require_relative "dhis2/error"
|
|
11
14
|
require_relative "dhis2/configuration"
|
|
15
|
+
require_relative "dhis2/classes"
|
|
12
16
|
require_relative "dhis2/collection_wrapper"
|
|
13
17
|
require_relative "dhis2/pager"
|
|
14
18
|
require_relative "dhis2/paginated_array"
|
|
15
|
-
require_relative "dhis2/import_error"
|
|
16
|
-
require_relative "dhis2/status"
|
|
17
19
|
require_relative "dhis2/client"
|
|
18
20
|
|
|
19
21
|
require_relative "dhis2/api/base"
|
|
20
|
-
require_relative "dhis2/api/
|
|
21
|
-
require_relative "dhis2/api/
|
|
22
|
-
require_relative "dhis2/api/
|
|
23
|
-
require_relative "dhis2/api/
|
|
24
|
-
require_relative "dhis2/api/
|
|
25
|
-
require_relative "dhis2/api/
|
|
26
|
-
require_relative "dhis2/api/
|
|
27
|
-
require_relative "dhis2/api/
|
|
28
|
-
require_relative "dhis2/api/
|
|
29
|
-
require_relative "dhis2/api/
|
|
30
|
-
|
|
31
|
-
require_relative "dhis2/api/analytic"
|
|
32
|
-
require_relative "dhis2/api/
|
|
33
|
-
require_relative "dhis2/api/
|
|
34
|
-
require_relative "dhis2/api/
|
|
35
|
-
require_relative "dhis2/api/
|
|
36
|
-
require_relative "dhis2/api/
|
|
37
|
-
require_relative "dhis2/api/
|
|
38
|
-
require_relative "dhis2/api/
|
|
39
|
-
require_relative "dhis2/api/
|
|
40
|
-
require_relative "dhis2/api/
|
|
41
|
-
require_relative "dhis2/api/
|
|
22
|
+
require_relative "dhis2/api/import_summary"
|
|
23
|
+
require_relative "dhis2/api/event_creation_status"
|
|
24
|
+
require_relative "dhis2/api/constants"
|
|
25
|
+
require_relative "dhis2/api/bulk_creatable"
|
|
26
|
+
require_relative "dhis2/api/creatable"
|
|
27
|
+
require_relative "dhis2/api/deletable"
|
|
28
|
+
require_relative "dhis2/api/listable"
|
|
29
|
+
require_relative "dhis2/api/findable"
|
|
30
|
+
require_relative "dhis2/api/updatable"
|
|
31
|
+
require_relative "dhis2/api/query_parameters_formatter"
|
|
32
|
+
|
|
33
|
+
require_relative "dhis2/api/shared/analytic"
|
|
34
|
+
require_relative "dhis2/api/shared/category_combo"
|
|
35
|
+
require_relative "dhis2/api/shared/category_option_combo"
|
|
36
|
+
require_relative "dhis2/api/shared/constants"
|
|
37
|
+
require_relative "dhis2/api/shared/data_element_group"
|
|
38
|
+
require_relative "dhis2/api/shared/data_set"
|
|
39
|
+
require_relative "dhis2/api/shared/data_value"
|
|
40
|
+
require_relative "dhis2/api/shared/data_value_set"
|
|
41
|
+
require_relative "dhis2/api/shared/event"
|
|
42
|
+
require_relative "dhis2/api/shared/organisation_unit"
|
|
43
|
+
require_relative "dhis2/api/shared/organisation_unit_group"
|
|
44
|
+
require_relative "dhis2/api/shared/report_tables"
|
|
45
|
+
require_relative "dhis2/api/shared/resource_table"
|
|
46
|
+
require_relative "dhis2/api/shared/save_validator"
|
|
47
|
+
require_relative "dhis2/api/shared/system_info"
|
|
48
|
+
|
|
49
|
+
require_relative "dhis2/api/version224/index"
|
|
50
|
+
require_relative "dhis2/api/version225/index"
|
|
51
|
+
require_relative "dhis2/api/version226/index"
|
|
52
|
+
require_relative "dhis2/api/version227/index"
|
|
53
|
+
require_relative "dhis2/api/version228/index"
|
|
42
54
|
|
|
43
55
|
module Dhis2
|
|
44
56
|
class << self
|
|
45
57
|
def play(debug = false)
|
|
46
|
-
Dhis2::Client.new(
|
|
47
|
-
url: "https://play.dhis2.org/demo/",
|
|
48
|
-
user: "admin",
|
|
49
|
-
password: "district",
|
|
50
|
-
debug: debug
|
|
51
|
-
)
|
|
58
|
+
Dhis2::Client.new(config.play_params(debug))
|
|
52
59
|
end
|
|
53
60
|
|
|
54
61
|
def client
|
|
55
|
-
|
|
56
|
-
@client ||= if config.user.nil? && config.password.nil?
|
|
57
|
-
Dhis2::Client.new(config.url)
|
|
58
|
-
else
|
|
59
|
-
Dhis2::Client.new(url: config.url,
|
|
60
|
-
user: config.user,
|
|
61
|
-
password: config.password,
|
|
62
|
-
debug: config.debug)
|
|
63
|
-
end
|
|
64
|
-
else
|
|
65
|
-
@client
|
|
66
|
-
end
|
|
62
|
+
@client ||= Dhis2::Client.new(config.client_params)
|
|
67
63
|
end
|
|
68
64
|
|
|
69
65
|
def configure
|
|
@@ -73,5 +69,18 @@ module Dhis2
|
|
|
73
69
|
def config
|
|
74
70
|
@configuration ||= Dhis2::Configuration.new
|
|
75
71
|
end
|
|
72
|
+
|
|
73
|
+
# params: { user: , password:, url: }
|
|
74
|
+
def get_version(params)
|
|
75
|
+
check_config = Dhis2::Configuration.new.tap do |conf|
|
|
76
|
+
conf.url = params.fetch(:url)
|
|
77
|
+
conf.password = params.fetch(:password)
|
|
78
|
+
conf.user = params.fetch(:user)
|
|
79
|
+
end
|
|
80
|
+
response = RestClient.get(
|
|
81
|
+
Dhis2::Client.uri(check_config.client_params[:url], "/system/info")
|
|
82
|
+
)
|
|
83
|
+
JSON.parse(response.body)["version"]
|
|
84
|
+
end
|
|
76
85
|
end
|
|
77
86
|
end
|