maestrano-connector-rails 1.3.5 → 1.4.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: c4122749ba27964c095c26a00e030bdbd3b2d7fa
4
- data.tar.gz: a48edb359406db70378f8f361ae1285ec9f51cc7
3
+ metadata.gz: e56b9e6724bd01d1877cdccbafc5e741c70161bf
4
+ data.tar.gz: c0dd848069ca945053bdfb31b84df0cb4d2a5414
5
5
  SHA512:
6
- metadata.gz: 693be8a01d2ebe2eb99679cee99352398bad9b4a0a567a78d6dbade564d37d05702137397e5ac5871f8c3095fb14e062930c34b95bf33ed83707cfbd1d626c6a
7
- data.tar.gz: 34cadd784f2410b2dfbb44e6a05e39ed17fb097729da1d04d4f5870494dd9dd372968ea882b6c1606a1a13ce61c0482653ccea01592c3dbee0c83bb2b87b1eda
6
+ metadata.gz: e6a23959d393239d71a5759f4ee589c916ca8b0f55ec410d50161952b29f516006e342285cd94ae0d32f83c7dc3da8fa59b1cea4f86dd0d4633ac344eca70d05
7
+ data.tar.gz: 0502316314c93a0d78993339d0caed4f0a3086bd8c20a6acacd53464a18674ce680cd228790aed70e0ebef7adb9be36e9043735a5f775f021fb9d034e77e75d6
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'http://rubygems.org'
3
3
  # Add dependencies required to use your gem here.
4
4
  gem 'rails', '~> 4.2'
5
5
  gem 'maestrano-rails'
6
- gem 'hash_mapper'
6
+ gem 'hash_mapper', '>= 0.2.2'
7
7
  gem 'haml-rails'
8
8
  gem 'bootstrap-sass'
9
9
  gem 'autoprefixer-rails'
data/Rakefile CHANGED
@@ -19,8 +19,8 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.license = 'MIT'
20
20
  gem.summary = 'Rails framework to build connector with Maestrano'
21
21
  gem.description = 'Maestrano is the next generation marketplace for SME applications. See https://maestrano.com for details.'
22
- gem.email = 'pierre.berard@maestrano.com'
23
- gem.authors = ['Pierre Berard']
22
+ gem.email = 'developers@maestrano.com'
23
+ gem.authors = ['Maestrano', 'Pierre Berard', 'Marco Bagnasco']
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.5
1
+ 1.4.0
@@ -5,6 +5,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
5
5
  # ----------------------------------------------
6
6
  # IdMap methods
7
7
  # ----------------------------------------------
8
+ # Default names hash used for id maps creation and look up
8
9
  def names_hash
9
10
  {
10
11
  connec_entity: connec_entity_name.downcase,
@@ -94,12 +95,18 @@ module Maestrano::Connector::Rails::Concerns::Entity
94
95
  raise 'Not implemented'
95
96
  end
96
97
 
98
+ # Optional creation only mapper, defaults to main mapper
99
+ def creation_mapper_class
100
+ mapper_class
101
+ end
102
+
97
103
  # An array of connec fields that are references
104
+ # Can also be an hash with keys record_references and id_references
98
105
  def references
99
106
  []
100
107
  end
101
108
 
102
- # An array of fields for smart merging. See connec! documentation
109
+ # An array of fields for smart merging. See Connec! documentation
103
110
  def connec_matching_fields
104
111
  nil
105
112
  end
@@ -131,14 +138,18 @@ module Maestrano::Connector::Rails::Concerns::Entity
131
138
  # ----------------------------------------------
132
139
  # Helper methods
133
140
  # ----------------------------------------------
141
+ # Returns the count and first element of the array
142
+ # Used for batch calling during the first synchronization
134
143
  def count_and_first(entities)
135
144
  {count: entities.size, first: entities.first}
136
145
  end
137
146
 
147
+ # For display purposes only
138
148
  def public_connec_entity_name
139
149
  singleton? ? connec_entity_name : connec_entity_name.pluralize
140
150
  end
141
151
 
152
+ # For display purposes only
142
153
  def public_external_entity_name
143
154
  external_entity_name.pluralize
144
155
  end
@@ -154,14 +165,26 @@ module Maestrano::Connector::Rails::Concerns::Entity
154
165
  # Mapper methods
155
166
  # ----------------------------------------------
156
167
  # Map a Connec! entity to the external model
157
- def map_to_external(entity)
158
- self.class.mapper_class.normalize(entity).with_indifferent_access
168
+ def map_to_external(entity, first_time_mapped = nil)
169
+ mapper = first_time_mapped ? self.class.creation_mapper_class : self.class.mapper_class
170
+ map_to_external_helper(entity, mapper)
171
+ end
172
+
173
+ def map_to_external_helper(entity, mapper)
174
+ # instance_values returns a hash with all the instance variables (http://apidock.com/rails/v4.0.2/Object/instance_values)
175
+ # that includes opts, organization, connec_client, external_client, and all the connector and entity specific variables
176
+ mapper.normalize(entity, instance_values.with_indifferent_access).with_indifferent_access
159
177
  end
160
178
 
161
179
  # Map an external entity to Connec! model
162
- def map_to_connec(entity)
163
- mapped_entity = self.class.mapper_class.denormalize(entity).merge(id: self.class.id_from_external_entity_hash(entity))
164
- folded_entity = Maestrano::Connector::Rails::ConnecHelper.fold_references(mapped_entity, self.class.references, @organization)
180
+ def map_to_connec(entity, first_time_mapped = nil)
181
+ mapper = first_time_mapped ? self.class.creation_mapper_class : self.class.mapper_class
182
+ map_to_connec_helper(entity, mapper, self.class.references)
183
+ end
184
+
185
+ def map_to_connec_helper(entity, mapper, references)
186
+ mapped_entity = mapper.denormalize(entity, instance_values.with_indifferent_access).merge(id: self.class.id_from_external_entity_hash(entity))
187
+ folded_entity = Maestrano::Connector::Rails::ConnecHelper.fold_references(mapped_entity, references, @organization)
165
188
  folded_entity[:opts] = (mapped_entity[:opts] || {}).merge(matching_fields: self.class.connec_matching_fields) if self.class.connec_matching_fields
166
189
  folded_entity
167
190
  end
@@ -173,6 +196,9 @@ module Maestrano::Connector::Rails::Concerns::Entity
173
196
  # * full_sync
174
197
  # * $filter (see Connec! documentation)
175
198
  # * $orderby (see Connec! documentation)
199
+ # * __skip_connec for half syncs
200
+ # * __limit and __skip for batch calls
201
+ # Returns an array of connec entities
176
202
  def get_connec_entities(last_synchronization_date = nil)
177
203
  return [] if @opts[:__skip_connec] || !self.class.can_read_connec?
178
204
 
@@ -220,15 +246,22 @@ module Maestrano::Connector::Rails::Concerns::Entity
220
246
  entities
221
247
  end
222
248
 
249
+ # Wrapper
250
+ # TODO, useless?
251
+ # Can be replace by def push_entities_to_connec_to(mapped_external_entities_with_idmaps, connec_entity_name = self.class.connec_entity_name) ?
223
252
  def push_entities_to_connec(mapped_external_entities_with_idmaps)
224
253
  push_entities_to_connec_to(mapped_external_entities_with_idmaps, self.class.connec_entity_name)
225
254
  end
226
255
 
256
+ # Pushes the external entities to Connec!, and updates the idmaps with either
257
+ # * connec_id and push timestamp
258
+ # * error message
227
259
  def push_entities_to_connec_to(mapped_external_entities_with_idmaps, connec_entity_name)
228
260
  return unless self.class.can_write_connec?
229
261
 
230
262
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending #{Maestrano::Connector::Rails::External.external_name} #{self.class.external_entity_name.pluralize} to Connec! #{connec_entity_name.pluralize}")
231
263
 
264
+ # As we're doing only POST, we use the idmaps to filter out updates
232
265
  unless self.class.can_update_connec?
233
266
  mapped_external_entities_with_idmaps.select! { |mapped_external_entity_with_idmap| !mapped_external_entity_with_idmap[:idmap].connec_id }
234
267
  end
@@ -237,6 +270,8 @@ module Maestrano::Connector::Rails::Concerns::Entity
237
270
  batch_calls(mapped_external_entities_with_idmaps, proc, connec_entity_name)
238
271
  end
239
272
 
273
+ # Helper method to build an op for batch call
274
+ # See http://maestrano.github.io/connec/#api-|-batch-calls
240
275
  def batch_op(method, mapped_external_entity, id, connec_entity_name)
241
276
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending #{method.upcase} #{connec_entity_name}: #{mapped_external_entity} to Connec! (Preparing batch request)")
242
277
  {
@@ -251,32 +286,42 @@ module Maestrano::Connector::Rails::Concerns::Entity
251
286
  # ----------------------------------------------
252
287
  # External methods
253
288
  # ----------------------------------------------
289
+ # Wrapper to process options and limitations
254
290
  def get_external_entities_wrapper(last_synchronization_date = nil, entity_name = self.class.external_entity_name)
255
291
  return [] if @opts[:__skip_external] || !self.class.can_read_external?
256
292
  get_external_entities(entity_name, last_synchronization_date)
257
293
  end
258
294
 
295
+ # To be implemented in each connector
259
296
  def get_external_entities(external_entity_name, last_synchronization_date = nil)
260
297
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Fetching #{Maestrano::Connector::Rails::External.external_name} #{external_entity_name.pluralize}")
261
298
  raise 'Not implemented'
262
299
  end
263
300
 
301
+ # Wrapper
302
+ # TODO, useless?
303
+ # Can be replace by def push_entities_to_external_to(mapped_connec_entities_with_idmaps, external_entity_name = self.class.external_entity_name) ?
264
304
  def push_entities_to_external(mapped_connec_entities_with_idmaps)
265
305
  push_entities_to_external_to(mapped_connec_entities_with_idmaps, self.class.external_entity_name)
266
306
  end
267
307
 
308
+ # Pushes connec entities to the external application
309
+ # Sends new external ids to Connec! (either only the id, or the id + the id references)
268
310
  def push_entities_to_external_to(mapped_connec_entities_with_idmaps, external_entity_name)
269
311
  return unless self.class.can_write_external?
270
312
 
271
313
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending Connec! #{self.class.connec_entity_name.pluralize} to #{Maestrano::Connector::Rails::External.external_name} #{external_entity_name.pluralize}")
314
+
272
315
  entities_to_send_to_connec = mapped_connec_entities_with_idmaps.map{ |mapped_connec_entity_with_idmap|
273
316
  push_entity_to_external(mapped_connec_entity_with_idmap, external_entity_name)
274
317
  }.compact
275
318
 
276
- return if entities_to_send_to_connec.empty?
277
-
278
319
  # Send the external ids to connec if it was a creation
279
320
  # or if there are some sub entities ids to send (completed_hash)
321
+ return if entities_to_send_to_connec.empty?
322
+
323
+ # Build a batch op from an idmap and a competed hash
324
+ # with either only the id, or the id + id references
280
325
  proc = lambda do |entity|
281
326
  id = {id: [Maestrano::Connector::Rails::ConnecHelper.id_hash(entity[:idmap].external_id, @organization)]}
282
327
  body = entity[:completed_hash] ? entity[:completed_hash].merge(id) : id
@@ -285,6 +330,12 @@ module Maestrano::Connector::Rails::Concerns::Entity
285
330
  batch_calls(entities_to_send_to_connec, proc, self.class.connec_entity_name, true)
286
331
  end
287
332
 
333
+ # Creates or updates connec entity to external
334
+ # Returns nil if there is nothing to send back to Connec!
335
+ # Returns an hash if
336
+ # - it's a creation: need to send id to Connec! (and potentially id references)
337
+ # - it's an update but it's the first push of a singleton
338
+ # - it's an update and there's id references to send to Connec!
288
339
  def push_entity_to_external(mapped_connec_entity_with_idmap, external_entity_name)
289
340
  idmap = mapped_connec_entity_with_idmap[:idmap]
290
341
  mapped_connec_entity = mapped_connec_entity_with_idmap[:entity]
@@ -324,36 +375,45 @@ module Maestrano::Connector::Rails::Concerns::Entity
324
375
  idmap.update(message: e.message.truncate(255))
325
376
  end
326
377
  end
378
+
379
+ # Nothing to send to Connec!
327
380
  nil
328
381
  end
329
382
 
383
+ # To be implemented in each connector
330
384
  def create_external_entity(mapped_connec_entity, external_entity_name)
331
385
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending create #{external_entity_name}: #{mapped_connec_entity} to #{Maestrano::Connector::Rails::External.external_name}")
332
386
  raise 'Not implemented'
333
387
  end
334
388
 
389
+ # To be implemented in each connector
335
390
  def update_external_entity(mapped_connec_entity, external_id, external_entity_name)
336
391
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending update #{external_entity_name} (id=#{external_id}): #{mapped_connec_entity} to #{Maestrano::Connector::Rails::External.external_name}")
337
392
  raise 'Not implemented'
338
393
  end
339
394
 
340
- # Maps the entity received from external after a creation or an update and complete the received ids with the connec ones
395
+ # Returns a completed hash containing id_references with both the connec and external ids
341
396
  def map_and_complete_hash_with_connec_ids(external_hash, external_entity_name, connec_hash)
342
397
  return nil if connec_hash.empty?
343
398
 
344
399
  mapped_external_hash = map_to_connec(external_hash)
345
- id_references = Maestrano::Connector::Rails::ConnecHelper.format_references(self.class.references)
400
+ references = Maestrano::Connector::Rails::ConnecHelper.format_references(self.class.references)
346
401
 
347
- Maestrano::Connector::Rails::ConnecHelper.merge_id_hashes(connec_hash, mapped_external_hash, id_references[:id_references])
402
+ Maestrano::Connector::Rails::ConnecHelper.merge_id_hashes(connec_hash, mapped_external_hash, references[:id_references])
348
403
  end
349
404
 
350
405
  # ----------------------------------------------
351
406
  # General methods
352
407
  # ----------------------------------------------
353
- # * Discards entities that do not need to be pushed because they have not been updated since their last push
354
- # * Discards entities from one of the two source in case of conflict
355
- # * Maps not discarded entities and associates them with their idmap, or create one if there isn't any
356
- # * Returns a hash {connec_entities: [], external_entities: []}
408
+ # Returns a hash containing the mapped and filtered connec and external entities
409
+ # * Discards entities that do not need to be pushed because
410
+ # * they date from before the date filtering limit (historical data)
411
+ # * they are lacking at least one reference (connec entities only)
412
+ # * they are inactive in the external application
413
+ # * they are flagged to not be shared (to_connec, to_external)
414
+ # * they have not been updated since their last push
415
+ # * Discards entities from one of the two sources in case of conflict
416
+ # * Maps not discarded entities and associates them with their idmap, or create one if there is none
357
417
  def consolidate_and_map_data(connec_entities, external_entities)
358
418
  Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Consolidating and mapping #{self.class.external_entity_name}/#{self.class.connec_entity_name}")
359
419
  return consolidate_and_map_singleton(connec_entities, external_entities) if self.class.singleton?
@@ -369,28 +429,33 @@ module Maestrano::Connector::Rails::Concerns::Entity
369
429
  # Entity has been created before date filtering limit
370
430
  next nil if before_date_filtering_limit?(entity, false) && !@opts[:full_sync]
371
431
 
432
+ # Unfold the id arrays
433
+ # From that point on, the connec_entity contains only string of external ids
372
434
  unfold_hash = Maestrano::Connector::Rails::ConnecHelper.unfold_references(entity, references, @organization)
373
435
  entity = unfold_hash[:entity]
374
- next nil unless entity
436
+ next nil unless entity # discard if at least one record reference is missing
375
437
  connec_id = unfold_hash[:connec_id]
376
438
  id_refs_only_connec_entity = unfold_hash[:id_refs_only_connec_entity]
377
439
 
378
440
  if entity['id'].blank?
441
+ # Expecting find_or_create to be mostly a create
379
442
  idmap = self.class.find_or_create_idmap(organization_id: @organization.id, name: self.class.object_name_from_connec_entity_hash(entity), external_entity: external_entity_name.downcase, connec_id: connec_id)
380
443
  next map_connec_entity_with_idmap(entity, external_entity_name, idmap, id_refs_only_connec_entity)
381
444
  end
382
445
 
446
+ # Expecting find_or_create to be mostly a find
383
447
  idmap = self.class.find_or_create_idmap(external_id: entity['id'], organization_id: @organization.id, external_entity: external_entity_name.downcase, connec_id: connec_id)
384
448
  idmap.update(name: self.class.object_name_from_connec_entity_hash(entity))
385
449
 
386
450
  next nil if idmap.external_inactive || !idmap.to_external || (!@opts[:full_sync] && not_modified_since_last_push_to_external?(idmap, entity))
451
+
387
452
  # Check for conflict with entities from external
388
453
  solve_conflict(entity, external_entities, external_entity_name, idmap, id_refs_only_connec_entity)
389
454
  }.compact
390
455
  end
391
456
 
392
457
  def consolidate_and_map_external_entities(external_entities, connec_entity_name)
393
- external_entities.map{|entity|
458
+ external_entities.map { |entity|
394
459
  # Entity has been created before date filtering limit
395
460
  next nil if before_date_filtering_limit?(entity) && !@opts[:full_sync]
396
461
 
@@ -447,6 +512,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
447
512
 
448
513
  # array_with_idmap must be an array of hashes with a key idmap
449
514
  # proc is a lambda to create a batch_op from an element of the array
515
+ # Perform batch calls on Connec API and parse the response
450
516
  def batch_calls(array_with_idmap, proc, connec_entity_name, id_update_only = false)
451
517
  request_per_call = @opts[:request_per_batch_call] || 100
452
518
  start = 0
@@ -468,6 +534,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
468
534
  response = JSON.parse(response.body)
469
535
 
470
536
  # Parse batch response
537
+ # Update idmaps with either connec_id and timestamps, or a error message
471
538
  response['results'].each_with_index do |result, index|
472
539
  if result['status'] == 200
473
540
  batch_entities[index][:idmap].update(connec_id: result['body'][self.class.normalize_connec_entity_name(connec_entity_name)]['id'].find { |id| id['provider'] == 'connec' }['id'], last_push_to_connec: Time.now, message: nil) unless id_update_only # id_update_only only apply for 200 as it's doing PUTs
@@ -475,9 +542,11 @@ module Maestrano::Connector::Rails::Concerns::Entity
475
542
  batch_entities[index][:idmap].update(connec_id: result['body'][self.class.normalize_connec_entity_name(connec_entity_name)]['id'].find { |id| id['provider'] == 'connec' }['id'], last_push_to_connec: Time.now, message: nil)
476
543
  else
477
544
  Maestrano::Connector::Rails::ConnectorLogger.log('error', @organization, "Error while pushing to Connec!: #{result['body']}")
545
+ # TODO, better error message
478
546
  batch_entities[index][:idmap].update(message: result['body'].to_s.truncate(255))
479
547
  end
480
548
  end
549
+
481
550
  start += request_per_call
482
551
  end
483
552
  end
@@ -502,7 +571,13 @@ module Maestrano::Connector::Rails::Concerns::Entity
502
571
  connec_entity['updated_at'] > self.class.last_update_date_from_external_entity_hash(external_entity)
503
572
  end
504
573
 
574
+ # This methods try to find a external entity among all the external entities matching the connec one (same id)
575
+ # If it does not find any, there is no conflict, and it returns the mapped connec entity
576
+ # If it finds one, the conflict is solved either with options or using the entities timestamps
577
+ # If the connec entity is kept, it is returned mapped and the matching external entity is discarded (deleted from the array)
578
+ # Else the method returns nil, meaning the connec entity is discarded
505
579
  def solve_conflict(connec_entity, external_entities, external_entity_name, idmap, id_refs_only_connec_entity)
580
+ # Here the connec_entity['id'] is an external id (String) because the entity has been unfolded.
506
581
  external_entity = external_entities.find { |entity| connec_entity['id'] == self.class.id_from_external_entity_hash(entity) }
507
582
  # No conflict
508
583
  return map_connec_entity_with_idmap(connec_entity, external_entity_name, idmap, id_refs_only_connec_entity) unless external_entity
@@ -522,11 +597,11 @@ module Maestrano::Connector::Rails::Concerns::Entity
522
597
  end
523
598
 
524
599
  def map_connec_entity_with_idmap(connec_entity, external_entity_name, idmap, id_refs_only_connec_entity)
525
- {entity: map_to_external(connec_entity), idmap: idmap, id_refs_only_connec_entity: id_refs_only_connec_entity}
600
+ {entity: map_to_external(connec_entity, idmap.last_push_to_external.nil?), idmap: idmap, id_refs_only_connec_entity: id_refs_only_connec_entity}
526
601
  end
527
602
 
528
603
  def map_external_entity_with_idmap(external_entity, connec_entity_name, idmap)
529
- {entity: map_to_connec(external_entity), idmap: idmap}
604
+ {entity: map_to_connec(external_entity, idmap.last_push_to_connec.nil?), idmap: idmap}
530
605
  end
531
606
 
532
607
  def fetch_connec(uri, page_number)
@@ -34,6 +34,12 @@ module Maestrano::Connector::Rails::Concerns::SubEntityBase
34
34
  {}
35
35
  end
36
36
 
37
+ # { 'External Entity' => CreationLalaMapper, 'Other external entity' => CreationLiliMapper }
38
+ # or { 'Connec Entity' => CreationLalaMapper, 'Other connec entity' => CreationLiliMapper }
39
+ def creation_mapper_classes
40
+ mapper_classes
41
+ end
42
+
37
43
  # {
38
44
  # 'External Entity' => ['organization_id'],
39
45
  # 'Other external entity' => ['an array of the connec reference fields']
@@ -43,31 +49,23 @@ module Maestrano::Connector::Rails::Concerns::SubEntityBase
43
49
  end
44
50
  end
45
51
 
46
- def map_to(name, entity)
47
- mapper = self.class.mapper_classes[name]
52
+ def map_to(name, entity, first_time_mapped = nil)
53
+ mapper = first_time_mapped ? self.class.creation_mapper_classes[name] : self.class.mapper_classes[name]
48
54
  raise "Impossible mapping from #{self.class.entity_name} to #{name}" unless mapper
49
55
 
50
56
  if self.class.external?
51
- mapped_entity = mapper.denormalize(entity).merge(id: self.class.id_from_external_entity_hash(entity))
52
- folded_entity = Maestrano::Connector::Rails::ConnecHelper.fold_references(mapped_entity, self.class.references[name] || [], @organization)
53
-
54
- if self.class.connec_matching_fields
55
- folded_entity[:opts] ||= {}
56
- folded_entity[:opts][:matching_fields] = self.class.connec_matching_fields
57
- end
58
-
59
- folded_entity
57
+ map_to_connec_helper(entity, mapper, self.class.references[name] || [])
60
58
  else
61
- mapper.normalize(entity).with_indifferent_access
59
+ map_to_external_helper(entity, mapper)
62
60
  end
63
61
  end
64
62
 
65
63
  def map_connec_entity_with_idmap(connec_entity, external_entity_name, idmap, id_refs_only_connec_entity)
66
- {entity: map_to(external_entity_name, connec_entity), idmap: idmap, id_refs_only_connec_entity: id_refs_only_connec_entity}
64
+ {entity: map_to(external_entity_name, connec_entity, idmap.last_push_to_external.nil?), idmap: idmap, id_refs_only_connec_entity: id_refs_only_connec_entity}
67
65
  end
68
66
 
69
67
  def map_external_entity_with_idmap(external_entity, connec_entity_name, idmap)
70
- {entity: map_to(connec_entity_name, external_entity), idmap: idmap}
68
+ {entity: map_to(connec_entity_name, external_entity, idmap.last_push_to_connec.nil?), idmap: idmap}
71
69
  end
72
70
 
73
71
  # Maps the entity received from external after a creation or an update and complete the received ids with the connec ones
@@ -17,6 +17,14 @@
17
17
  # ExampleEntityMapper
18
18
  # end
19
19
 
20
+ # This method is optional. It is needed only if a mandatory field
21
+ # is missing in Connec! and has to be pushed with a default value on creation.
22
+ # Refer to the FAQ section for more details.
23
+
24
+ # def self.creation_mapper_class
25
+ # CreationExampleEntityMapper
26
+ # end
27
+
20
28
  # def self.object_name_from_connec_entity_hash(entity)
21
29
  # "#{entity['first_name']} #{entity['last_name']}"
22
30
  # end
@@ -27,6 +35,13 @@
27
35
 
28
36
  # end
29
37
 
38
+ # class CreationExampleEntityMapper < ExampleEntityMapper
39
+ #
40
+ # after_normalize do |input, output|
41
+ # output[:missing_connec_field] = "Default Value"
42
+ # end
43
+ # end
44
+
30
45
  # class ExampleEntityMapper
31
46
  # extend HashMapper
32
47
 
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: maestrano-connector-rails 1.3.5 ruby lib
5
+ # stub: maestrano-connector-rails 1.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "1.3.5"
9
+ s.version = "1.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
- s.authors = ["Pierre Berard"]
14
- s.date = "2016-08-19"
13
+ s.authors = ["Maestrano", "Pierre Berard", "Marco Bagnasco"]
14
+ s.date = "2016-08-24"
15
15
  s.description = "Maestrano is the next generation marketplace for SME applications. See https://maestrano.com for details."
16
- s.email = "pierre.berard@maestrano.com"
16
+ s.email = "developers@maestrano.com"
17
17
  s.executables = ["rails"]
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE",
@@ -224,7 +224,7 @@ Gem::Specification.new do |s|
224
224
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
225
225
  s.add_runtime_dependency(%q<rails>, ["~> 4.2"])
226
226
  s.add_runtime_dependency(%q<maestrano-rails>, [">= 0"])
227
- s.add_runtime_dependency(%q<hash_mapper>, [">= 0"])
227
+ s.add_runtime_dependency(%q<hash_mapper>, [">= 0.2.2"])
228
228
  s.add_runtime_dependency(%q<haml-rails>, [">= 0"])
229
229
  s.add_runtime_dependency(%q<bootstrap-sass>, [">= 0"])
230
230
  s.add_runtime_dependency(%q<autoprefixer-rails>, [">= 0"])
@@ -250,7 +250,7 @@ Gem::Specification.new do |s|
250
250
  else
251
251
  s.add_dependency(%q<rails>, ["~> 4.2"])
252
252
  s.add_dependency(%q<maestrano-rails>, [">= 0"])
253
- s.add_dependency(%q<hash_mapper>, [">= 0"])
253
+ s.add_dependency(%q<hash_mapper>, [">= 0.2.2"])
254
254
  s.add_dependency(%q<haml-rails>, [">= 0"])
255
255
  s.add_dependency(%q<bootstrap-sass>, [">= 0"])
256
256
  s.add_dependency(%q<autoprefixer-rails>, [">= 0"])
@@ -277,7 +277,7 @@ Gem::Specification.new do |s|
277
277
  else
278
278
  s.add_dependency(%q<rails>, ["~> 4.2"])
279
279
  s.add_dependency(%q<maestrano-rails>, [">= 0"])
280
- s.add_dependency(%q<hash_mapper>, [">= 0"])
280
+ s.add_dependency(%q<hash_mapper>, [">= 0.2.2"])
281
281
  s.add_dependency(%q<haml-rails>, [">= 0"])
282
282
  s.add_dependency(%q<bootstrap-sass>, [">= 0"])
283
283
  s.add_dependency(%q<autoprefixer-rails>, [">= 0"])