Class: Dhis2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dhis2/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/dhis2/client.rb', line 7

def initialize(options)
  @base_url   = options.fetch(:url)
  @version    = options.fetch(:version)
  @verify_ssl = options.fetch(:verify_ssl, OpenSSL::SSL::VERIFY_PEER)
  @timeout    = options.fetch(:timeout, 120)
  @debug      = options.fetch(:debug, false)
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/dhis2/client.rb', line 5

def version
  @version
end

Class Method Details

.uri(base_url, path) ⇒ Object



160
161
162
# File 'lib/dhis2/client.rb', line 160

def self.uri(base_url, path)
  File.join(base_url, API, path)
end

Instance Method Details

#analyticsObject



35
36
37
# File 'lib/dhis2/client.rb', line 35

def analytics
  @analytics ||= CollectionWrapper.new("Analytic", self)
end

#attributesObject



39
40
41
# File 'lib/dhis2/client.rb', line 39

def attributes
  @attributes ||= CollectionWrapper.new("Attribute", self)
end

#can_connect?Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
# File 'lib/dhis2/client.rb', line 151

def can_connect?
  system_infos.get
  true
rescue ::Dhis2::Error
  false
rescue StandardError
  false
end

#categoriesObject



43
44
45
# File 'lib/dhis2/client.rb', line 43

def categories
  @categories ||= CollectionWrapper.new("Category", self)
end

#category_combosObject



51
52
53
# File 'lib/dhis2/client.rb', line 51

def category_combos
  @category_combos ||= CollectionWrapper.new("CategoryCombo", self)
end

#category_option_combosObject



55
56
57
# File 'lib/dhis2/client.rb', line 55

def category_option_combos
  @category_option_combos ||= CollectionWrapper.new("CategoryOptionCombo", self)
end

#category_optionsObject



47
48
49
# File 'lib/dhis2/client.rb', line 47

def category_options
  @category_options ||= CollectionWrapper.new("CategoryOption", self)
end

#complete_data_set_registrationsObject



59
60
61
# File 'lib/dhis2/client.rb', line 59

def complete_data_set_registrations
  @complete_data_set_registrations ||= CollectionWrapper.new("CompleteDataSetRegistration", self)
end

#data_element_groupsObject



67
68
69
# File 'lib/dhis2/client.rb', line 67

def data_element_groups
  @data_element_groups ||= CollectionWrapper.new("DataElementGroup", self)
end

#data_elementsObject



63
64
65
# File 'lib/dhis2/client.rb', line 63

def data_elements
  @data_elements ||= CollectionWrapper.new("DataElement", self)
end

#data_setsObject



71
72
73
# File 'lib/dhis2/client.rb', line 71

def data_sets
  @data_sets ||= CollectionWrapper.new("DataSet", self)
end

#data_value_setsObject



79
80
81
# File 'lib/dhis2/client.rb', line 79

def data_value_sets
  @data_value_sets ||= CollectionWrapper.new("DataValueSet", self)
end

#data_valuesObject



75
76
77
# File 'lib/dhis2/client.rb', line 75

def data_values
  @data_values ||= CollectionWrapper.new("DataValue", self)
end

#delete(path:, query_params: {}, raw: false) ⇒ Object



23
24
25
# File 'lib/dhis2/client.rb', line 23

def delete(path:, query_params: {}, raw: false)
  execute(method_name: :delete, url: uri(path), query_params: query_params, raw: raw)
end

#eventsObject



83
84
85
# File 'lib/dhis2/client.rb', line 83

def events
  @events ||= CollectionWrapper.new("Event", self)
end

#get(path:, query_params: {}, raw: false) ⇒ Object



19
20
21
# File 'lib/dhis2/client.rb', line 19

def get(path:, query_params: {}, raw: false)
  execute(method_name: :get, url: uri(path), query_params: query_params, raw: raw)
end

#indicator_groupsObject



91
92
93
# File 'lib/dhis2/client.rb', line 91

def indicator_groups
  @indicator_groups ||= CollectionWrapper.new("IndicatorGroup", self)
end

#indicator_typesObject



95
96
97
# File 'lib/dhis2/client.rb', line 95

def indicator_types
  @indicator_types ||= CollectionWrapper.new("IndicatorType", self)
end

#indicatorsObject



87
88
89
# File 'lib/dhis2/client.rb', line 87

def indicators
  @indicators ||= CollectionWrapper.new("Indicator", self)
end

#legend_setsObject



99
100
101
# File 'lib/dhis2/client.rb', line 99

def legend_sets
  @legend_sets ||= CollectionWrapper.new("LegendSet", self)
end

#organisation_unit_group_setsObject



111
112
113
# File 'lib/dhis2/client.rb', line 111

def organisation_unit_group_sets
  @organisation_unit_group_sets ||= CollectionWrapper.new("OrganisationUnitGroupSet", self)
end

#organisation_unit_groupsObject



107
108
109
# File 'lib/dhis2/client.rb', line 107

def organisation_unit_groups
  @organisation_unit_groups ||= CollectionWrapper.new("OrganisationUnitGroup", self)
end

#organisation_unit_levelsObject



115
116
117
# File 'lib/dhis2/client.rb', line 115

def organisation_unit_levels
  @organisation_unit_levels ||= CollectionWrapper.new("OrganisationUnitLevel", self)
end

#organisation_unitsObject



103
104
105
# File 'lib/dhis2/client.rb', line 103

def organisation_units
  @organisation_units ||= CollectionWrapper.new("OrganisationUnit", self)
end

#patch(path:, payload:, query_params: {}, raw: false) ⇒ Object



31
32
33
# File 'lib/dhis2/client.rb', line 31

def patch(path:, payload:, query_params: {}, raw: false)
  execute(method_name: :patch, url: uri(path), query_params: query_params, payload: payload, raw: raw)
end

#post(path:, payload: nil, query_params: {}, raw: false, raw_input: false) ⇒ Object



15
16
17
# File 'lib/dhis2/client.rb', line 15

def post(path:, payload: nil, query_params: {}, raw: false, raw_input: false)
  execute(method_name: :post, url: uri(path), query_params: query_params, payload: payload, raw: raw, raw_input: raw_input)
end

#program_indicator_groupsObject



127
128
129
# File 'lib/dhis2/client.rb', line 127

def program_indicator_groups
  @program_indicator_groups ||= CollectionWrapper.new("ProgramIndicatorGroup", self)
end

#program_indicatorsObject



123
124
125
# File 'lib/dhis2/client.rb', line 123

def program_indicators
  @program_indicators ||= CollectionWrapper.new("ProgramIndicator", self)
end

#programsObject



119
120
121
# File 'lib/dhis2/client.rb', line 119

def programs
  @programs ||= CollectionWrapper.new("Program", self)
end

#put(path:, payload:, query_params: {}, raw: false) ⇒ Object



27
28
29
# File 'lib/dhis2/client.rb', line 27

def put(path:, payload:, query_params: {}, raw: false)
  execute(method_name: :put, url: uri(path), query_params: query_params, payload: payload, raw: raw)
end

#report_tablesObject



135
136
137
# File 'lib/dhis2/client.rb', line 135

def report_tables
  @report_tables ||= CollectionWrapper.new("ReportTable", self)
end

#reportsObject



131
132
133
# File 'lib/dhis2/client.rb', line 131

def reports
  @reports ||= CollectionWrapper.new("Report", self)
end

#resource_tablesObject



139
140
141
# File 'lib/dhis2/client.rb', line 139

def resource_tables
  @resource_tables ||= CollectionWrapper.new("ResourceTable", self)
end

#system_infosObject



143
144
145
# File 'lib/dhis2/client.rb', line 143

def system_infos
  @system_infos ||= CollectionWrapper.new("SystemInfo", self)
end

#usersObject



147
148
149
# File 'lib/dhis2/client.rb', line 147

def users
  @users ||= CollectionWrapper.new("User", self)
end