sitra_client 0.0.2 → 0.0.3
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.
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sitra_client/attribute_helper'
|
2
|
+
require 'sitra_client/touristic_object'
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
class SitraResponse
|
@@ -19,4 +20,14 @@ class SitraResponse
|
|
19
20
|
@json_response
|
20
21
|
end
|
21
22
|
|
23
|
+
def as_array
|
24
|
+
response = as_hash
|
25
|
+
if response[:objetsTouristiques].nil?
|
26
|
+
results = []
|
27
|
+
else
|
28
|
+
results = response[:objetsTouristiques].collect {|obj_hash| TouristicObject.new(obj_hash)}
|
29
|
+
end
|
30
|
+
results
|
31
|
+
end
|
32
|
+
|
22
33
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'sitra_client/attribute_helper'
|
3
|
+
|
4
|
+
class TouristicObject
|
5
|
+
|
6
|
+
include AttributeHelper
|
7
|
+
|
8
|
+
def initialize(hash)
|
9
|
+
self.attributes = hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def id
|
13
|
+
@id.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def title
|
17
|
+
@nom[:libelleFr]
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
@presentation[:descriptifCourt][:libelleFr] unless @presentation[:descriptifCourt].nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def details
|
25
|
+
@presentation[:descriptifDetaille][:libelleFr] unless @presentation[:descriptifDetaille].nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def contact
|
29
|
+
contact_details = {}
|
30
|
+
contact_entries = @informations[:moyensCommunication].nil? ? [] : @informations[:moyensCommunication]
|
31
|
+
contact_entries.each do |c|
|
32
|
+
label = c[:type][:libelleFr]
|
33
|
+
contact_details[c[:type][:libelleFr]] = c[:coordonnee] unless label == 'Fax'
|
34
|
+
end
|
35
|
+
contact_details
|
36
|
+
end
|
37
|
+
|
38
|
+
def picture_url(default_url)
|
39
|
+
@imagePrincipale.nil? ? default_url : @imagePrincipale[:traductionFichiers][0][:url]
|
40
|
+
end
|
41
|
+
|
42
|
+
def service_provider
|
43
|
+
if @informationsActivite && @informationsActivite[:commerceEtServicePrestataire]
|
44
|
+
@informationsActivite[:commerceEtServicePrestataire][:nom][:libelleFr]
|
45
|
+
elsif @informationsFeteEtManifestation
|
46
|
+
@informationsFeteEtManifestation[:nomLieu]
|
47
|
+
else
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def address_details
|
53
|
+
if @informationsActivite && @informationsActivite[:commerceEtServicePrestataire]
|
54
|
+
@informationsActivite[:commerceEtServicePrestataire][:adresse]
|
55
|
+
else
|
56
|
+
@localisation[:adresse]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def address
|
61
|
+
"#{address_details[:adresse1]}, #{address_details[:commune][:nom]}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def latitude
|
65
|
+
geoloc_details = parse_geoloc_details
|
66
|
+
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][1] : nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def longitude
|
70
|
+
geoloc_details = parse_geoloc_details
|
71
|
+
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][0] : nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def horaires
|
75
|
+
if @ouverture && @ouverture[:periodeEnClair]
|
76
|
+
@ouverture[:periodeEnClair][:libelleFr]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def tarif
|
81
|
+
if @descriptionTarif
|
82
|
+
if @descriptionTarif[:gratuit]
|
83
|
+
return 'gratuit'
|
84
|
+
elsif @descriptionTarif[:tarifsEnClair]
|
85
|
+
@descriptionTarif[:tarifsEnClair][:libelleFr]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def population
|
91
|
+
eligible_populations = []
|
92
|
+
if @prestations && @prestations[:typesClientele]
|
93
|
+
eligible_populations += @prestations[:typesClientele].collect {|t| t[:libelleFr]}
|
94
|
+
end
|
95
|
+
eligible_populations.uniq
|
96
|
+
end
|
97
|
+
|
98
|
+
def adapted_tourism
|
99
|
+
@prestations && @prestations[:tourismesAdaptes] && @prestations[:tourismesAdaptes].collect {|t| t[:libelleFr]}
|
100
|
+
end
|
101
|
+
|
102
|
+
def environments
|
103
|
+
@localisation && @localisation[:environnements] && @localisation[:environnements].collect {|e| e[:libelleFr]}
|
104
|
+
end
|
105
|
+
|
106
|
+
def additional_criteria
|
107
|
+
@presentation && @presentation[:typologiesPromoSitra] && @presentation[:typologiesPromoSitra].collect {|t| t[:libelleFr]}
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def parse_geoloc_details
|
113
|
+
if @informationsActivite.nil? || @informationsActivite[:commerceEtServicePrestataire].nil?
|
114
|
+
geoloc_details = @localisation[:geolocalisation]
|
115
|
+
else
|
116
|
+
geoloc_details = @informationsActivite[:commerceEtServicePrestataire][:geolocalisation]
|
117
|
+
end
|
118
|
+
geoloc_details
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/lib/sitra_client/version.rb
CHANGED
@@ -34,4 +34,33 @@ class SitraResponseTest < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
+
should 'return an array of touristic objects' do
|
38
|
+
|
39
|
+
json_response = '{ "numFound" : 2, "objetsTouristiques" : [ {"id" : 1, "nom" : {"libelleFr" : "my_first_object"} }, {"id" : 2, "nom" : {"libelleFr" : "my_second_object"} } ] }'
|
40
|
+
|
41
|
+
sitra_response = SitraResponse.new
|
42
|
+
sitra_response.append_line(json_response)
|
43
|
+
|
44
|
+
touristic_objects = sitra_response.as_array
|
45
|
+
|
46
|
+
assert_equal 2, touristic_objects.length
|
47
|
+
assert_equal "1", touristic_objects[0].id
|
48
|
+
assert_equal "my_first_object", touristic_objects[0].title
|
49
|
+
assert_equal "2", touristic_objects[1].id
|
50
|
+
assert_equal "my_second_object", touristic_objects[1].title
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'return empty array when no data is available' do
|
55
|
+
|
56
|
+
json_response = '{ "numFound" : 2 }'
|
57
|
+
|
58
|
+
sitra_response = SitraResponse.new
|
59
|
+
sitra_response.append_line(json_response)
|
60
|
+
|
61
|
+
touristic_objects = sitra_response.as_array
|
62
|
+
assert_empty touristic_objects
|
63
|
+
|
64
|
+
end
|
65
|
+
|
37
66
|
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# encoding : UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'shoulda'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'sitra_client/touristic_object'
|
7
|
+
|
8
|
+
class TouristicObjectTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
should 'populate title of touristic object' do
|
11
|
+
hash_result = {:nom => {:libelleFr => "my_title"}}
|
12
|
+
touristic_object = TouristicObject.new(hash_result)
|
13
|
+
|
14
|
+
assert_equal 'my_title', touristic_object.title
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'populate description of touristic object' do
|
18
|
+
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description"}}}
|
19
|
+
touristic_object = TouristicObject.new(hash_result)
|
20
|
+
|
21
|
+
assert_equal 'my_description', touristic_object.description
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'populate detailed description of touristic object' do
|
25
|
+
hash_result = {:presentation => {:descriptifDetaille => {:libelleFr => "my_detailed_description"}}}
|
26
|
+
touristic_object = TouristicObject.new(hash_result)
|
27
|
+
|
28
|
+
assert_equal 'my_detailed_description', touristic_object.details
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'populate contact details' do
|
32
|
+
hash_result = {
|
33
|
+
:informations => {
|
34
|
+
:moyensCommunication => [
|
35
|
+
{:type => {:libelleFr => "Téléphone"}, :coordonnee => "0123456789"},
|
36
|
+
{:type => {:libelleFr => "Fax"}, :coordonnee => "9876543201"}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
touristic_object = TouristicObject.new(hash_result)
|
41
|
+
|
42
|
+
assert_equal({'Téléphone' => '0123456789'}, touristic_object.contact)
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'populate image details' do
|
46
|
+
hash_result = {:imagePrincipale => {:traductionFichiers => [{:url => "my/image/url"}]}}
|
47
|
+
touristic_object = TouristicObject.new(hash_result)
|
48
|
+
|
49
|
+
assert_equal 'my/image/url', touristic_object.picture_url('default.png')
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'populate address details' do
|
53
|
+
hash_result = {
|
54
|
+
:informationsActivite => {
|
55
|
+
:commerceEtServicePrestataire => {
|
56
|
+
:nom => {:libelleFr => "my_service"},
|
57
|
+
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
58
|
+
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
touristic_object = TouristicObject.new(hash_result)
|
63
|
+
|
64
|
+
assert_equal 'my_service', touristic_object.service_provider
|
65
|
+
assert_equal 'my_address, my_city', touristic_object.address
|
66
|
+
assert_equal 0.2, touristic_object.latitude
|
67
|
+
assert_equal 0.1, touristic_object.longitude
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'use event details when available' do
|
71
|
+
hash_result = {:informationsFeteEtManifestation => {:nomLieu => "my_place"}}
|
72
|
+
touristic_object = TouristicObject.new(hash_result)
|
73
|
+
|
74
|
+
assert_equal 'my_place', touristic_object.service_provider
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'fallback to localisation address when service details are missing' do
|
78
|
+
hash_result = {
|
79
|
+
:localisation => {
|
80
|
+
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
81
|
+
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
82
|
+
},
|
83
|
+
:informationsActivite => {}
|
84
|
+
}
|
85
|
+
touristic_object = TouristicObject.new(hash_result)
|
86
|
+
|
87
|
+
assert_nil touristic_object.service_provider
|
88
|
+
assert_equal 'my_address, my_city', touristic_object.address
|
89
|
+
assert_equal 0.2, touristic_object.latitude
|
90
|
+
assert_equal 0.1, touristic_object.longitude
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'populate opening hours when available' do
|
94
|
+
hash_result = {:ouverture => {:periodeEnClair => {:libelleFr => "my_opening_hours"}}}
|
95
|
+
touristic_object = TouristicObject.new(hash_result)
|
96
|
+
|
97
|
+
assert_equal 'my_opening_hours', touristic_object.horaires
|
98
|
+
end
|
99
|
+
|
100
|
+
should 'populate tariffs data when available' do
|
101
|
+
hash_result = {
|
102
|
+
:descriptionTarif => {:gratuit => false,
|
103
|
+
:tarifsEnClair => {:libelleFr => "my_tariff_description"}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
touristic_object = TouristicObject.new(hash_result)
|
107
|
+
|
108
|
+
assert_equal 'my_tariff_description', touristic_object.tarif
|
109
|
+
end
|
110
|
+
|
111
|
+
should 'tag free oject when relevant' do
|
112
|
+
hash_result = {:descriptionTarif => {:gratuit => true}}
|
113
|
+
touristic_object = TouristicObject.new(hash_result)
|
114
|
+
|
115
|
+
assert_equal 'gratuit', touristic_object.tarif
|
116
|
+
end
|
117
|
+
|
118
|
+
should 'populate populations information' do
|
119
|
+
hash_result = {
|
120
|
+
:prestations => {:typesClientele => [{:libelleFr => "Familles"}]}
|
121
|
+
}
|
122
|
+
touristic_object = TouristicObject.new(hash_result)
|
123
|
+
|
124
|
+
assert_equal ['Familles'], touristic_object.population
|
125
|
+
end
|
126
|
+
|
127
|
+
should 'populate adapted tourism fields' do
|
128
|
+
hash_result = {:prestations => {:tourismesAdaptes => [{:libelleFr => "Accessible en fauteuil roulant en autonomie"}]}}
|
129
|
+
touristic_object = TouristicObject.new(hash_result)
|
130
|
+
|
131
|
+
assert_true touristic_object.adapted_tourism.include?('Accessible en fauteuil roulant en autonomie')
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitra_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,10 +123,12 @@ files:
|
|
123
123
|
- lib/sitra_client/attribute_helper.rb
|
124
124
|
- lib/sitra_client/sitra_query.rb
|
125
125
|
- lib/sitra_client/sitra_response.rb
|
126
|
+
- lib/sitra_client/touristic_object.rb
|
126
127
|
- lib/sitra_client/version.rb
|
127
128
|
- sitra_client.gemspec
|
128
129
|
- test/sitra_client/sitra_query_test.rb
|
129
130
|
- test/sitra_client/sitra_response_test.rb
|
131
|
+
- test/sitra_client/touristic_object_test.rb
|
130
132
|
homepage: https://github.com/jeanbaptistevilain/sitra_client
|
131
133
|
licenses:
|
132
134
|
- MIT
|
@@ -155,3 +157,4 @@ summary: A simple Ruby wrapper for the SITRA JSON api
|
|
155
157
|
test_files:
|
156
158
|
- test/sitra_client/sitra_query_test.rb
|
157
159
|
- test/sitra_client/sitra_response_test.rb
|
160
|
+
- test/sitra_client/touristic_object_test.rb
|