apidae 1.4.28 → 1.4.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02a75c98465e95a1f4c085ba3c9bb4f470492d21f36144e0bc7ce3f4443abd43
4
- data.tar.gz: 6aa2d6e64128804f1ea79dcf5e08d31c14a37134683c803fa21d78c01802db60
3
+ metadata.gz: 97392b71ecba1be3def741734fab735d940c98c6caf74131ba699261793ce3a9
4
+ data.tar.gz: 013af2d00d04dac662a40934e53814a1ebd69f7e347c57e2c27d8624eee21900
5
5
  SHA512:
6
- metadata.gz: 5f6d21a634071a39bb6f2ec299672086a640e5c01230220c26c11fc0c90623026dfdc01c4a7f91613c4546626d28fa21634cde5319df893fd360df8565bdef83
7
- data.tar.gz: bc3b53e312a327923b8e02190b0c4fac3ab62b68477d1fc20b2475eba6507bddbc6c05c723928181582281bcdb3a18d4669a756b1cf6eda1992366b04bfa69fb
6
+ metadata.gz: b006a8f118a63fe011c35b8d07d5721ad87754ec7a3978d62cbc83b36f5032b9725ca11f3c8eb69a005bb89833b6eba6e4a1faa1d1fcc5f80c8e551234dbe2a0
7
+ data.tar.gz: 5e174766ca0e24da87e16c786f7b9343c177ae3cad8c805b8bb1878b4f73c4124d4bd575a2c9ba5a110818f366fb70336b7ded4aa4161e3b090d70a3866d3064
@@ -52,6 +52,26 @@ module Apidae
52
52
  'DIMANCHE' => SUNDAY
53
53
  }
54
54
 
55
+ OPENING_HOURS_TYPES = {
56
+ 7487 => 'opening',
57
+ 7488 => 'last_entry',
58
+ 7489 => 'ceremony',
59
+ 7490 => 'guided_tour',
60
+ 7491 => 'surpervised_swimming',
61
+ 7492 => 'service',
62
+ 7493 => 'arrival',
63
+ 7494 => 'departure',
64
+ 7495 => 'representation',
65
+ 7496 => 'petitdejeuner',
66
+ 7497 => 'checkin',
67
+ 7498 => 'Checkout',
68
+ 7499 => 'derniere_descente',
69
+ 7500 => 'derniere_montee',
70
+ 7501 => 'shop',
71
+ 7502 => 'reception',
72
+ 9000 => 'debut_seance'
73
+ }
74
+
55
75
  def self.parse_versioned_fields(data_hash)
56
76
  version_fields = data_hash[:champsAspect] || []
57
77
  matched_fields = []
@@ -426,24 +446,32 @@ module Apidae
426
446
  end
427
447
 
428
448
  def self.build_time_periods(o)
429
- if o[:horaires].blank?
430
- [
431
- {
432
- type: 'opening',
433
- weekdays: compute_weekdays(o),
434
- time_frames: (o[:horaireOuverture].blank? && o[:horaireFermeture].blank?) ? [] : [{start_time: o[:horaireOuverture], end_time: o[:horaireFermeture], recurrence: nil}]
435
- }
436
- ]
437
- else
438
- o[:horaires].map do |h|
439
- {
440
- type: h.dig(:type, :externalType),
441
- weekdays: compute_weekdays(o),
442
- time_frames: (h[:timePeriods] || []).map {|tp| (tp[:timeFrames] || [])}.flatten.select {|tf| !tf[:startTime].blank? || !tf[:endTime].blank?}
443
- .map {|tf| {start_time: tf[:startTime], end_time: tf[:endTime]}}
444
- }
445
- end
446
- end
449
+ time_periods = (o[:horaires] || []).flat_map {|h| build_typed_time_periods(o, h)}
450
+ time_periods.blank? ? [build_default_time_period(o)] : time_periods
451
+ end
452
+
453
+ def self.build_default_time_period(o)
454
+ {
455
+ type: 'opening',
456
+ weekdays: compute_weekdays(o),
457
+ time_frames: (o[:horaireOuverture].blank? && o[:horaireFermeture].blank?) ? [] : [{start_time: o[:horaireOuverture], end_time: o[:horaireFermeture], recurrence: nil}]
458
+ }
459
+ end
460
+
461
+ def self.build_typed_time_periods(o, h)
462
+ type = h.dig(:type, :externalType) || OPENING_HOURS_TYPES[h.dig(:type, :id)]
463
+ open_time_periods = (h[:timePeriods] || []).reject {|tp| tp[:closed]}
464
+ open_time_periods.map {|tp| {type: type, weekdays: time_period_weekdays(o, tp), time_frames: build_time_frames(tp)}}
465
+ .sort_by.with_index {|tp, i| [ALL_DAYS.index(tp[:weekdays].first) || ALL_DAYS.length, i]}
466
+ end
467
+
468
+ def self.time_period_weekdays(o, tp)
469
+ tp[:weekdays].blank? ? compute_weekdays(o) : ALL_DAYS & tp[:weekdays]
470
+ end
471
+
472
+ def self.build_time_frames(tp)
473
+ (tp[:timeFrames] || []).select {|tf| !tf[:startTime].blank? || !tf[:endTime].blank?}
474
+ .map {|tf| {start_time: tf[:startTime], end_time: tf[:endTime], recurrence: tf[:recurrence]}}
447
475
  end
448
476
 
449
477
  def self.node_value(node, key, *locales)
@@ -2,6 +2,7 @@ module Apidae
2
2
  class Obj < ActiveRecord::Base
3
3
 
4
4
  belongs_to :town, class_name: 'Apidae::Town', foreign_key: :town_insee_code, primary_key: :insee_code, optional: true
5
+ belongs_to :apidae_town, class_name: 'Apidae::Town', foreign_key: :apidae_town_id, primary_key: :apidae_id, optional: true
5
6
  has_many :apidae_selection_objects, class_name: 'Apidae::SelectionObject', foreign_key: :apidae_object_id
6
7
  has_many :selections, class_name: 'Apidae::Selection', source: :apidae_selection, through: :apidae_selection_objects
7
8
 
@@ -243,6 +244,7 @@ module Apidae
243
244
  apidae_obj.location_data = ApidaeDataParser.parse_location_data(object_data[:localisation], object_data[type_fields[:node]],
244
245
  object_data[:territoires])
245
246
  apidae_obj.town = ApidaeDataParser.parse_town(object_data[:localisation])
247
+ apidae_obj.apidae_town_id = apidae_obj.town&.apidae_id
246
248
  apidae_obj.openings_data = ApidaeDataParser.parse_openings(object_data[:ouverture], object_data[:datesOuverture], *locales)
247
249
  apidae_obj.rates_data = ApidaeDataParser.parse_rates(object_data[:descriptionTarif], *locales)
248
250
  apidae_obj.booking_data = ApidaeDataParser.parse_booking(object_data[:reservation], object_data[:visites], *locales)
@@ -223,7 +223,7 @@ module Apidae
223
223
  def get_response(args)
224
224
  response = ''
225
225
  query = JSON.generate args.except(:url)
226
- logger.debug "Apidae API query : #{args[:url]}?query=#{query}"
226
+ logger.info "Apidae API query : #{args[:url]}?query=#{query}"
227
227
  open("#{args[:url]}?query=#{CGI.escape query}") { |f|
228
228
  f.each_line {|line| response += line if line}
229
229
  }
@@ -0,0 +1,6 @@
1
+ class AddApidaeTownIdToApidaeObjs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :apidae_objs, :apidae_town_id, :integer
4
+ add_index :apidae_objs, :apidae_town_id
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.4.28"
2
+ VERSION = "1.4.30"
3
3
  end