desmoservice 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2161b9b8e4dadbd49e0fb3821c25d3b90fc8c236
4
+ data.tar.gz: f2df8f17e1d746c270a92ba13f5c9cefd36218ec
5
+ SHA512:
6
+ metadata.gz: 7f67a71402b0765a9c877a0553431d61a6fb993637c23c2ef00e3116347fc2103caba6279c6e28df15d5cb06783f434b484231754d612d0f893dfd567ee46abd
7
+ data.tar.gz: c06871d72b3bf9c35d81d185a84dcc6b7b82715497fb1daceb240c616666b42d07c25d5e11d62ad24330f233112178ce225ba9216af62284e2e6ad5bf0c64491
data/README ADDED
@@ -0,0 +1,3 @@
1
+ Bibliothèque destinée à communiquer avec un serveur Desmoservice :
2
+ -en lecture, transforme les objets JSON en objet Ruby plus facilement manipulables
3
+ -en écriture, aide à la rédaction du fichier XMl d'édition
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'desmoservice'
3
+ s.version = '0.0.0'
4
+ s.date = '2015-09-20'
5
+ s.license = 'Ruby'
6
+ s.summary = 'Read and write access to Desmoservice API'
7
+ s.description = 'Manage the connection to Desmoservice server, convert JSON to ruby objects and build XML for edition'
8
+ s.author = 'Vincent Calame'
9
+ s.email = 'vincent.calame@exemole.fr'
10
+ s.platform = Gem::Platform::RUBY
11
+ s.required_ruby_version = '>=2.0'
12
+ s.files = Dir['**/**']
13
+ s.homepage = 'https://github.com/vcalame/desmoservice'
14
+ end
data/lib/conf.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'uri'
2
+
3
+ module Desmoservice
4
+ class Conf
5
+
6
+ attr_reader :service_url, :desmo_name, :lang, :dsmd_script
7
+
8
+ def initialize(service_url: nil, desmo_name: nil, lang: nil, dsmd_script: nil)
9
+ raise "Missing service_url" if service_url.nil?
10
+ raise "Missing desmo_name" if desmo_name.nil?
11
+ raise "Missing lang" if lang.nil?
12
+ if service_url[-1] != "/"
13
+ service_url << "/"
14
+ end
15
+ @service_url = service_url
16
+ @desmo_name = desmo_name
17
+ @lang = lang
18
+ @dsmd_script = dsmd_script
19
+ end
20
+
21
+ def build_json_uri(parameters=nil)
22
+ map = {"desmo" => @desmo_name, "lang" => @lang}
23
+ if not parameters.nil?
24
+ map.merge!(parameters)
25
+ end
26
+ map.delete_if { |k, v| v.nil? }
27
+ uri = URI(@service_url + 'json')
28
+ uri.query = URI.encode_www_form(map)
29
+ return uri
30
+ end
31
+
32
+ def build_edition_uri
33
+ return URI(@service_url + 'edition?desmo=' + @desmo_name)
34
+ end
35
+
36
+ def build_dsmd_url
37
+ dsmd_url = @service_url + "export/" + @desmo_name + "_" + @lang + ".dsmd"
38
+ if @dsmd_script
39
+ dsmd_url += "?script=" + @dsmd_script
40
+ end
41
+ return dsmd_url
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,14 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require_relative 'conf'
4
+ require_relative 'families'
5
+ require_relative 'ventilation'
6
+ require_relative 'term'
7
+ require_relative 'family'
8
+ require_relative 'sector'
9
+ require_relative 'word_distribution'
10
+ require_relative 'get'
11
+ require_relative 'get_params'
12
+ require_relative 'edition'
13
+ require_relative 'post'
14
+ require_relative 'log_handler'
data/lib/edition.rb ADDED
@@ -0,0 +1,144 @@
1
+ require 'rack/utils'
2
+
3
+ module Desmoservice
4
+ class Edition
5
+
6
+ def initialize
7
+ @xml = '<edition>'
8
+ end
9
+
10
+ def close_to_xml
11
+ @xml << '</edition>'
12
+ return @xml
13
+ end
14
+
15
+ #arg peut être un entier (id) ou une chaine (localkey)
16
+ def link_creation(down_arg=nil)
17
+ @xml << '<lienhierarchique-creation'
18
+ Edition.to_attribute(@xml, down_arg, 'fils')
19
+ @xml << '>'
20
+ yield(LinkCreation.new(@xml))
21
+ @xml << '</lienhierarchique-creation>'
22
+ end
23
+
24
+ def term_change(term_arg)
25
+ @xml << '<terme-change'
26
+ Edition.to_attribute(@xml, term_arg)
27
+ @xml << '>'
28
+ yield(TermChange.new(@xml))
29
+ @xml << '</terme-change>'
30
+ end
31
+
32
+ def self.to_attribute(xml, term_arg, suffix=nil)
33
+ if term_arg.is_a? Integer
34
+ xml << ' '
35
+ if suffix.nil?
36
+ xml << 'code' << '="' << term_arg.to_s << '"'
37
+ else
38
+ xml << suffix << '="' << term_arg.to_s << '"'
39
+ end
40
+ elsif not term_arg.nil?
41
+ xml << ' '
42
+ if suffix.nil?
43
+ xml << 'iddesc' << '="' << term_arg.to_s << '"'
44
+ else
45
+ xml << suffix << '-iddesc="' << term_arg.to_s << '"'
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.family(xml, family_arg)
51
+ xml << '<famille '
52
+ if family_arg.is_a? Integer
53
+ xml << 'code' << '="' << family_arg.to_s << '"'
54
+ else
55
+ xml << 'idctxt' << '="' << family_arg << '"'
56
+ end
57
+ xml << '/>'
58
+ end
59
+
60
+ def self.text(xml, lang, content)
61
+ if content.nil?
62
+ xml << '<lib-remove xml:lang="' << lang << '"/>'
63
+ else
64
+ xml << '<lib xml:lang="' << lang << '">'
65
+ xml << Rack::Utils.escape_html(content)
66
+ xml << '</lib>'
67
+ end
68
+ end
69
+
70
+ def self.attr(xml, attr_key, values)
71
+ index = attr_key.index(':')
72
+ ns = attr_key[0,index]
73
+ localkey = attr_key[index+1..-1]
74
+ if values.nil?
75
+ xml << '<attr-remove ns="' << ns << '" key="' << localkey << '"/>'
76
+ else
77
+ xml << '<attr ns="' << ns << '" key="' << localkey << '">'
78
+ if values.is_a? String
79
+ xml << '<val>' << Rack::Utils.escape_html(values) << '</val>'
80
+ else
81
+ values.each do |v|
82
+ xml << '<val>' << Rack::Utils.escape_html(v) << '</val>'
83
+ end
84
+ end
85
+ xml << '</attr>'
86
+ end
87
+ end
88
+ end
89
+
90
+ class LinkCreation
91
+
92
+ def initialize(xml)
93
+ @xml = xml
94
+ end
95
+
96
+ def up(up_arg, context_arg=nil)
97
+ @xml << '<pere'
98
+ Edition.to_attribute(@xml, up_arg)
99
+ if not context_arg.nil?
100
+ if context_arg.is_a? Integer
101
+ @xml << ' contexte="' << context_arg.to_s << '"'
102
+ else
103
+ index = context_arg.index('/')
104
+ @xml << ' contexte-grille="' << context_arg[0,index] << '"'
105
+ @xml << ' contexte-idctxt="' << context_arg[index+1..-1] << '"'
106
+ end
107
+ end
108
+ @xml << '/>'
109
+ end
110
+
111
+ def family(family_arg)
112
+ Edition.family(@xml, family_arg)
113
+ end
114
+
115
+ def text(lang, content)
116
+ Edition.text(@xml, lang, content)
117
+ end
118
+
119
+ def attr(attr_key, values)
120
+ Edition.attr(@xml, attr_key, values)
121
+ end
122
+ end
123
+
124
+ class TermChange
125
+
126
+ def initialize(xml)
127
+ @xml = xml
128
+ end
129
+
130
+ def family(family_arg)
131
+ Edition.family(@xml, family_arg)
132
+ end
133
+
134
+ def text(lang, content)
135
+ Edition.text(@xml, lang, content)
136
+ end
137
+
138
+ def attr(attr_key, values)
139
+ Edition.attr(@xml, attr_key, values)
140
+ end
141
+
142
+ end
143
+
144
+ end
data/lib/families.rb ADDED
@@ -0,0 +1,40 @@
1
+ module Desmoservice
2
+ class Families
3
+ include Enumerable
4
+
5
+ attr_reader :orphan_terms
6
+
7
+ def initialize()
8
+ @array = Array.new
9
+ @orphan_members = Array.new
10
+ end
11
+
12
+ def parse_json(json_string)
13
+ data = JSON.parse(json_string)
14
+ if data.has_key?('familles')
15
+ familles = data['familles']
16
+ if familles.has_key?('familleArray')
17
+ familles['familleArray'].each {|v| @array << Family.new(v)}
18
+ end
19
+ if familles.has_key?('sansfamille')
20
+ familles['descripteurArray'].each {|v| @orphan_terms << Term.new(v)}
21
+ end
22
+ end
23
+ end
24
+
25
+ def each
26
+ @array.each do |v|
27
+ yield(v)
28
+ end
29
+ end
30
+
31
+ def length
32
+ return @array.length
33
+ end
34
+
35
+ def [](index)
36
+ return @array[index]
37
+ end
38
+
39
+ end
40
+ end
data/lib/family.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Desmoservice
2
+
3
+ class Family < Term
4
+
5
+ attr_reader :members, :subfamilies
6
+
7
+ def initialize(data)
8
+ super(data['terme'])
9
+ @subfamilies = Array.new
10
+ @members = Array.new
11
+ if data.has_key?('descripteurArray')
12
+ data['descripteurArray'].each {|v| @members << Term.new(v)}
13
+ end
14
+ if data.has_key?('familleArray')
15
+ data['familleArray'].each {|v| @subfamilies << Family.new(v)}
16
+ end
17
+
18
+ end
19
+
20
+ def active?
21
+ return true
22
+ end
23
+ end
24
+
25
+ end
data/lib/get.rb ADDED
@@ -0,0 +1,53 @@
1
+ module Desmoservice
2
+ class Get
3
+
4
+ def initialize
5
+ end
6
+
7
+ def self.families(desmoservice_conf, get_params, http=nil)
8
+ options = get_params.to_h('familles')
9
+ uri = desmoservice_conf.build_json_uri(options)
10
+ if http.nil?
11
+ json_string = Net::HTTP.get(uri)
12
+ else
13
+ request = Net::HTTP::Get.new(uri)
14
+ response = http.request(request)
15
+ json_string = response.body
16
+ end
17
+ families = Families.new()
18
+ families.parse_json(json_string)
19
+ return families
20
+ end
21
+
22
+ def self.ventilation(desmoservice_conf, get_params, http=nil)
23
+ options = get_params.to_h('ventilation')
24
+ uri = desmoservice_conf.build_json_uri(options)
25
+ if http.nil?
26
+ json_string = Net::HTTP.get(uri)
27
+ else
28
+ request = Net::HTTP::Get.new(uri)
29
+ response = http.request(request)
30
+ json_string = response.body
31
+ end
32
+ ventilation = Ventilation.new()
33
+ ventilation.parse_json(json_string)
34
+ return ventilation
35
+ end
36
+
37
+ def self.word_distribution(desmoservice_conf, get_params, http=nil)
38
+ options = get_params.to_h('lexiedistribution')
39
+ uri = desmoservice_conf.build_json_uri(options)
40
+ if http.nil?
41
+ json_string = Net::HTTP.get(uri)
42
+ else
43
+ request = Net::HTTP::Get.new(uri)
44
+ response = http.request(request)
45
+ json_string = response.body
46
+ end
47
+ word_distribution = WordDistribution.new()
48
+ word_distribution.parse_json(json_string)
49
+ return word_distribution
50
+ end
51
+ end
52
+
53
+ end
data/lib/get_params.rb ADDED
@@ -0,0 +1,67 @@
1
+ module Desmoservice
2
+ class GetParams
3
+
4
+ attr_accessor :with_keys, :with_attrs,
5
+ :family_filter,
6
+ :ventilation_root_id, :ventilation_root_uri, :ventilation_name,
7
+ :ignore_empty_sectors
8
+
9
+
10
+ def initialize()
11
+ @with_keys = true
12
+ @with_attrs = false
13
+ @ventilation_root_id = nil
14
+ @ventilation_root_uri = nil
15
+ @ignore_empty_sectors = nil
16
+ @ventilation_name = 'ventilation:naturelle'
17
+ end
18
+
19
+ def to_h(type)
20
+ result = Hash.new
21
+ result['type'] = type
22
+ fields = 'libelles,famille-color'
23
+ fields += ',idctxt,iddesc,grille-name' if @with_keys
24
+ fields += ',attrs' if @with_attrs
25
+ result['fields'] = fields
26
+ if not @family_filter.nil?
27
+ if type == 'ventilation'
28
+ options['conf:limitation.familles.idctxtarray'] = @family_filter
29
+ else
30
+ result['selection_idctxt'] = @family_filter
31
+ end
32
+ end
33
+ if not @ignore_empty_sectors.nil?
34
+ if @ignore_empty_sectors
35
+ result['conf:ignore.empty.secteur'] = 'true'
36
+ else
37
+ result['conf:ignore.empty.secteur'] = 'false'
38
+ end
39
+ end
40
+ if type == 'ventilation'
41
+ if not @ventilation_root_id.nil?
42
+ result['root_code'] = @ventilation_root_id
43
+ elsif not @ventilation_root_uri.nil?
44
+ result['root_uri'] = @ventilation_root_uri
45
+ end
46
+ if not @ventilation_name.nil?
47
+ result['name'] = @ventilation_name
48
+ end
49
+ end
50
+ return result
51
+ end
52
+
53
+ def ventilation_name_uri=(uri)
54
+ @ventilation_name = 'ventilation:' + uri
55
+ end
56
+
57
+ def ventilation_name_context=(localkey)
58
+ index = localkey.index('/')
59
+ if index.nil?
60
+ @ventilation_name = 'ventilation:grille:' + localkey
61
+ else
62
+ @ventilation_name = 'ventilation:contexte:' + localkey
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ module Desmoservice
2
+ class LogHandler
3
+
4
+ attr_reader :destination
5
+
6
+ def initialize(destination)
7
+ @destination = destination
8
+
9
+ end
10
+
11
+ def add_log_message(log_message)
12
+ destination << log_message << "\n"
13
+ end
14
+
15
+ end
16
+
17
+ end
data/lib/post.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+
3
+ module Desmoservice
4
+ class Post
5
+
6
+ def initialize
7
+ end
8
+
9
+ def self.xml(desmoservice_conf, xml, log_handler=nil, http=nil)
10
+ uri = desmoservice_conf.build_edition_uri
11
+ if http.nil?
12
+ response = Net::HTTP.post_form(uri, 'desmo' => desmoservice_conf.desmo_name, 'xml' => xml)
13
+ response_body = response.body
14
+ else
15
+ request = Net::HTTP::Post.new(uri)
16
+ request.set_form_data('desmo' => desmoservice_conf.desmo_name, 'xml' => xml)
17
+ response =http.request(request)
18
+ response_body = response.body
19
+ end
20
+ if not log_handler.nil?
21
+ json = JSON.parse(response_body)
22
+ if json.has_key?('error')
23
+ error = json['error']
24
+ message= "[[RequestParams]]\n [" + error['key']
25
+ if error.has_key?('parameter')
26
+ message += ' / ' + error['parameter']
27
+ end
28
+ message += ']'
29
+ if error.has_key?('value')
30
+ message += ' ' + error['value']
31
+ end
32
+ log_handler.add_log_message(message)
33
+ end
34
+ if json.has_key?('log')
35
+ log_handler.add_log_message(json['log'])
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
data/lib/sector.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Desmoservice
2
+
3
+ class Sector < Term
4
+
5
+ attr_reader :subsectors, :members
6
+
7
+ def initialize(data)
8
+ super(data['terme'])
9
+ @members = Array.new
10
+ if data.has_key?('liaisonArray')
11
+ data['liaisonArray'].each {|v| @members << SectorTerm.new(v)}
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ class SectorTerm < Term
18
+
19
+ attr_reader :position
20
+
21
+ def initialize(data)
22
+ super(data['terme'])
23
+ @position = data['position']
24
+ end
25
+
26
+ end
27
+
28
+ end
data/lib/term.rb ADDED
@@ -0,0 +1,62 @@
1
+ module Desmoservice
2
+
3
+ class Term
4
+ attr_reader :id, :localkey, :text, :color, :attrs
5
+
6
+ def initialize(data)
7
+ @id = data['code']
8
+ @localkey = if data.has_key?('iddesc')
9
+ data['iddesc']
10
+ elsif data.has_key?('idctxt')
11
+ data['idctxt']
12
+ else
13
+ nil
14
+ end
15
+ @text = nil
16
+ if data.has_key?('libelles')
17
+ if data['libelles'].length > 0
18
+ @text = data['libelles'][0]['lib']
19
+ end
20
+ end
21
+ @color = nil
22
+ if data.has_key?('familleColor')
23
+ @color = data['familleColor']
24
+ end
25
+ @attrs = nil
26
+ if data.has_key?('attrs')
27
+ @attrs = data['attrs']
28
+ end
29
+ end
30
+
31
+ def localkey?
32
+ return !@localkey.nil?
33
+ end
34
+
35
+ def text?
36
+ return !@text.nil?
37
+ end
38
+
39
+ def color?
40
+ return !@color.nil?
41
+ end
42
+
43
+ def has_attr?
44
+ if @attrs.nil?
45
+ return false
46
+ else
47
+ return @attrs.has_key?(key)
48
+ end
49
+ end
50
+
51
+ def [](key)
52
+ if @attrs.nil?
53
+ return nil
54
+ elsif !@attrs.has_key?(key)
55
+ return nil
56
+ else
57
+ return @attrs[key]
58
+ end
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,24 @@
1
+ module Desmoservice
2
+ class Ventilation
3
+
4
+ attr_reader :root, :sectors
5
+
6
+ def initialize
7
+ @sectors = Array.new
8
+ end
9
+
10
+ def parse_json(json_string)
11
+ data = JSON.parse(json_string)
12
+ if data.has_key?('ventilation')
13
+ ventilation = data['ventilation']
14
+ if ventilation.has_key?('secteurArray')
15
+ ventilation['secteurArray'].each {|v| @sectors << Sector.new(v)}
16
+ end
17
+ if ventilation.has_key?('root')
18
+ @root = Term.new(ventilation['root'])
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,71 @@
1
+ module Desmoservice
2
+ class WordDistribution
3
+
4
+ attr_reader :words, :tagged_terms
5
+
6
+ def initialize
7
+ @words = Hash.new
8
+ @tagged_terms = Hash.new
9
+ end
10
+
11
+ def parse_json(json_string)
12
+ data = JSON.parse(json_string)
13
+ if data.has_key?('lexiedistribution')
14
+ if data['lexiedistribution'].has_key?('lexieArray')
15
+ data['lexiedistribution']['lexieArray'].each do |v|
16
+ word = Word.new(v['id'], v['value'])
17
+ v['codeArray'].each {|id| word.term_ids << id}
18
+ @words[word.id] = word
19
+ end
20
+ end
21
+ if data['lexiedistribution'].has_key?('sourceMap')
22
+ data['lexiedistribution']['sourceMap'].each_value do |v|
23
+ tagged_term = TaggedTerm.new(v)
24
+ @tagged_terms[tagged_term.id] = tagged_term
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ class Word
33
+
34
+ attr_reader :id, :value, :term_ids
35
+
36
+ def initialize(id, value)
37
+ @id = id
38
+ @value = value
39
+ @term_ids = Array.new
40
+ end
41
+ end
42
+
43
+ class TaggedTerm < Term
44
+
45
+ attr_reader :tagged_parts
46
+
47
+ def initialize(data)
48
+ super(data['descripteur'])
49
+ @tagged_parts = Array.new
50
+ data['text'].each do |v|
51
+ if v.respond_to?('has_key?')
52
+ @tagged_parts << TaggedPart.new(v['lexie'], v['value'])
53
+ else
54
+ @tagged_parts << TaggedPart.new(nil, v)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ class TaggedPart
62
+
63
+ attr_reader :word_id, :value
64
+
65
+ def initialize(word_id, value)
66
+ @word_id = word_id
67
+ @value = value
68
+ end
69
+
70
+ end
71
+ end
data/test/test_conf.rb ADDED
@@ -0,0 +1,27 @@
1
+ require_relative '../lib/desmoservice'
2
+ require 'minitest/autorun'
3
+
4
+ class TestConf < Minitest::Test
5
+
6
+ def setup
7
+ @conf = Desmoservice::Conf.new({
8
+ service_url: 'http://bases.fichotheque.net:8080/exemole/ext/fr-exemole-desmoservice',
9
+ desmo_name: 'citego',
10
+ lang: 'fr',
11
+ dsmd_script: 'niveau1_par_dimension'
12
+ })
13
+ end
14
+
15
+ def test_url_building
16
+ assert_equal(
17
+ 'http://bases.fichotheque.net:8080/exemole/ext/fr-exemole-desmoservice/export/citego_fr.dsmd?script=niveau1_par_dimension',
18
+ @conf.build_dsmd_url
19
+ )
20
+ assert_equal(
21
+ 'http://bases.fichotheque.net:8080/exemole/ext/fr-exemole-desmoservice/json?desmo=citego&lang=fr&fields=iddesc%2Clibelles%2Cattrs',
22
+ @conf.build_json_url(fields: 'iddesc,libelles,attrs',selection_idctxt: nil)
23
+ )
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/desmoservice'
2
+ require 'minitest/autorun'
3
+
4
+ class TestEdition < Minitest::Test
5
+
6
+ def setup
7
+ end
8
+
9
+ def test_xml
10
+ edition = Desmoservice::Edition.new()
11
+ edition.link_creation(345) do |link_creation|
12
+ link_creation.up(456, 67)
13
+ link_creation.up('A12', 'simple/dossier')
14
+ link_creation.family(67)
15
+ end
16
+ edition.link_creation('hjjh') do |link_creation|
17
+ end
18
+ edition.link_creation() do |link_creation|
19
+ link_creation.up(13, 'simple/dossier')
20
+ link_creation.text('fr', 'essai <')
21
+ link_creation.attr('atlas:url', 'http://www.exemole.fr/')
22
+ end
23
+ puts edition.close_to_xml()
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../lib/desmoservice'
2
+ require 'minitest/autorun'
3
+ require 'json'
4
+
5
+ class TestFamilies < Minitest::Test
6
+
7
+ def setup
8
+ @conf = Desmoservice::Conf.new({
9
+ service_url: 'http://bases.fichotheque.net:8080/exemole/ext/fr-exemole-desmoservice',
10
+ desmo_name: 'citego',
11
+ lang: 'fr',
12
+ dsmd_script: 'niveau1_par_dimension'
13
+ })
14
+ @json = %q@{"familles":{"familleArray":[{"terme":{"code":684,"libelles":[{"lang":"fr","lib":"Grilles de départ"}],"attrs":{"atlas:color":["#ffcccc"]},"active":true},"descripteurArray":[{"iddesc":"A","code":5321,"libelles":[{"lang":"fr","lib":"Éléments constitutifs des territoires, des villes et de la gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/A"]}},{"iddesc":"B","code":5331,"libelles":[{"lang":"fr","lib":"Types de territoires, de villes et de gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/B"]}},{"iddesc":"C","code":5341,"libelles":[{"lang":"fr","lib":"Dynamique des territoires, des villes, de la gouvernance"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/C"]}},{"iddesc":"D","code":5351,"libelles":[{"lang":"fr","lib":"Acteurs des territoires et de la gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/D"]}},{"iddesc":"E","code":5361,"libelles":[{"lang":"fr","lib":"Domaines de la gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/E"]}},{"iddesc":"F","code":5371,"libelles":[{"lang":"fr","lib":"Moyens de la gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/F"]}},{"iddesc":"G","code":5381,"libelles":[{"lang":"fr","lib":"Principes de gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/G"]}},{"iddesc":"H","code":5391,"libelles":[{"lang":"fr","lib":"Gouvernance territoriale et autres échelles de gouvernance"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/H"]}},{"iddesc":"I","code":5401,"libelles":[{"lang":"fr","lib":"Spécificités des territoires, villes et gouvernances territoriales dans le monde"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/I"]}}]}]}}@
15
+ end
16
+
17
+ def test_json
18
+ families = Desmoservice::Families.new()
19
+ families.parse_json(@json)
20
+ assert_equal(1, families.length)
21
+ assert_equal(9, families[0].members.length)
22
+ assert_equal("Grilles de départ", families[0].text)
23
+ assert_equal("Éléments constitutifs des territoires, des villes et de la gouvernance territoriale", families[0].members[0].text)
24
+ end
25
+
26
+ def test_download
27
+ get_params = Desmoservice::GetParams.new()
28
+ get_params.family_filter = 'grille'
29
+ families = Desmoservice::Get.families(@conf, get_params)
30
+ assert_equal(1, families.length)
31
+ assert_equal(9, families[0].members.length)
32
+ end
33
+ end
34
+
data/test/test_term.rb ADDED
@@ -0,0 +1,18 @@
1
+ require_relative '../lib/desmoservice'
2
+ require 'minitest/autorun'
3
+ require 'json'
4
+
5
+ class TestTerm < Minitest::Test
6
+
7
+ def setup
8
+ @json = %q@{"iddesc":"E","code":5361,"libelles":[{"lang":"fr","lib":"Domaines de la gouvernance territoriale"}],"attrs":{"atlas:ventilationnaturelle":["ventilation:contexte:complete/E"]}}@
9
+
10
+ end
11
+
12
+ def test_json
13
+ data = JSON.parse(@json)
14
+ term = Desmoservice::Term.new(data)
15
+ assert_equal("Domaines de la gouvernance territoriale", term.text)
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../lib/desmoservice'
2
+ require 'minitest/autorun'
3
+ require 'json'
4
+
5
+ class TestWordDistribution < Minitest::Test
6
+
7
+ def setup
8
+ @conf = Desmoservice::Conf.new({
9
+ service_url: 'http://bases.fichotheque.net:8080/exemole/ext/fr-exemole-desmoservice',
10
+ desmo_name: 'citego',
11
+ lang: 'fr',
12
+ dsmd_script: 'niveau1_par_dimension'
13
+ })
14
+ end
15
+
16
+ def test2_json
17
+ word_distribution = Desmoservice::WordDistribution.new()
18
+ word_distribution.parse_json(@json)
19
+ assert_equal(457, word_distribution.words.length)
20
+ assert_equal(225, word_distribution.tagged_terms.length)
21
+ tagged_text = ''
22
+ word_distribution.tagged_terms[21].tagged_parts.each do |part|
23
+ if part.word_id.nil?
24
+ tagged_text += part.value
25
+ else
26
+ tagged_text += '<word id="' + part.word_id + '">' + part.value + '</word>'
27
+ end
28
+ end
29
+ assert_equal(
30
+ '<word id="1">organisation</word> <word id="2">sociale</word> des <word id="3">territoires</word> et des <word id="4">villes</word>',
31
+ tagged_text
32
+ )
33
+ end
34
+
35
+
36
+ def test2_download
37
+ get_params = Desmoservice::GetParams.new()
38
+ get_params.family_filter = 'niveau1@'
39
+ word_distribution = Desmoservice::Get.word_distribution(@conf, get_params)
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: desmoservice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Calame
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Manage the connection to Desmoservice server, convert JSON to ruby objects
14
+ and build XML for edition
15
+ email: vincent.calame@exemole.fr
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README
21
+ - lib/ventilation.rb
22
+ - lib/get.rb
23
+ - lib/conf.rb
24
+ - lib/families.rb
25
+ - lib/term.rb
26
+ - lib/family.rb
27
+ - lib/edition.rb
28
+ - lib/get_params.rb
29
+ - lib/log_handler.rb
30
+ - lib/desmoservice.rb
31
+ - lib/sector.rb
32
+ - lib/post.rb
33
+ - lib/word_distribution.rb
34
+ - test/test_edition.rb
35
+ - test/test_families.rb
36
+ - test/test_conf.rb
37
+ - test/test_term.rb
38
+ - test/test_word_distribution.rb
39
+ - desmoservice.gemspec
40
+ homepage: https://github.com/vcalame/desmoservice
41
+ licenses:
42
+ - Ruby
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.1.11
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Read and write access to Desmoservice API
64
+ test_files: []