apidae 1.2.13 → 1.3.3

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
2
  SHA1:
3
- metadata.gz: d44db939b2c69c3821b8c82b9e38441b69e63ab7
4
- data.tar.gz: 5762520b0275479d67ce316d177c3f750c7519e1
3
+ metadata.gz: d1f8d7ad0798847cc0b3882958e5f557f1f01219
4
+ data.tar.gz: 94d139b245115c273ec4c73b385c380bf816da87
5
5
  SHA512:
6
- metadata.gz: 12d44dcf49f4b3288ed04381405fc0188adb8715aa49cd2586b80a3bdab572780ba47470dfcab7d0033b21c05ebb5a42583ab346cd64c309d62b64d0da92aa3f
7
- data.tar.gz: 63edb21d44e5997086a883570ac71de38e3910f85d39c322cbe37acdf377bbb2d764f08af339e1b1703f2279b29543259107610942de3b64830ee828940657ed
6
+ metadata.gz: 47dea0045600b59233e78a4616396aee8341de70e9121a335741fbe66d39ffea03e18503564a83c4cd9fe496ebe7058b7ba13690c902f794f46967146d65b16d
7
+ data.tar.gz: 2350154e37a3fac1d56eed268eb322309842fcf8b349c2e2b28c63af4605aa3cb15c1b629f31a60d740ffe6ec6b9778e9c2a9ae4f03414ae9c86a3023661c719
@@ -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)
@@ -0,0 +1,4 @@
1
+ module Apidae
2
+ module ExtendableHelper
3
+ end
4
+ end
@@ -151,7 +151,6 @@ module Apidae
151
151
  name: localized_value(att, :nom, locale),
152
152
  url: att[:traductionFichiers][0][:url].gsub('http:', 'https:'),
153
153
  type: att[:type],
154
- link: att[:link],
155
154
  description: localized_value(att, :legende, locale)
156
155
  }
157
156
  end
@@ -223,7 +222,6 @@ module Apidae
223
222
  loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1]
224
223
  loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0]
225
224
  end
226
- loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details
227
225
  loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details
228
226
  loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements]
229
227
  end
@@ -238,7 +236,6 @@ module Apidae
238
236
  openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
239
237
  openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
240
238
  openings: build_openings(openings_hash, *locales),
241
- all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false',
242
239
  time_periods: lists_ids(openings_hash[:indicationsPeriode]),
243
240
  openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
244
241
  }
@@ -278,8 +275,7 @@ module Apidae
278
275
  (node_id(data_hash, :typeLabel) ? [node_id(data_hash, :typeLabel)] : []),
279
276
  chains: lists_ids(data_hash[:chaines]) + nodes_ids(data_hash[:chaineEtLabel]),
280
277
  area: apidae_obj.apidae_type == Obj::DOS ? data_hash.except(:classification) : node_value(data_hash, :lieuDePratique),
281
- track: apidae_obj.apidae_type == Obj::EQU ? (data_hash[:itineraire] || {}).except(:passagesDelicats) : nil,
282
- tricky_sections: apidae_obj.apidae_type == Obj::EQU ? data_hash.dig(:itineraire, :passagesDelicats) : nil,
278
+ track: apidae_obj.apidae_type == Obj::EQU ? data_hash[:itineraire] : nil,
283
279
  products: lists_ids(data_hash[:typesProduit], data_hash[:aopAocIgps], data_hash[:specialites]),
284
280
  audience: lists_ids(prestations_hash[:typesClientele]),
285
281
  animals: {allowed: prestations_hash[:animauxAcceptes] == 'ACCEPTES', desc: node_value(prestations_hash, :descriptifAnimauxAcceptes, *locales),
@@ -321,17 +317,13 @@ module Apidae
321
317
  tags
322
318
  end
323
319
 
324
- def self.parse_booking(reservation_hash, visits_hash, *locales)
325
- booking_hash = {}
320
+ def self.parse_booking(reservation_hash, *locales)
326
321
  if reservation_hash
327
- booking_hash[:booking_desc] = node_value(reservation_hash, :complement, *locales),
328
- booking_hash[:booking_entities] = reservation_hash[:organismes]
329
- end
330
- if visits_hash
331
- booking_hash[:visits_allowed] = visits_hash[:visitable] == true
332
- booking_hash[:visits_desc] = node_value(visits_hash, :complementVisite, *locales)
322
+ {
323
+ booking_desc: node_value(reservation_hash, :complement, *locales),
324
+ booking_entities: reservation_hash[:organismes]
325
+ }
333
326
  end
334
- booking_hash
335
327
  end
336
328
 
337
329
  def self.parse_town(location_hash)
@@ -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
@@ -7,7 +7,6 @@ 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
12
  store_accessor :owner_data, :owner_name, :owner_id
@@ -15,15 +14,15 @@ module Apidae
15
14
  store_accessor :pictures_data, :pictures
16
15
  store_accessor :attachments_data, :attachments
17
16
  store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
18
- :tricky_sections, :products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
17
+ :products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
19
18
  store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id, :is_service_provider
20
19
  store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :fax,
21
20
  :mobile_website, :shorty_url, :contacts
22
- store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments, :altitude
21
+ store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
23
22
  store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods, :openings_extra
24
23
  store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes, :rates_extra
25
24
  store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages
26
- store_accessor :booking_data, :booking_desc, :booking_entities, :visits_allowed, :visits_desc
25
+ store_accessor :booking_data, :booking_desc, :booking_entities
27
26
  store_accessor :tags_data, :promo, :internal, :linked
28
27
  store_accessor :version_data, :versioned_fields
29
28
 
@@ -84,7 +83,7 @@ module Apidae
84
83
  COS => {node: :informationsCommerceEtService, subtype: :commerceEtServiceType},
85
84
  DEG => {node: :informationsDegustation, subtype: :degustationType},
86
85
  DOS => {node: :informationsDomaineSkiable, subtype: :domaineSkiableType},
87
- EQU => {node: :informationsEquipement, subtype: :rubrique},
86
+ EQU => {node: :informationsEquipement, subtype: :equipementType},
88
87
  FEM => {node: :informationsFeteEtManifestation, subtype: :feteEtManifestationType},
89
88
  HCO => {node: :informationsHebergementCollectif, subtype: :hebergementCollectifType},
90
89
  HLO => {node: :informationsHebergementLocatif, subtype: :hebergementLocatifType},
@@ -101,7 +100,6 @@ module Apidae
101
100
  after_initialize do
102
101
  @locale = DEFAULT_LOCALE
103
102
  @obj_version = DEFAULT_VERSION
104
- @obj_versions = {}
105
103
  end
106
104
 
107
105
  def root_obj
@@ -113,15 +111,11 @@ module Apidae
113
111
  end
114
112
 
115
113
  def in_version(v)
116
- if v == DEFAULT_VERSION && root_obj_id.nil?
117
- @obj_version = DEFAULT_VERSION
118
- self
119
- else
120
- if @obj_versions[v].nil?
121
- @obj_versions[v] = versions.where(version: v).first
122
- end
123
- @obj_versions[v]
114
+ @cached_versions ||= {}
115
+ if @cached_versions[v].nil?
116
+ @cached_versions[v] = versions.where(version: v).first
124
117
  end
118
+ @cached_versions[v]
125
119
  end
126
120
 
127
121
  def in_locale(l)
@@ -170,7 +164,6 @@ module Apidae
170
164
  apidae_obj
171
165
  end
172
166
 
173
- # Note : overrides existing fields (not a merge)
174
167
  def self.populate_fields(apidae_obj, object_data, locales)
175
168
  type_fields = TYPES_DATA[object_data[:type]]
176
169
  apidae_obj.last_update = DateTime.parse(object_data[:gestion][:dateModification]) unless object_data[:gestion].blank?
@@ -185,7 +178,7 @@ module Apidae
185
178
  apidae_obj.town = ApidaeDataParser.parse_town(object_data[:localisation])
186
179
  apidae_obj.openings_data = ApidaeDataParser.parse_openings(object_data[:ouverture], *locales)
187
180
  apidae_obj.rates_data = ApidaeDataParser.parse_rates(object_data[:descriptionTarif], *locales)
188
- 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)
189
182
  apidae_obj.type_data = ApidaeDataParser.parse_type_data(apidae_obj, object_data[type_fields[:node]], object_data[:prestations],
190
183
  object_data[:tourismeAffaires], *locales)
191
184
  apidae_obj.pictures_data = ApidaeDataParser.parse_pictures_data(object_data[:illustrations], *locales)
@@ -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
@@ -69,7 +69,7 @@ module Apidae
69
69
  key = cache_key(:agenda, from, to)
70
70
  res = $apidae_cache.read(key)
71
71
  unless res
72
- query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to})
72
+ query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to, count: 200})
73
73
  res = query_api(query_args, true)
74
74
  $apidae_cache.write(key, res)
75
75
  end
@@ -142,14 +142,15 @@ module Apidae
142
142
 
143
143
  if all_results
144
144
  loops = 0
145
+ max_loops = only_ids ? 50 : MAX_LOOPS
145
146
  query_args[:first] = 0
146
- query_args[:count] = MAX_COUNT
147
+ query_args[:count] ||= MAX_COUNT
147
148
  query_args[:locales] ||= apidae_project && !apidae_project.locales.blank? ? apidae_project.locales : [DEFAULT_LOCALE]
148
149
  response = JSON.parse get_response(query_args), symbolize_names: false
149
150
  total = response['numFound']
150
151
  query_result[:results] = (only_ids ? response['objetTouristiqueIds'] : response['objetsTouristiques']) || {}
151
152
 
152
- while total > results_count(query_result) && loops < MAX_LOOPS
153
+ while total > results_count(query_result) && loops < max_loops
153
154
  loops += 1
154
155
  query_args[:first] += MAX_COUNT
155
156
  response = JSON.parse get_response(query_args), symbolize_names: false
@@ -0,0 +1,18 @@
1
+ module Apidae
2
+ class Territory < ApplicationRecord
3
+ def self.import(territories_json)
4
+ territories_hashes = JSON.parse(territories_json, symbolize_names: true)
5
+ territories_hashes.each do |t_data|
6
+ t = Territory.find_or_initialize_by(apidae_id: t_data[:id])
7
+ t.name = t_data.dig(:nom, :libelleFr)
8
+
9
+ t.save!
10
+ end
11
+ end
12
+
13
+ def self.import_file(json_file)
14
+ territories_json = File.read(json_file)
15
+ import(territories_json)
16
+ end
17
+ end
18
+ end
@@ -25,11 +25,8 @@ module Apidae
25
25
  ALL_VERSIONS = [STANDARD_VERSION, WINTER_VERSION, SUMMER_VERSION, CHALLENGED_VERSION, BUSINESS_VERSION,
26
26
  GROUPS_VERSION, ACTIVITIES_VERSION]
27
27
 
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, :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]
28
+ LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :pictures, :attachments, :openings_desc, :rates_desc,
29
+ :includes, :excludes, :extra, :booking_desc]
30
+ ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :capacity, :telephone, :email, :website, :services,
31
+ :equipments, :comfort, :activities, :promo, :internal, :linked]
35
32
  end
@@ -0,0 +1,10 @@
1
+ class CreateApidaeTerritories < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :apidae_territories do |t|
4
+ t.integer :apidae_id
5
+ t.string :name
6
+ end
7
+
8
+ add_index :apidae_territories, :apidae_id
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddApidaeTypeToApidaeTerritories < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :apidae_territories, :apidae_type, :integer
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.2.13"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.13
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,20 +41,23 @@ dependencies:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rubyzip
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.0'
53
+ version: '2.0'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.0'
60
+ version: '2.0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: jbuilder
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +97,7 @@ files:
91
97
  - app/helpers/apidae/apidae_helper.rb
92
98
  - app/helpers/apidae/application_helper.rb
93
99
  - app/helpers/apidae/dashboard_helper.rb
100
+ - app/helpers/apidae/extendable_helper.rb
94
101
  - app/helpers/apidae/import_helper.rb
95
102
  - app/helpers/apidae/objects_helper.rb
96
103
  - app/helpers/apidae/references_helper.rb
@@ -104,6 +111,7 @@ files:
104
111
  - app/models/apidae/reference.rb
105
112
  - app/models/apidae/selection.rb
106
113
  - app/models/apidae/selection_object.rb
114
+ - app/models/apidae/territory.rb
107
115
  - app/models/apidae/town.rb
108
116
  - app/views/apidae/dashboard/index.html.erb
109
117
  - app/views/apidae/import/_form.html.erb
@@ -181,6 +189,8 @@ files:
181
189
  - db/migrate/20200312150904_add_version_index_on_apidae_objs.rb
182
190
  - db/migrate/20200522124205_rename_objs_contact_to_contact_data.rb
183
191
  - db/migrate/20200528101957_add_is_active_to_apidae_references.rb
192
+ - db/migrate/20201112080847_create_apidae_territories.rb
193
+ - db/migrate/20210607214647_add_apidae_type_to_apidae_territories.rb
184
194
  - lib/apidae.rb
185
195
  - lib/apidae/engine.rb
186
196
  - lib/apidae/version.rb