apidae 1.2.35 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 0ab6ee3f3a2d8930bc4d486e7de657f1fb408e69f0faf9b49e01921241210b02
4
- data.tar.gz: 8c7637a88153f8befc3d3b94569f60afad0caf19235fc128b5302b104109bc1e
2
+ SHA1:
3
+ metadata.gz: 11f5031e46f8bfa23ce228c242e023c4ebe10e0e
4
+ data.tar.gz: '0083f65ff4cfbd3f53c5a13126ca940c4be696ae'
5
5
  SHA512:
6
- metadata.gz: 3f27a28ff6f954de764937f484ce844113acc6f642c2ba7f6eab37889f80c979ad92f4ddd0c13263017280678f969f83ff0920a4ac315306237bbefc75d35114
7
- data.tar.gz: 75b2bb35a5d82be0b16019e4f55e1b804e69aa8cbe496d8f240dfb8dff7771d6f24a9c0150841ea389a80182f5b5851e56cb0b50c27ad11c1b50d470f3d94cb0
6
+ metadata.gz: 0a6544dae89ca3cee7525b37433fc6941b5ae76d720f2adce045d3357fd65efca3150885b0cb9da8234a5324218448e57545897865a77896e1bdfe7a462ab31b
7
+ data.tar.gz: 9c51ebdb6c1d9d671499fd60f086a8c43feb94a9c77d06108aa030b73d5bce00ad4fd5b58e0f5467d21a509bcc1594c2c59f6d19e4be2f61a78d76fc04037b3b
@@ -37,7 +37,7 @@ module Apidae
37
37
  def run
38
38
  success = true
39
39
  Export.pending.each do |e|
40
- success &&= import_data(e)
40
+ success &&= e.import_data
41
41
  end
42
42
  success ? head(:ok) : head(:internal_server_error)
43
43
  end
@@ -48,7 +48,7 @@ module Apidae
48
48
 
49
49
  def create
50
50
  @export = Export.new(export_params)
51
- if @export.save && import_data(@export)
51
+ if @export.save && @export.import_data
52
52
  redirect_to apidae.root_url, notice: 'Le fichier a bien été importé.'
53
53
  else
54
54
  flash.now[:alert] = "Une erreur s'est produite lors de l'import du fichier."
@@ -61,43 +61,5 @@ module Apidae
61
61
  def export_params
62
62
  params.require(:export).permit(:project_id, :file_url, :status)
63
63
  end
64
-
65
- def import_data(e)
66
- success = true
67
- begin
68
- open(e.file_url) do |f|
69
- begin
70
- FileImport.import(f, e.project_id)
71
- unless e.confirm_url.blank?
72
- uri = URI(e.confirm_url)
73
- req = Net::HTTP::Post.new(uri)
74
- Net::HTTP.start(uri.hostname, uri.port) do |http|
75
- http.request(req)
76
- end
77
- end
78
- e.update(status: Export::COMPLETE)
79
- if Rails.application.config.respond_to?(:apidae_import_callback)
80
- Rails.application.config.apidae_import_callback.call(e)
81
- end
82
- rescue Exception => ex
83
- logger.error("Failed to import export file : #{e.file_url}")
84
- logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
85
- success = false
86
- e.update(status: Export::CANCELLED)
87
- end
88
- end
89
- rescue OpenURI::HTTPError => err
90
- logger.error("Failed to download export file : #{e.file_url}")
91
- logger.error("Error is : #{err}")
92
- success = false
93
- e.update(status: Export::CANCELLED)
94
- rescue Exception => e
95
- logger.error "Failed to import file : #{e.file_url}"
96
- logger.error("Error is : #{err}")
97
- success = false
98
- e.update(status: Export::CANCELLED)
99
- end
100
- success
101
- end
102
64
  end
103
65
  end
@@ -1,6 +1,6 @@
1
1
  module Apidae
2
2
  module ApplicationHelper
3
- include Apidae::ApidaeHelper
3
+ include ApidaeHelper
4
4
 
5
5
  def apidae_user
6
6
  send(Rails.application.config.apidae_user) if Rails.application.config.respond_to?(:apidae_user)
@@ -44,7 +44,7 @@ module Apidae
44
44
  'LUNDI' => MONDAY,
45
45
  'MARDI' => TUESDAY,
46
46
  'MERCREDI' => WEDNESDAY,
47
- 'JEUDI' => THURSDAY,
47
+ 'JEUD' => THURSDAY,
48
48
  'VENDREDI' => FRIDAY,
49
49
  'SAMEDI' => SATURDAY,
50
50
  'DIMANCHE' => SUNDAY
@@ -101,25 +101,19 @@ module Apidae
101
101
  {title: node_value(data_hash, :nom, *locales)}
102
102
  end
103
103
 
104
- def self.parse_owner_data(data_hash, polls_data)
105
- owner_data = {}
104
+ def self.parse_owner_data(data_hash)
106
105
  unless data_hash.blank?
107
- owner_data.merge!({owner_name: data_hash[:nom], owner_id: data_hash[:id]})
106
+ {owner_name: data_hash[:nom], owner_id: data_hash[:id]}
108
107
  end
109
- unless polls_data.blank?
110
- owner_data.merge!({polls: polls_data[:enquetes] || []})
111
- end
112
- owner_data
113
108
  end
114
109
 
115
- def self.parse_desc_data(data_hash, private_data, presta_data, *locales)
110
+ def self.parse_desc_data(data_hash, private_data, *locales)
116
111
  unless data_hash.blank?
117
112
  {
118
113
  short_desc: node_value(data_hash, :descriptifCourt, *locales),
119
114
  long_desc: node_value(data_hash, :descriptifDetaille, *locales),
120
115
  theme_desc: data_hash[:descriptifsThematises].blank? ? {} : Hash[data_hash[:descriptifsThematises].map {|th| [node_id(th, :theme), node_value(th, :description, *locales)]}],
121
- private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique], (node_value(d, :descriptif, *locales).blank? ? {LOCALE_FR => d[:libelleFr]} : node_value(d, :descriptif, *locales))]}],
122
- accessibility_desc: presta_data.blank? ? {} : Hash[presta_data.select {|k, v| k.to_s.start_with?('descriptifHandicap')}.map {|k, v| [k, node_value(presta_data, k, *locales)]}]
116
+ private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique], node_value(d, :descriptif, *locales)]}]
123
117
  }
124
118
  end
125
119
  end
@@ -157,7 +151,6 @@ module Apidae
157
151
  name: localized_value(att, :nom, locale),
158
152
  url: att[:traductionFichiers][0][:url].gsub('http:', 'https:'),
159
153
  type: att[:type],
160
- link: att[:link],
161
154
  description: localized_value(att, :legende, locale)
162
155
  }
163
156
  end
@@ -215,22 +208,20 @@ module Apidae
215
208
  def self.parse_location_data(location_hash, type_data_hash, territories)
216
209
  loc_data = {}
217
210
  unless location_hash.blank?
218
- address_hash = location_hash[:adresse] || {}
211
+ address_hash = location_hash[:adresse]
219
212
  computed_address = []
220
213
  unless address_hash.blank?
221
- computed_address << address_hash[:adresse1]
222
- computed_address << address_hash[:adresse2]
223
- computed_address << address_hash[:adresse3]
214
+ computed_address << address_hash[:adresse1] unless address_hash[:adresse1].blank?
215
+ computed_address << address_hash[:adresse2] unless address_hash[:adresse2].blank?
216
+ computed_address << address_hash[:adresse3] unless address_hash[:adresse3].blank?
224
217
  end
225
218
  loc_data.merge!({address: computed_address})
226
- loc_data.merge!({place: (type_data_hash ? type_data_hash[:nomLieu] : nil) || address_hash[:nomDuLieu]})
219
+ loc_data.merge!({place: type_data_hash[:nomLieu]}) if type_data_hash
227
220
  geoloc_details = location_hash[:geolocalisation]
228
221
  if geoloc_details && geoloc_details[:valide] && geoloc_details[:geoJson]
229
222
  loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1]
230
223
  loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0]
231
224
  end
232
- loc_data[:map_reference] = geoloc_details[:reperePlan]
233
- loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details
234
225
  loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details
235
226
  loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements]
236
227
  end
@@ -245,7 +236,6 @@ module Apidae
245
236
  openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
246
237
  openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
247
238
  openings: build_openings(openings_hash, *locales),
248
- all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false',
249
239
  time_periods: lists_ids(openings_hash[:indicationsPeriode]),
250
240
  openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
251
241
  }
@@ -257,10 +247,8 @@ module Apidae
257
247
  desc = rates_hash[:gratuit] ? {DEFAULT_LOCALE => 'gratuit'} : node_value(rates_hash, :tarifsEnClair, *locales)
258
248
  values = rates_hash[:periodes].blank? ? [] : rates_hash[:periodes].map {|p| build_rate(p, *locales)}
259
249
  methods = rates_hash[:modesPaiement].blank? ? [] : rates_hash[:modesPaiement].map {|p| p[:id]}
260
-
261
250
  {
262
251
  rates_desc: desc, rates: values, payment_methods: methods,
263
- tax_included: rates_hash[:taxeDeSejourIncluse].blank? ? nil : (rates_hash[:taxeDeSejourIncluse] == 'OUI'),
264
252
  rates_desc_mode: rates_hash[:tarifsEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
265
253
  includes: node_value(rates_hash, :leTarifComprend, *locales),
266
254
  excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales),
@@ -276,22 +264,18 @@ module Apidae
276
264
  apidae_obj.apidae_subtype = node_id(data_hash, :rubrique) if apidae_obj.apidae_type == Obj::EQU
277
265
  apidae_obj.apidae_subtype = lists_ids(data_hash[:typesHebergement]).first if apidae_obj.apidae_type == Obj::SPA
278
266
  {
279
- categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories], data_hash[:typesHabitation]),
267
+ categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories]),
280
268
  themes: lists_ids(data_hash[:themes]),
281
269
  capacity: (data_hash[:capacite] || {})
282
270
  .merge(presta_hash ? {group_min: presta_hash[:tailleGroupeMin], group_max: presta_hash[:tailleGroupeMax],
283
- age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax],
284
- wheelchair_max: presta_hash[:nombrePersonnesEnFauteuilRoulantAccueilliesSimultanement]} : {}),
271
+ age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax]} : {}),
285
272
  classification: nodes_ids(data_hash[:classement], data_hash[:classementPrefectoral], data_hash[:classification]) +
286
273
  lists_ids(data_hash[:classementsGuides]) + lists_ids(data_hash[:classements]),
287
- classification_date: data_hash[:dateClassement],
288
- classification_ref: data_hash[:numeroClassement],
289
274
  labels: lists_ids(data_hash[:labels], data_hash[:labelsChartesQualite], prestations_hash[:labelsTourismeHandicap]) +
290
275
  (node_id(data_hash, :typeLabel) ? [node_id(data_hash, :typeLabel)] : []),
291
276
  chains: lists_ids(data_hash[:chaines]) + nodes_ids(data_hash[:chaineEtLabel]),
292
277
  area: apidae_obj.apidae_type == Obj::DOS ? data_hash.except(:classification) : node_value(data_hash, :lieuDePratique),
293
- track: apidae_obj.apidae_type == Obj::EQU ? (data_hash[:itineraire] || {}).except(:passagesDelicats) : nil,
294
- tricky_sections: apidae_obj.apidae_type == Obj::EQU ? node_value(data_hash[:itineraire], :passagesDelicats, *locales) : nil,
278
+ track: apidae_obj.apidae_type == Obj::EQU ? data_hash[:itineraire] : nil,
295
279
  products: lists_ids(data_hash[:typesProduit], data_hash[:aopAocIgps], data_hash[:specialites]),
296
280
  audience: lists_ids(prestations_hash[:typesClientele]),
297
281
  animals: {allowed: prestations_hash[:animauxAcceptes] == 'ACCEPTES', desc: node_value(prestations_hash, :descriptifAnimauxAcceptes, *locales),
@@ -299,10 +283,7 @@ module Apidae
299
283
  extra: apidae_obj.apidae_type == Obj::SPA ? node_value(data_hash, :formuleHebergement, *locales) : node_value(prestations_hash, :complementAccueil, *locales),
300
284
  duration: apidae_obj.apidae_type == Obj::SPA ? {days: data_hash[:nombreJours], nights: data_hash[:nombreNuits]} : data_hash[:dureeSeance],
301
285
  certifications: data_hash[:agrements].blank? ? [] : data_hash[:agrements].map {|a| {id: a[:type][:id], identifier: a[:numero]}},
302
- business: (business_hash || {}).except(:sallesEquipeesPour, :sallesEquipement, :sallesRestauration, :sallesReunion, :sallesHebergement),
303
- business_equipments: lists_ids((business_hash || {})[:sallesEquipeesPour], (business_hash || {})[:sallesEquipement],
304
- (business_hash || {})[:sallesRestauration], (business_hash || {})[:sallesHebergement]),
305
- business_rooms: (business_hash || {})[:sallesReunion]
286
+ business: business_hash
306
287
  }
307
288
  end
308
289
 
@@ -316,8 +297,7 @@ module Apidae
316
297
  type_data_hash ? type_data_hash[:activitesSportives] : [],
317
298
  type_data_hash ? type_data_hash[:activitesCulturelles] : []),
318
299
  challenged: lists_ids(data_hash[:tourismesAdaptes]),
319
- languages: lists_ids(data_hash[:languesParlees]),
320
- documentation_languages: lists_ids(data_hash[:languesDocumentation])
300
+ languages: lists_ids(data_hash[:languesParlees])
321
301
  }
322
302
  end
323
303
  end
@@ -337,19 +317,13 @@ module Apidae
337
317
  tags
338
318
  end
339
319
 
340
- def self.parse_booking(reservation_hash, visits_hash, *locales)
341
- booking_hash = {}
320
+ def self.parse_booking(reservation_hash, *locales)
342
321
  if reservation_hash
343
- booking_hash[:booking_desc] = node_value(reservation_hash, :complement, *locales)
344
- booking_hash[:booking_entities] = reservation_hash[:organismes]
345
- end
346
- if visits_hash
347
- booking_hash[:visits_allowed] = visits_hash[:visitable] == true
348
- booking_hash[:visits_desc] = node_value(visits_hash, :complementVisite, *locales)
349
- booking_hash[:visits_duration] = visits_hash[:dureeMoyenneVisiteIndividuelle]
350
- booking_hash[:visits_services] = lists_ids(visits_hash[:prestationsVisitesGroupees]) + lists_ids(visits_hash[:prestationsVisitesIndividuelles])
322
+ {
323
+ booking_desc: node_value(reservation_hash, :complement, *locales),
324
+ booking_entities: reservation_hash[:organismes]
325
+ }
351
326
  end
352
- booking_hash
353
327
  end
354
328
 
355
329
  def self.parse_town(location_hash)
@@ -361,24 +335,10 @@ module Apidae
361
335
  end
362
336
  end
363
337
 
364
- def self.parse_entity_fields(information_hash, type_data_hash, sp_hash)
365
- entity_hash = {}
366
- if information_hash
367
- if information_hash[:structureGestion]
368
- entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], entity_name: information_hash[:structureGestion].dig(:nom, :libelleFr),
369
- info_entity_id: (information_hash[:structureInformation] || information_hash[:structureGestion])[:id],
370
- info_entity_name: (information_hash[:structureInformation] || information_hash[:structureGestion]).dig(:nom, :libelleFr),
371
- service_provider_id: node_id(type_data_hash, :prestataireActivites)})
372
- end
373
-
374
- if information_hash[:informationsLegales]
375
- entity_hash.merge!({legal: information_hash[:informationsLegales]})
376
- end
377
- end
378
- if sp_hash && sp_hash[:prestataireActivites]
379
- entity_hash[:is_service_provider] = true
338
+ def self.parse_entity_fields(information_hash, type_data_hash)
339
+ if information_hash && information_hash[:structureGestion]
340
+ {entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)}
380
341
  end
381
- entity_hash
382
342
  end
383
343
 
384
344
  def self.node_id(node, key)
@@ -1,3 +1,6 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
1
4
  module Apidae
2
5
  class Export < ActiveRecord::Base
3
6
 
@@ -20,5 +23,43 @@ module Apidae
20
23
  def self.pending
21
24
  where(remote_status: 'SUCCESS', status: PENDING).order(:id)
22
25
  end
26
+
27
+ def import_data
28
+ success = true
29
+ begin
30
+ open(file_url) do |f|
31
+ begin
32
+ FileImport.import(f, project_id)
33
+ unless confirm_url.blank?
34
+ uri = URI(confirm_url)
35
+ req = Net::HTTP::Post.new(uri)
36
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
37
+ http.request(req)
38
+ end
39
+ end
40
+ update(status: Export::COMPLETE)
41
+ if Rails.application.config.respond_to?(:apidae_import_callback)
42
+ Rails.application.config.apidae_import_callback.call(self)
43
+ end
44
+ rescue Exception => ex
45
+ logger.error("Failed to import export file : #{file_url}")
46
+ logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
47
+ success = false
48
+ update(status: Export::CANCELLED)
49
+ end
50
+ end
51
+ rescue OpenURI::HTTPError => err
52
+ logger.error("Failed to download export file : #{file_url}")
53
+ logger.error("Error is : #{err}")
54
+ success = false
55
+ update(status: Export::CANCELLED)
56
+ rescue Exception => e
57
+ logger.error "Failed to import file : #{e.file_url}"
58
+ logger.error("Error is : #{err}")
59
+ success = false
60
+ e.update(status: Export::CANCELLED)
61
+ end
62
+ success
63
+ end
23
64
  end
24
65
  end
@@ -30,21 +30,18 @@ module Apidae
30
30
  Town.import(zfile.read(TOWNS_FILE))
31
31
  logger.info "Completed #{Town.count} towns update"
32
32
  end
33
- ordered_files(zfile).each do |file|
33
+ zfile.each do |file|
34
34
  if file.file? && file.name.end_with?('.json')
35
35
  logger.info "Processing file : #{file.name}"
36
36
  if file.name.include?(MODIFIED_DIR)
37
37
  add_or_update_objects(zfile.read(file.name), result, project.locales, project.versions)
38
- end
39
- if file.name.include?(SELECTIONS_FILE)
40
- add_or_update_selections(project, zfile.read(file.name), result)
41
- end
42
- if file.name.include?(DELETED_FILE)
38
+ elsif file.name.include?(DELETED_FILE)
43
39
  delete_objects(zfile.read(file.name), result)
40
+ elsif file.name.include?(SELECTIONS_FILE)
41
+ add_or_update_selections(project, zfile.read(file.name), result)
44
42
  end
45
43
  end
46
44
  end
47
- project.cleanup_selections
48
45
  create(result.except(:selections)
49
46
  .merge({remote_file: (zip_file.is_a?(File) ? zip_file.path : zip_file), status: STATUS_COMPLETE, apidae_id: project_id}))
50
47
  logger.info "Import results : #{result}"
@@ -107,16 +104,12 @@ module Apidae
107
104
  end
108
105
  end
109
106
 
110
- def self.ordered_files(zfile)
111
- zfile.sort_by {|f| f.name.include?(MODIFIED_DIR) ? 0 : (f.name.include?(SELECTIONS_FILE) ? 1 : 2)}
112
- end
113
-
114
107
  def self.delete_objects(deleted_json, result)
115
108
  deleted_ids = JSON.parse(deleted_json)
116
109
  deleted_ids.each do |id|
117
110
  obj = Obj.find_by_apidae_id(id)
118
111
  if obj
119
- obj.destroy! if obj.selections.empty?
112
+ obj.destroy!
120
113
  result[:deleted] += 1
121
114
  else
122
115
  logger.info "skipping object deletion : #{id}"
@@ -170,9 +163,7 @@ module Apidae
170
163
  def self.add_or_update_selections(project, selections_json, result)
171
164
  selections_hashes = JSON.parse(selections_json, symbolize_names: true)
172
165
  deleted_ids = Selection.where(apidae_project_id: project.id).collect {|sel| sel.apidae_id}.uniq - selections_hashes.collect {|sel| sel[:id]}
173
- apidae_selection_ids = Selection.where(apidae_id: deleted_ids).map {|s| s.id}
174
- SelectionObject.where(apidae_selection_id: apidae_selection_ids).delete_all
175
- Selection.where(id: apidae_selection_ids).delete_all
166
+ Selection.where(apidae_id: deleted_ids).delete_all
176
167
  selections_hashes.each do |selection_data|
177
168
  logger.info "Updating selection #{selection_data[:id]}"
178
169
  Selection.add_or_update(selection_data, project.id)
@@ -7,24 +7,22 @@ module Apidae
7
7
 
8
8
  attr_accessor :locale
9
9
  attr_accessor :obj_version
10
- attr_accessor :obj_versions
11
10
 
12
11
  store_accessor :title_data, :title
13
- store_accessor :owner_data, :owner_name, :owner_id, :polls
14
- store_accessor :description_data, :short_desc, :long_desc, :theme_desc, :private_desc, :accessibility_desc
12
+ store_accessor :owner_data, :owner_name, :owner_id
13
+ store_accessor :description_data, :short_desc, :long_desc, :theme_desc, :private_desc
15
14
  store_accessor :pictures_data, :pictures
16
15
  store_accessor :attachments_data, :attachments
17
- store_accessor :type_data, :categories, :themes, :capacity, :classification, :classification_date,
18
- :classification_ref, :labels, :chains, :area, :track, :tricky_sections, :products, :audience, :animals,
19
- :animals_desc, :extra, :duration, :certifications, :business, :business_equipments, :business_rooms
20
- store_accessor :entity_data, :entity_id, :entity_name, :info_entity_id, :info_entity_name, :service_provider_id, :is_service_provider, :legal
16
+ store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
17
+ :products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
18
+ store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
21
19
  store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :fax,
22
20
  :mobile_website, :shorty_url, :contacts
23
- store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments, :altitude, :map_reference
21
+ store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
24
22
  store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods, :openings_extra
25
- store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes, :rates_extra, :tax_included
26
- store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages, :documentation_languages
27
- store_accessor :booking_data, :booking_desc, :booking_entities, :visits_allowed, :visits_desc, :visits_duration, :visits_services
23
+ store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes, :rates_extra
24
+ store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages
25
+ store_accessor :booking_data, :booking_desc, :booking_entities
28
26
  store_accessor :tags_data, :promo, :internal, :linked
29
27
  store_accessor :version_data, :versioned_fields
30
28
 
@@ -85,7 +83,7 @@ module Apidae
85
83
  COS => {node: :informationsCommerceEtService, subtype: :commerceEtServiceType},
86
84
  DEG => {node: :informationsDegustation, subtype: :degustationType},
87
85
  DOS => {node: :informationsDomaineSkiable, subtype: :domaineSkiableType},
88
- EQU => {node: :informationsEquipement, subtype: :rubrique},
86
+ EQU => {node: :informationsEquipement, subtype: :equipementType},
89
87
  FEM => {node: :informationsFeteEtManifestation, subtype: :feteEtManifestationType},
90
88
  HCO => {node: :informationsHebergementCollectif, subtype: :hebergementCollectifType},
91
89
  HLO => {node: :informationsHebergementLocatif, subtype: :hebergementLocatifType},
@@ -102,7 +100,6 @@ module Apidae
102
100
  after_initialize do
103
101
  @locale = DEFAULT_LOCALE
104
102
  @obj_version = DEFAULT_VERSION
105
- @obj_versions = {}
106
103
  end
107
104
 
108
105
  def root_obj
@@ -114,15 +111,11 @@ module Apidae
114
111
  end
115
112
 
116
113
  def in_version(v)
117
- if v == DEFAULT_VERSION && root_obj_id.nil?
118
- @obj_version = DEFAULT_VERSION
119
- self
120
- else
121
- if @obj_versions[v].nil?
122
- @obj_versions[v] = versions.where(version: v).first
123
- end
124
- @obj_versions[v]
114
+ @cached_versions ||= {}
115
+ if @cached_versions[v].nil?
116
+ @cached_versions[v] = versions.where(version: v).first
125
117
  end
118
+ @cached_versions[v]
126
119
  end
127
120
 
128
121
  def in_locale(l)
@@ -171,27 +164,26 @@ module Apidae
171
164
  apidae_obj
172
165
  end
173
166
 
174
- # Note : overrides existing fields (not a merge)
175
167
  def self.populate_fields(apidae_obj, object_data, locales)
176
168
  type_fields = TYPES_DATA[object_data[:type]]
177
169
  apidae_obj.last_update = DateTime.parse(object_data[:gestion][:dateModification]) unless object_data[:gestion].blank?
178
- apidae_obj.owner_data = ApidaeDataParser.parse_owner_data(object_data[:gestion][:membreProprietaire], object_data[:enquete]) unless (object_data[:gestion].blank? && object_data[:enquete].blank?)
170
+ apidae_obj.owner_data = ApidaeDataParser.parse_owner_data(object_data[:gestion][:membreProprietaire]) unless object_data[:gestion].blank?
179
171
  apidae_obj.apidae_type = object_data[:type]
180
172
  apidae_obj.apidae_subtype = ApidaeDataParser.node_id(object_data[type_fields[:node]], type_fields[:subtype])
181
173
  apidae_obj.title_data = ApidaeDataParser.parse_title(object_data, *locales)
182
- apidae_obj.description_data = ApidaeDataParser.parse_desc_data(object_data[:presentation], object_data[:donneesPrivees], object_data[:prestations], *locales)
174
+ apidae_obj.description_data = ApidaeDataParser.parse_desc_data(object_data[:presentation], object_data[:donneesPrivees], *locales)
183
175
  apidae_obj.contact_data = ApidaeDataParser.parse_contact_data(object_data[:informations], object_data[:contacts])
184
176
  apidae_obj.location_data = ApidaeDataParser.parse_location_data(object_data[:localisation], object_data[type_fields[:node]],
185
177
  object_data[:territoires])
186
178
  apidae_obj.town = ApidaeDataParser.parse_town(object_data[:localisation])
187
179
  apidae_obj.openings_data = ApidaeDataParser.parse_openings(object_data[:ouverture], *locales)
188
180
  apidae_obj.rates_data = ApidaeDataParser.parse_rates(object_data[:descriptionTarif], *locales)
189
- apidae_obj.booking_data = ApidaeDataParser.parse_booking(object_data[:reservation], object_data[:visites], *locales)
181
+ apidae_obj.booking_data = ApidaeDataParser.parse_booking(object_data[:reservation], *locales)
190
182
  apidae_obj.type_data = ApidaeDataParser.parse_type_data(apidae_obj, object_data[type_fields[:node]], object_data[:prestations],
191
183
  object_data[:tourismeAffaires], *locales)
192
184
  apidae_obj.pictures_data = ApidaeDataParser.parse_pictures_data(object_data[:illustrations], *locales)
193
185
  apidae_obj.attachments_data = ApidaeDataParser.parse_attachments_data(object_data[:multimedias], *locales)
194
- apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]], object_data[:informationsPrestataireActivites])
186
+ apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]])
195
187
  apidae_obj.service_data = ApidaeDataParser.parse_service_data(object_data[:prestations], object_data[type_fields[:node]])
196
188
  apidae_obj.tags_data = ApidaeDataParser.parse_tags_data(object_data[:presentation], object_data[:criteresInternes], object_data[:liens])
197
189
  apidae_obj.meta_data = object_data[:metadonnees]
@@ -20,11 +20,5 @@ module Apidae
20
20
  def versions=(values)
21
21
  self.versions_data = values.blank? ? nil : values.join('|')
22
22
  end
23
-
24
- def cleanup_selections
25
- apidae_selections.reload.each do |s|
26
- s.cleanup
27
- end
28
- end
29
23
  end
30
24
  end
@@ -10,7 +10,7 @@ module Apidae
10
10
  end
11
11
 
12
12
  def self.import(refs_json)
13
- locales = Rails.application.config.respond_to?(:apidae_locales) ? Rails.application.config.apidae_locales : [DEFAULT_LOCALE]
13
+ locales = Rails.application.config.respond_to?(:apidae_locales) ? Rails.application.config.apidae_locales : [DEFAULT_LOCALE]
14
14
  locales_map = Hash[locales.map {|loc| ["libelle#{loc.camelize.gsub('-', '')}".to_sym, loc]}]
15
15
  refs_hashes = JSON.parse(refs_json, symbolize_names: true)
16
16
  if refs_hashes.length != where("apidae_type != ?", INTERNAL).count
@@ -42,20 +42,6 @@ module Apidae
42
42
  SelectionObject.where(apidae_selection_id: apidae_sel.id, apidae_object_id: removed_ids).delete_all
43
43
  end
44
44
 
45
- def cleanup
46
- obsolete_count = apidae_selection_objects
47
- .joins("LEFT JOIN apidae_objs ON apidae_objs.id = apidae_selection_objects.apidae_object_id")
48
- .where("apidae_objs.id IS NULL")
49
- .delete_all
50
- logger.info "Cleaned up #{obsolete_count} obsolete selection-objects associations for selection #{apidae_id}"
51
-
52
- dups = apidae_selection_objects.reload.group(:apidae_object_id)
53
- .select("COUNT(id), apidae_object_id, ARRAY_AGG(id) AS so_ids")
54
- .having("COUNT(id) > ?", 1).map {|so| so.so_ids}
55
- dups_count = apidae_selection_objects.where(id: dups.map {|d| d.sort[1..-1]}.flatten).delete_all
56
- logger.info "Cleaned up #{dups_count} duplicate selection-objects associations for selection #{apidae_id}"
57
- end
58
-
59
45
  def results(where_clause, offset, size)
60
46
  objects.includes(:town).limit(size).offset(offset).where(where_clause)
61
47
  end
@@ -106,7 +92,6 @@ module Apidae
106
92
  query_api(query_args, true, false)
107
93
  end
108
94
 
109
- # Note : WARNING - updated obj will only contain the provided fields
110
95
  def add_or_refresh_obj(apidae_obj_id, fields = ["@all"])
111
96
  if valid_api?
112
97
  res = api_object(apidae_obj_id, fields)
@@ -117,7 +102,6 @@ module Apidae
117
102
  end
118
103
  end
119
104
 
120
- # Note : WARNING - updated objs will only contain the provided fields
121
105
  def add_or_refresh_objs(fields = ["@all"])
122
106
  if valid_api?
123
107
  res = api_objects({fields: fields})
@@ -219,7 +203,7 @@ module Apidae
219
203
  def get_response(args)
220
204
  response = ''
221
205
  query = JSON.generate args.except(:url)
222
- logger.debug "Apidae API query : #{args[:url]}?query=#{query}"
206
+ logger.info "Apidae API query : #{args[:url]}?query=#{query}"
223
207
  open("#{args[:url]}?query=#{CGI.escape query}") { |f|
224
208
  f.each_line {|line| response += line if line}
225
209
  }
@@ -8,10 +8,9 @@ module Apidae
8
8
  LOCALE_ZH = 'zh'
9
9
  LOCALE_ES = 'es'
10
10
  LOCALE_PT_BR = 'pt-BR'
11
- LOCALE_JP = 'jp'
12
11
 
13
12
  DEFAULT_LOCALE = LOCALE_FR
14
- ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR, LOCALE_JP]
13
+ ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR]
15
14
 
16
15
  STANDARD_VERSION = 'STANDARD'
17
16
  WINTER_VERSION = 'HIVER'
@@ -25,11 +24,8 @@ module Apidae
25
24
  ALL_VERSIONS = [STANDARD_VERSION, WINTER_VERSION, SUMMER_VERSION, CHALLENGED_VERSION, BUSINESS_VERSION,
26
25
  GROUPS_VERSION, ACTIVITIES_VERSION]
27
26
 
28
- LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :pictures, :attachments,
29
- :openings_desc, :rates_desc, :includes, :excludes, :extra, :booking_desc]
30
- ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :accessibility_desc, :capacity, :telephone, :email, :website,
31
- :google, :facebook, :twitter, :yelp, :trip_advisor, :fax, :mobile_website, :shorty_url,
32
- :openings, :openings_extra, :rates, :services, :payment_methods, :categories, :themes,
33
- :labels, :chains, :classification, :challenged, :environments, :languages, :products,
34
- :animals, :equipments, :comfort, :activities, :promo, :internal, :linked]
27
+ LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :pictures, :attachments, :openings_desc, :rates_desc,
28
+ :includes, :excludes, :extra, :booking_desc]
29
+ ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :capacity, :telephone, :email, :website, :services,
30
+ :equipments, :comfort, :activities, :promo, :internal, :linked]
35
31
  end
@@ -41,7 +41,6 @@ fr:
41
41
  ru: Russe
42
42
  zh: Chinois
43
43
  'pt-BR': Brésilien
44
- jp: Japonais
45
44
  versions:
46
45
  STANDARD: Standard
47
46
  HIVER: Hiver
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.2.35"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2020_05_28_101957) do
13
+ ActiveRecord::Schema.define(version: 2020_05_22_124205) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -92,10 +92,8 @@ ActiveRecord::Schema.define(version: 2020_05_28_101957) do
92
92
  t.datetime "created_at", null: false
93
93
  t.datetime "updated_at", null: false
94
94
  t.jsonb "meta_data"
95
- t.boolean "is_active"
96
95
  t.index ["apidae_id"], name: "index_apidae_references_on_apidae_id"
97
96
  t.index ["apidae_type"], name: "index_apidae_references_on_apidae_type"
98
- t.index ["is_active"], name: "index_apidae_references_on_is_active"
99
97
  end
100
98
 
101
99
  create_table "apidae_selection_objects", force: :cascade do |t|