apidae 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/apidae/import_controller.rb +2 -40
- data/app/helpers/apidae/application_helper.rb +1 -1
- data/app/models/apidae/apidae_data_parser.rb +0 -1
- data/app/models/apidae/export.rb +41 -0
- data/app/models/apidae/obj.rb +4 -11
- data/app/models/apidae/reference.rb +1 -1
- data/app/models/apidae/selection.rb +0 -2
- data/config/initializers/constants.rb +3 -6
- data/lib/apidae/version.rb +1 -1
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11f5031e46f8bfa23ce228c242e023c4ebe10e0e
|
4
|
+
data.tar.gz: '0083f65ff4cfbd3f53c5a13126ca940c4be696ae'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
}
|
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
@@ -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
|
@@ -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
|
-
|
117
|
-
|
118
|
-
|
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?
|
@@ -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,7 +92,6 @@ 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
|
96
95
|
def add_or_refresh_obj(apidae_obj_id, fields = ["@all"])
|
97
96
|
if valid_api?
|
98
97
|
res = api_object(apidae_obj_id, fields)
|
@@ -103,7 +102,6 @@ module Apidae
|
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
|
-
# Note : WARNING - updated objs will only contain the provided fields
|
107
105
|
def add_or_refresh_objs(fields = ["@all"])
|
108
106
|
if valid_api?
|
109
107
|
res = api_objects({fields: fields})
|
@@ -24,11 +24,8 @@ module Apidae
|
|
24
24
|
ALL_VERSIONS = [STANDARD_VERSION, WINTER_VERSION, SUMMER_VERSION, CHALLENGED_VERSION, BUSINESS_VERSION,
|
25
25
|
GROUPS_VERSION, ACTIVITIES_VERSION]
|
26
26
|
|
27
|
-
LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :
|
28
|
-
:
|
29
|
-
ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :capacity, :telephone, :email, :website,
|
30
|
-
:google, :facebook, :twitter, :yelp, :trip_advisor, :fax, :mobile_website, :shorty_url,
|
31
|
-
:openings, :rates, :services, :payment_methods, :categories, :themes, :labels, :chains,
|
32
|
-
:classification, :challenged, :environments, :languages, :products, :animals,
|
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,
|
33
30
|
:equipments, :comfort, :activities, :promo, :internal, :linked]
|
34
31
|
end
|
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.
|
4
|
+
version: 1.3.0
|
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-10-
|
11
|
+
date: 2020-10-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: '
|
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
|