dhis2 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +105 -0
- data/Rakefile +10 -0
- data/TODO.md +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dhis2.gemspec +27 -0
- data/lib/base.rb +49 -0
- data/lib/data_element.rb +39 -0
- data/lib/data_set.rb +35 -0
- data/lib/dhis2/version.rb +3 -0
- data/lib/dhis2.rb +47 -0
- data/lib/organisation_unit.rb +14 -0
- data/lib/organisation_unit_level.rb +19 -0
- data/lib/pager.rb +10 -0
- data/lib/paginated_array.rb +11 -0
- data/lib/status.rb +53 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77af2d4ee9db850966b8fe67375be8554acfbe72
|
4
|
+
data.tar.gz: 79a9fccf546c3e1b5d94e85ca17718dcfb520c44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91d423b15b3adcd7371f281b908170ac12a902a408957e18c3b78be32973a3435e1d2479d1c34bd1f0273aea785ece0b368ce183d37291f70529c109b5760065
|
7
|
+
data.tar.gz: 5dafa945e708eea647ec1b097f10c32b6b83d886bab1f33b9f1741ec0f8719490a81f291e0807fbdbfebd066caad95361c1890ba89b1b534efd5ce87471af636
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
AlignHash:
|
4
|
+
# Alignment of entries using hash rocket as separator. Valid values are:
|
5
|
+
#
|
6
|
+
# key - left alignment of keys
|
7
|
+
# 'a' => 2
|
8
|
+
# 'bb' => 3
|
9
|
+
# separator - alignment of hash rockets, keys are right aligned
|
10
|
+
# 'a' => 2
|
11
|
+
# 'bb' => 3
|
12
|
+
# table - left alignment of keys, hash rockets, and values
|
13
|
+
# 'a' => 2
|
14
|
+
# 'bb' => 3
|
15
|
+
EnforcedHashRocketStyle: table
|
16
|
+
# Alignment of entries using colon as separator. Valid values are:
|
17
|
+
#
|
18
|
+
# key - left alignment of keys
|
19
|
+
# a: 0
|
20
|
+
# bb: 1
|
21
|
+
# separator - alignment of colons, keys are right aligned
|
22
|
+
# a: 0
|
23
|
+
# bb: 1
|
24
|
+
# table - left alignment of keys and values
|
25
|
+
# a: 0
|
26
|
+
# bb: 1
|
27
|
+
EnforcedColonStyle: table
|
28
|
+
IfUnlessModifier:
|
29
|
+
MaxLineLength: 100
|
30
|
+
LineLength:
|
31
|
+
Max: 100
|
32
|
+
StringLiterals:
|
33
|
+
EnforcedStyle: double_quotes
|
34
|
+
WhileUntilModifier:
|
35
|
+
MaxLineLength: 100
|
36
|
+
MethodCalledOnDoEndBlock:
|
37
|
+
Description: 'Avoid chaining a method call on a do...end block.'
|
38
|
+
Enabled: true
|
39
|
+
ClassLength:
|
40
|
+
Max: 400
|
41
|
+
Documentation:
|
42
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at martin@joyouscoding.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Martin Van Aken
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Dhis2
|
2
|
+
|
3
|
+
Basic DHIS2 API client for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dhis2', :github => 'BLSQ/dhis2' # not published yet, so get it from github
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dhis2
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Connection
|
24
|
+
|
25
|
+
The functionalities are available as a module. First thing you need to do is to connect to the instance:
|
26
|
+
|
27
|
+
Dhis2.connect(url: "https://play.dhis2.org/demo", user: "admin", password: "district")
|
28
|
+
|
29
|
+
### Search for elements
|
30
|
+
|
31
|
+
All subsequent calls can be done on the object themselves and are going to use the provided url and credentials
|
32
|
+
|
33
|
+
org_unit_levels = Dhis2::OrganisationUnitLevel.list
|
34
|
+
|
35
|
+
The various methods are taking an optional hash parameter to be used for ´filter´ and ´fields´ values:
|
36
|
+
|
37
|
+
org_units = Dhis2::OrganisationUnit.list(filter: "level:eq:2", fields: %w(id level displayName parent))
|
38
|
+
|
39
|
+
If you want all fields, simply specify `:all`
|
40
|
+
|
41
|
+
org_units = Dhis2::OrganisationUnit.list(filter: "level:eq:2", fields: :all)
|
42
|
+
|
43
|
+
Notes that any field found in the resulting JSON will be accessible from the object.
|
44
|
+
|
45
|
+
### Pagination
|
46
|
+
|
47
|
+
Following the DHIS2 API, all calls are paginated - you can access the page info using the `pager` property on the returned list:
|
48
|
+
|
49
|
+
org_units = Dhis2::OrganisationUnit.list(filter: "level:eq:2", fields: %w(id level displayName parent))
|
50
|
+
org_units.pager.page # current page
|
51
|
+
org_units.pager.page_count # number of pages
|
52
|
+
org_units.pager.total # number of records
|
53
|
+
|
54
|
+
### Retreive a single element
|
55
|
+
|
56
|
+
You can also retreive a single element using its id with `find`(in this case, all fields are returned by default):
|
57
|
+
|
58
|
+
ou = Dhis2.Dhis2::OrganisationUnit.find(id)
|
59
|
+
|
60
|
+
If you have an equality condition or set of equality conditions that should return a single element, you can use `find_by` instead of the longer list option:
|
61
|
+
|
62
|
+
# Instead of this:
|
63
|
+
data_element = Dhis2::DataElement.list(filter: "code:eq:C27", fields: :all).first
|
64
|
+
|
65
|
+
# Just do:
|
66
|
+
data_element = Dhis2::DataElement.find_by(code: "C27")
|
67
|
+
|
68
|
+
## Supported features
|
69
|
+
|
70
|
+
The API is currently limited to **read** actions on the following elements:
|
71
|
+
|
72
|
+
* Organisation Units
|
73
|
+
* Organisation Units Levels
|
74
|
+
* Data Elements
|
75
|
+
* Data Sets
|
76
|
+
|
77
|
+
A very basic **write** use case exists for Data Elements and Data Sets:
|
78
|
+
|
79
|
+
elements = [
|
80
|
+
{ name: "TesTesT1", short_name: "TTT1" },
|
81
|
+
{ name: "TesTesT2", short_name: "TTT2" }
|
82
|
+
]
|
83
|
+
status = Dhis2:DataElement.create(elements)
|
84
|
+
status.success? # => true
|
85
|
+
status.total_imported # => 2
|
86
|
+
|
87
|
+
DHIS2 API does not return the ids of the created elements, but you can retreive them with their (unique) name or code.
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. Note that the tests are using the DHIS2 demo server, which is reset every day but can be updated by anyone - so if someone change the password of the default user, the tests are going to fail.
|
92
|
+
|
93
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
94
|
+
|
95
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/BLSQ/dhis2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
104
|
+
|
105
|
+
z
|
data/Rakefile
ADDED
data/TODO.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Improvements
|
2
|
+
|
3
|
+
## Reading
|
4
|
+
|
5
|
+
Convert the CamelCase JSON field names to more Ruby-like snake_case fields.
|
6
|
+
|
7
|
+
Ex: shortName => short_name
|
8
|
+
|
9
|
+
## API Structure
|
10
|
+
|
11
|
+
Have a look to Stripe API to use the objects themselves as starting point:
|
12
|
+
|
13
|
+
data_elements = DataElement.list(filter: "...", fields: [...])
|
14
|
+
data_element = DataElement.find(id)
|
15
|
+
|
16
|
+
This would make the "write/update" API better:
|
17
|
+
|
18
|
+
DataElement.create(name: "", short_name: "")
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dhis2"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dhis2.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dhis2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dhis2"
|
8
|
+
spec.version = Dhis2::VERSION
|
9
|
+
spec.authors = ["Martin Van Aken"]
|
10
|
+
spec.email = ["mvanaken@bluesquare.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple Ruby wrapper on DHIS2 API.}
|
13
|
+
spec.description = %q{Allows to retreive items from a DHIS2 server in a more "Ruby way".}
|
14
|
+
spec.homepage = "http://github.com/blsq/dhis2"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'rest-client'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
end
|
data/lib/base.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Dhis2
|
2
|
+
class Base
|
3
|
+
def initialize(raw_data)
|
4
|
+
@raw_data = raw_data
|
5
|
+
@id = raw_data["id"]
|
6
|
+
@display_name = raw_data["displayName"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(m, *args, &block)
|
10
|
+
return @raw_data[m.to_s] if @raw_data[m.to_s]
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def find(id)
|
16
|
+
response = Dhis2.get_resource("#{resource_name}/#{id}").get
|
17
|
+
json_response = JSON.parse(response)
|
18
|
+
new(json_response)
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_by(clauses)
|
22
|
+
filter = []
|
23
|
+
clauses.each do |field, value|
|
24
|
+
filter << "#{field}:eq:#{value}"
|
25
|
+
end
|
26
|
+
list(fields: :all, filter: filter.join("&")).first
|
27
|
+
end
|
28
|
+
|
29
|
+
def list(options = {})
|
30
|
+
options[:fields] = default_fields if default_fields && !options[:fields]
|
31
|
+
response = Dhis2.get_resource(resource_name, options).get
|
32
|
+
json_response = JSON.parse(response)
|
33
|
+
PaginatedArray.new(
|
34
|
+
json_response[resource_name].map { |raw_org_unit| new(raw_org_unit) },
|
35
|
+
json_response["pager"]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def resource_name
|
40
|
+
simple_name = name.split("::").last
|
41
|
+
simple_name[0].downcase + simple_name[1..-1] + "s"
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_fields
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/data_element.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "base"
|
2
|
+
|
3
|
+
module Dhis2
|
4
|
+
class DataElement < Base
|
5
|
+
attr_reader :id, :display_name
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
super(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def create(elements)
|
13
|
+
elements = [elements].flatten
|
14
|
+
category_combo_id = JSON.parse(Dhis2.resource["categoryCombos"].get)["categoryCombos"]
|
15
|
+
.first["id"]
|
16
|
+
data_element = {
|
17
|
+
dataElements: elements.map do |element|
|
18
|
+
{
|
19
|
+
name: element[:name],
|
20
|
+
shortName: element[:short_name],
|
21
|
+
code: element[:code] || element[:short_name],
|
22
|
+
domainType: element[:domain_type] || "AGGREGATE",
|
23
|
+
valueType: element[:value_type] || "INTEGER_POSITIVE",
|
24
|
+
aggregationType: element[:aggregation_type] || "SUM",
|
25
|
+
categoryCombo: { id: category_combo_id }
|
26
|
+
}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
json_response = Dhis2.resource["metadata"].post(
|
30
|
+
JSON.generate(data_element),
|
31
|
+
content_type: "application/json"
|
32
|
+
)
|
33
|
+
response = JSON.parse(json_response)
|
34
|
+
|
35
|
+
Dhis2::Status.new(response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/data_set.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "base"
|
2
|
+
|
3
|
+
module Dhis2
|
4
|
+
class DataSet < Base
|
5
|
+
def initialize(params)
|
6
|
+
super(params)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def create(sets)
|
11
|
+
sets = [sets].flatten
|
12
|
+
|
13
|
+
data_set = {
|
14
|
+
dataSets: sets.map do |set|
|
15
|
+
{
|
16
|
+
name: set[:name],
|
17
|
+
shortName: set[:short_name],
|
18
|
+
code: set[:code],
|
19
|
+
periodType: "Monthly",
|
20
|
+
dataElements: set[:data_element_ids] ? set[:data_element_ids].map { |id| { id: id } } : [],
|
21
|
+
organisationUnits: set[:organisation_unit_ids] ? set[:organisation_unit_ids].map { |id| { id: id } } : []
|
22
|
+
}
|
23
|
+
end
|
24
|
+
}
|
25
|
+
json_response = Dhis2.resource["metadata"].post(
|
26
|
+
JSON.generate(data_set),
|
27
|
+
content_type: "application/json"
|
28
|
+
)
|
29
|
+
response = JSON.parse(json_response)
|
30
|
+
|
31
|
+
Dhis2::Status.new(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/dhis2.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "dhis2/version"
|
2
|
+
require "rest-client"
|
3
|
+
require "json"
|
4
|
+
require "organisation_unit"
|
5
|
+
require "data_element"
|
6
|
+
require "data_set"
|
7
|
+
require "organisation_unit_level"
|
8
|
+
require "status"
|
9
|
+
require "paginated_array"
|
10
|
+
|
11
|
+
module Dhis2
|
12
|
+
class << self
|
13
|
+
attr_reader :url
|
14
|
+
|
15
|
+
def connect(options)
|
16
|
+
raise "Missing #{url}" unless options[:url]
|
17
|
+
raise "Missing #{user}" unless options[:user]
|
18
|
+
raise "Missing #{password}" unless options[:password]
|
19
|
+
|
20
|
+
@url = options[:url]
|
21
|
+
@user = options[:user]
|
22
|
+
@password = options[:password]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_resource(name, options = {})
|
26
|
+
arguments = []
|
27
|
+
if options[:fields]
|
28
|
+
arguments << "fields=" + options[:fields].join(",") if options[:fields].respond_to?(:join)
|
29
|
+
arguments << "fields=:#{options[:fields]}" if options[:fields].class == Symbol
|
30
|
+
end
|
31
|
+
arguments << "filter=" + options[:filter] if options[:filter]
|
32
|
+
arguments << "pageSize=#{options[:page_size]}" if options[:page_size]
|
33
|
+
arguments << "page=#{options[:page]}" if options[:page]
|
34
|
+
|
35
|
+
path = "#{name}?#{arguments.join('&')}"
|
36
|
+
resource[path]
|
37
|
+
end
|
38
|
+
|
39
|
+
def resource
|
40
|
+
@resource ||= RestClient::Resource.new("#{@url}/api", headers: { accept: "application/json" }, user: @user, password: @password)
|
41
|
+
end
|
42
|
+
|
43
|
+
def camelize(str)
|
44
|
+
str.gsub(/\_([a-z])/, "")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "base"
|
2
|
+
|
3
|
+
module Dhis2
|
4
|
+
class OrganisationUnit < Base
|
5
|
+
attr_reader :id, :display_name, :level, :parent_id, :children_ids
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
super(params)
|
9
|
+
@level = params["level"]
|
10
|
+
@parent_id = params["parent"]["id"] if params["parent"]
|
11
|
+
@children_ids = params["children"] ? params["children"].map { |raw| raw["id"] } : []
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "base"
|
2
|
+
|
3
|
+
module Dhis2
|
4
|
+
class OrganisationUnitLevel < Base
|
5
|
+
attr_reader :id, :name, :level
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
super(params)
|
9
|
+
@name = params["name"]
|
10
|
+
@level = params["level"]
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def default_fields
|
15
|
+
%w(id name level)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/pager.rb
ADDED
data/lib/status.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Dhis2
|
2
|
+
class Status
|
3
|
+
attr_reader :raw_status
|
4
|
+
|
5
|
+
def initialize(raw_status)
|
6
|
+
@raw_status = raw_status
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
@raw_status["importTypeSummaries"].all? { |summary| summary["status"] == "SUCCESS" }
|
11
|
+
end
|
12
|
+
|
13
|
+
def import_count
|
14
|
+
@raw_status["importCount"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_imported
|
18
|
+
total = 0
|
19
|
+
import_count.each do |_, count|
|
20
|
+
total += count
|
21
|
+
end
|
22
|
+
total
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_imported_ids
|
26
|
+
@raw_status["importTypeSummaries"].map { |summary| summary["lastImported"] }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# {
|
32
|
+
# "importCount"=>{
|
33
|
+
# "imported"=>1,
|
34
|
+
# "updated"=>0,
|
35
|
+
# "ignored"=>0,
|
36
|
+
# "deleted"=>0
|
37
|
+
# },
|
38
|
+
# "importTypeSummaries"=>[
|
39
|
+
# {
|
40
|
+
# "responseType"=>"ImportTypeSummary",
|
41
|
+
# "status"=>"SUCCESS",
|
42
|
+
# "importCount"=>
|
43
|
+
# {
|
44
|
+
# "imported"=>1,
|
45
|
+
# "updated"=>0,
|
46
|
+
# "ignored"=>0,
|
47
|
+
# "deleted"=>0
|
48
|
+
# },
|
49
|
+
# "type"=>"DataElement",
|
50
|
+
# "lastImported"=>"lMadHjxdo5q"
|
51
|
+
# }
|
52
|
+
# ]
|
53
|
+
# }
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dhis2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Van Aken
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: Allows to retreive items from a DHIS2 server in a more "Ruby way".
|
70
|
+
email:
|
71
|
+
- mvanaken@bluesquare.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- TODO.md
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- dhis2.gemspec
|
88
|
+
- lib/base.rb
|
89
|
+
- lib/data_element.rb
|
90
|
+
- lib/data_set.rb
|
91
|
+
- lib/dhis2.rb
|
92
|
+
- lib/dhis2/version.rb
|
93
|
+
- lib/organisation_unit.rb
|
94
|
+
- lib/organisation_unit_level.rb
|
95
|
+
- lib/pager.rb
|
96
|
+
- lib/paginated_array.rb
|
97
|
+
- lib/status.rb
|
98
|
+
homepage: http://github.com/blsq/dhis2
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.5.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Simple Ruby wrapper on DHIS2 API.
|
122
|
+
test_files: []
|