apidae 1.2.8 → 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
2
  SHA1:
3
- metadata.gz: 60d30181c595dde4d2f63e3389cfab37de03ba14
4
- data.tar.gz: c4f2dc5189846f3068537fa832735bdedee85cc1
3
+ metadata.gz: 11f5031e46f8bfa23ce228c242e023c4ebe10e0e
4
+ data.tar.gz: '0083f65ff4cfbd3f53c5a13126ca940c4be696ae'
5
5
  SHA512:
6
- metadata.gz: 259771713e098dcfee2c5e20f1c42ec5209dc976a38177b43cb7580eb5a4bec5b6d6e3cdbc790a8ef1f1c37e4af2b55d3d1cc40401ad6da95f8cea60d9e05b20
7
- data.tar.gz: 95a7109af9633d25cba07aaf58268905c51bcb9dc72387e0a13ab1b0a60868fa1e2cf32bfb1a1c38e00cf84b97a60ef8ad3582f4330c4aadce427cc877178a62
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)
@@ -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,15 +335,10 @@ module Apidae
336
335
  end
337
336
  end
338
337
 
339
- def self.parse_entity_fields(information_hash, type_data_hash, sp_hash)
340
- entity_hash = {}
338
+ def self.parse_entity_fields(information_hash, type_data_hash)
341
339
  if information_hash && information_hash[:structureGestion]
342
- entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)})
340
+ {entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)}
343
341
  end
344
- if sp_hash && sp_hash[:prestataireActivites]
345
- entity_hash[:is_service_provider] = true
346
- end
347
- entity_hash
348
342
  end
349
343
 
350
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
@@ -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
@@ -16,7 +15,7 @@ module Apidae
16
15
  store_accessor :attachments_data, :attachments
17
16
  store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
18
17
  :products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
19
- store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id, :is_service_provider
18
+ store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
20
19
  store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :fax,
21
20
  :mobile_website, :shorty_url, :contacts
22
21
  store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
@@ -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?
@@ -190,7 +183,7 @@ module Apidae
190
183
  object_data[:tourismeAffaires], *locales)
191
184
  apidae_obj.pictures_data = ApidaeDataParser.parse_pictures_data(object_data[:illustrations], *locales)
192
185
  apidae_obj.attachments_data = ApidaeDataParser.parse_attachments_data(object_data[:multimedias], *locales)
193
- 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]])
194
187
  apidae_obj.service_data = ApidaeDataParser.parse_service_data(object_data[:prestations], object_data[type_fields[:node]])
195
188
  apidae_obj.tags_data = ApidaeDataParser.parse_tags_data(object_data[:presentation], object_data[:criteresInternes], object_data[:liens])
196
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
- 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
@@ -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})
@@ -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, :capacity, :telephone, :email, :website,
31
- :google, :facebook, :twitter, :yelp, :trip_advisor, :fax, :mobile_website, :shorty_url,
32
- :openings, :rates, :services, :payment_methods, :categories, :themes, :labels, :chains,
33
- :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,
34
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.8"
2
+ VERSION = "1.3.0"
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.8
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-12-02 00:00:00.000000000 Z
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: '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