apidae 1.2.5 → 1.3.2
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 +4 -4
- data/app/controllers/apidae/import_controller.rb +2 -40
- data/app/helpers/apidae/application_helper.rb +1 -1
- data/app/helpers/apidae/extendable_helper.rb +4 -0
- data/app/models/apidae/apidae_data_parser.rb +7 -3
- data/app/models/apidae/export.rb +41 -0
- data/app/models/apidae/obj.rb +2 -2
- data/app/models/apidae/reference.rb +1 -1
- data/app/models/apidae/selection.rb +2 -0
- data/app/models/apidae/territory.rb +17 -0
- data/config/initializers/constants.rb +2 -1
- data/config/locales/apidae.fr.yml +1 -0
- data/db/migrate/20201112080847_create_apidae_territories.rb +10 -0
- data/lib/apidae/version.rb +1 -1
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3df5740373cfa229b7411e21a55eae04df831561
|
4
|
+
data.tar.gz: ec010b9d61a4cea4fa552180531f606498e04231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 141dca6a42911917ad0722772df54b4f542364de8fe1502586e6710d9a37b0ade5cddd9abf5994b6768d8597b66fe3627f4fa3068d8d8da7506a4f899fa34737
|
7
|
+
data.tar.gz: 17f51ee8066cd53f353bf91f395191bb78255343f65f7978ff01e56c27b9205d91203687ad0c7b4b234cb05b88116decba24df1eba317b51d52992a9baa9495e
|
@@ -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
|
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 &&
|
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
|
@@ -236,7 +236,6 @@ module Apidae
|
|
236
236
|
openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
|
237
237
|
openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
238
238
|
openings: build_openings(openings_hash, *locales),
|
239
|
-
all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false',
|
240
239
|
time_periods: lists_ids(openings_hash[:indicationsPeriode]),
|
241
240
|
openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
|
242
241
|
}
|
@@ -336,10 +335,15 @@ module Apidae
|
|
336
335
|
end
|
337
336
|
end
|
338
337
|
|
339
|
-
def self.parse_entity_fields(information_hash, type_data_hash)
|
338
|
+
def self.parse_entity_fields(information_hash, type_data_hash, sp_hash)
|
339
|
+
entity_hash = {}
|
340
340
|
if information_hash && information_hash[:structureGestion]
|
341
|
-
{entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)}
|
341
|
+
entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)})
|
342
342
|
end
|
343
|
+
if sp_hash && sp_hash[:prestataireActivites]
|
344
|
+
entity_hash[:is_service_provider] = true
|
345
|
+
end
|
346
|
+
entity_hash
|
343
347
|
end
|
344
348
|
|
345
349
|
def self.node_id(node, key)
|
data/app/models/apidae/export.rb
CHANGED
@@ -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
|
data/app/models/apidae/obj.rb
CHANGED
@@ -15,7 +15,7 @@ module Apidae
|
|
15
15
|
store_accessor :attachments_data, :attachments
|
16
16
|
store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
|
17
17
|
:products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
|
18
|
-
store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
|
18
|
+
store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id, :is_service_provider
|
19
19
|
store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :fax,
|
20
20
|
:mobile_website, :shorty_url, :contacts
|
21
21
|
store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
|
@@ -183,7 +183,7 @@ module Apidae
|
|
183
183
|
object_data[:tourismeAffaires], *locales)
|
184
184
|
apidae_obj.pictures_data = ApidaeDataParser.parse_pictures_data(object_data[:illustrations], *locales)
|
185
185
|
apidae_obj.attachments_data = ApidaeDataParser.parse_attachments_data(object_data[:multimedias], *locales)
|
186
|
-
apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]])
|
186
|
+
apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]], object_data[:informationsPrestataireActivites])
|
187
187
|
apidae_obj.service_data = ApidaeDataParser.parse_service_data(object_data[:prestations], object_data[type_fields[:node]])
|
188
188
|
apidae_obj.tags_data = ApidaeDataParser.parse_tags_data(object_data[:presentation], object_data[:criteresInternes], object_data[:liens])
|
189
189
|
apidae_obj.meta_data = object_data[:metadonnees]
|
@@ -10,7 +10,7 @@ module Apidae
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.import(refs_json)
|
13
|
-
|
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
|
@@ -92,6 +92,7 @@ module Apidae
|
|
92
92
|
query_api(query_args, true, false)
|
93
93
|
end
|
94
94
|
|
95
|
+
# Note : WARNING - updated obj will only contain the provided fields
|
95
96
|
def add_or_refresh_obj(apidae_obj_id, fields = ["@all"])
|
96
97
|
if valid_api?
|
97
98
|
res = api_object(apidae_obj_id, fields)
|
@@ -102,6 +103,7 @@ module Apidae
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
106
|
+
# Note : WARNING - updated objs will only contain the provided fields
|
105
107
|
def add_or_refresh_objs(fields = ["@all"])
|
106
108
|
if valid_api?
|
107
109
|
res = api_objects({fields: fields})
|
@@ -0,0 +1,17 @@
|
|
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
|
+
t.save!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.import_file(json_file)
|
13
|
+
territories_json = File.read(json_file)
|
14
|
+
import(territories_json)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -8,9 +8,10 @@ module Apidae
|
|
8
8
|
LOCALE_ZH = 'zh'
|
9
9
|
LOCALE_ES = 'es'
|
10
10
|
LOCALE_PT_BR = 'pt-BR'
|
11
|
+
LOCALE_JP = 'jp'
|
11
12
|
|
12
13
|
DEFAULT_LOCALE = LOCALE_FR
|
13
|
-
ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR]
|
14
|
+
ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR, LOCALE_JP]
|
14
15
|
|
15
16
|
STANDARD_VERSION = 'STANDARD'
|
16
17
|
WINTER_VERSION = 'HIVER'
|
data/lib/apidae/version.rb
CHANGED
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
|
4
|
+
version: 1.3.2
|
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: 2020-
|
11
|
+
date: 2020-12-02 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: '
|
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: '
|
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: '
|
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: '
|
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,7 @@ 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
|
184
193
|
- lib/apidae.rb
|
185
194
|
- lib/apidae/engine.rb
|
186
195
|
- lib/apidae/version.rb
|