maestrano-connector-rails 0.4.3 → 0.4.4

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: 173bdf0c540c2e0218f01962ca98defe2e678bb9
4
- data.tar.gz: f4e34051fbecb1035281eea03895e8b98ad4f418
3
+ metadata.gz: e2b30b01e9635bb23e54086aa72a76209ff6ff90
4
+ data.tar.gz: 093c8366dae9dd669fd6989f95e8030c44698d1b
5
5
  SHA512:
6
- metadata.gz: 031e61b8d07199ad89fbc7cae4b5bb245f9c1873d04964bb1c2a698aa5f1ef016faa4e72c61c9939e6b25bacf283949d785ad1c4b31bee2c90b1239cc8162a25
7
- data.tar.gz: 1dbcaf2614a24187b2a9ab91629a32f6da76876107b934fce5e31f977b6ac15aaac3877564a35721c24a21b5b1c3370a641cd4ef814da4afc90e237a23754452
6
+ metadata.gz: c4e022328533a25167c5c3d37b4c146edf6a9d88bec6d952209a3a52d3b156f7262800bdc7148ba8a4320272a4e39720704adb57529ccb294cfda08e5fd623a1
7
+ data.tar.gz: cd8609ffcf02458ea2b97419076ec7e521a28fa9fde702d2ce7c6bd9fecf773c6cc63dc9fb3a708f8e5bfb3f46132984d1ce71b2226715b31172f8c2b5c196cd
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -4,7 +4,7 @@ class Maestrano::ConnecController < Maestrano::Rails::WebHookController
4
4
  Rails.logger.debug "Received notification from Connec!: #{params}"
5
5
 
6
6
  begin
7
- params.except(:tenant, :controller, :action).each do |entity_name, entities|
7
+ params.except(:tenant, :controller, :action, :connec).each do |entity_name, entities|
8
8
 
9
9
  entity_instance_hash = find_entity_instance(entity_name)
10
10
  next Rails.logger.info "Received notification from Connec! for unknow entity: #{entity_name}" unless entity_instance_hash
@@ -23,11 +23,15 @@ class Maestrano::ConnecController < Maestrano::Rails::WebHookController
23
23
  last_synchronization = organization.last_successful_synchronization
24
24
 
25
25
  entity_instance.before_sync(connec_client, external_client, last_synchronization, organization, {})
26
+
27
+
26
28
  # Build expected input for consolidate_and_map_data
27
29
  if entity_instance_hash[:is_complex]
28
- mapped_entity = entity_instance.consolidate_and_map_data(Hash[ *entity_instance.class.connec_entities_names.collect{|name| name.parameterize('_').pluralize == entity_name ? [name, [entity]] : [ name, []]}.flatten(1) ], Hash[ *entity_instance.class.external_entities_names.collect{|name| [ name, []]}.flatten(1) ], organization, {})
30
+ filtered_entities = entity_instance.filter_connec_entities(Hash[ *entity_instance.class.connec_entities_names.collect{|name| name.parameterize('_').pluralize == entity_name ? [name, [entity]] : [ name, []]}.flatten(1) ], organization)
31
+ mapped_entity = entity_instance.consolidate_and_map_data(filtered_entities, Hash[ *entity_instance.class.external_entities_names.collect{|name| [ name, []]}.flatten(1) ], organization, {})
29
32
  else
30
- mapped_entity = entity_instance.consolidate_and_map_data([entity], [], organization, {})
33
+ filtered_entities = entity_instance.filter_connec_entities([entity], organization)
34
+ mapped_entity = entity_instance.consolidate_and_map_data(filtered_entities, [], organization, {})
31
35
  end
32
36
  entity_instance.push_entities_to_external(external_client, mapped_entity[:connec_entities], organization)
33
37
 
@@ -176,4 +176,14 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
176
176
  def after_sync(connec_client, external_client, last_synchronization, organization, opts)
177
177
  # Does nothing by default
178
178
  end
179
+
180
+ # This method is called during the webhook workflow only. It should return the hash of arrays of filtered entities
181
+ # The aim is to have the same filtering as with the Connec! filters on API calls in the webhooks
182
+ # input : {
183
+ # external_entities_names[0]: [unmapped_external_entity1}, unmapped_external_entity2],
184
+ # external_entities_names[1]: [unmapped_external_entity3}, unmapped_external_entity4]
185
+ # }
186
+ def filter_connec_entities(entities, organization, opts={})
187
+ entities
188
+ end
179
189
  end
@@ -267,7 +267,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
267
267
  batch_entities[index][:idmap].update_attributes(connec_id: result['body'][self.class.normalize_connec_entity_name(connec_entity_name)]['id'], last_push_to_connec: Time.now, message: nil)
268
268
  else
269
269
  Maestrano::Connector::Rails::ConnectorLogger.log('error', organization, "Error while pushing to Connec!: #{result['body']}")
270
- batch_entities[index][:idmap].update_attributes(message: result['body'])
270
+ batch_entities[index][:idmap].update_attributes(message: result['body'].truncate(255))
271
271
  end
272
272
  end
273
273
  start += request_per_call
@@ -340,7 +340,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
340
340
  rescue => e
341
341
  # Store External error
342
342
  Maestrano::Connector::Rails::ConnectorLogger.log('error', organization, "Error while pushing to #{Maestrano::Connector::Rails::External.external_name}: #{e}")
343
- idmap.update_attributes(message: e.message)
343
+ idmap.update_attributes(message: e.message.truncate(255))
344
344
  end
345
345
  end
346
346
 
@@ -353,6 +353,12 @@ module Maestrano::Connector::Rails::Concerns::Entity
353
353
  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}")
354
354
  raise "Not implemented"
355
355
  end
356
+
357
+ # This method is called during the webhook workflow only. It should return the array of filtered entities
358
+ # The aim is to have the same filtering as with the Connec! filters on API calls in the webhooks
359
+ def filter_connec_entities(entities, organization, opts={})
360
+ entities
361
+ end
356
362
  # ----------------------------------------------
357
363
  # General methods
358
364
  # ----------------------------------------------
@@ -2,16 +2,16 @@
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 0.4.3 ruby lib
5
+ # stub: maestrano-connector-rails 0.4.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.4.3"
9
+ s.version = "0.4.4"
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
13
  s.authors = ["Pierre Berard"]
14
- s.date = "2016-05-04"
14
+ s.date = "2016-05-11"
15
15
  s.description = "Maestrano is the next generation marketplace for SME applications. See https://maestrano.com for details."
16
16
  s.email = "pierre.berard@maestrano.com"
17
17
  s.executables = ["rails"]
data/realse_notes.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.3
2
+
3
+ ### Fixes
4
+ * Add `forced` option in home_controller when requesting a manual synchronization.
5
+
6
+
1
7
  ## 0.4.2
2
8
  /!\ This release contains a new migration that you'll need to fetch and run
3
9
 
@@ -71,6 +71,7 @@ describe Maestrano::ConnecController, type: :controller do
71
71
 
72
72
  it 'process the data and push them' do
73
73
  expect_any_instance_of(Entities::ContactAndLead).to receive(:before_sync)
74
+ expect_any_instance_of(Entities::ContactAndLead).to receive(:filter_connec_entities).and_return({"Lead"=>[entity]})
74
75
  expect_any_instance_of(Entities::ContactAndLead).to receive(:consolidate_and_map_data).with({"Lead"=>[entity]}, {}, organization, {}).and_return({})
75
76
  expect_any_instance_of(Entities::ContactAndLead).to receive(:push_entities_to_external)
76
77
  expect_any_instance_of(Entities::ContactAndLead).to receive(:after_sync)
@@ -138,6 +139,7 @@ describe Maestrano::ConnecController, type: :controller do
138
139
 
139
140
  it 'process the data and push them' do
140
141
  expect_any_instance_of(Entities::Person).to receive(:before_sync)
142
+ expect_any_instance_of(Entities::Person).to receive(:filter_connec_entities).and_return([entity])
141
143
  expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).with([entity], [], organization, {}).and_return({})
142
144
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
143
145
  expect_any_instance_of(Entities::Person).to receive(:after_sync)
Binary file
@@ -21,9 +21,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
21
21
  end
22
22
 
23
23
  describe 'general methods' do
24
+ let(:organization) { create(:organization) }
24
25
 
25
26
  describe 'map_to_external_with_idmap' do
26
- let(:organization) { create(:organization) }
27
27
  let(:id) { '322j-bbfg4' }
28
28
  let(:entity) { {'id' => id, 'name' => 'John', 'updated_at' => 2.day.ago} }
29
29
  let(:mapped_entity) { {'first_name' => 'John'} }
@@ -90,6 +90,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
90
90
  end
91
91
  end
92
92
 
93
+ describe 'filter_connec_entities' do
94
+ it { expect(subject.filter_connec_entities({'lead' => [{a: 2}]}, organization)).to eql({'lead' => [{a: 2}]}) }
95
+ end
93
96
  end
94
97
 
95
98
  describe 'methods with sub complex entities' do
@@ -420,7 +420,8 @@ describe Maestrano::Connector::Rails::Entity do
420
420
  end
421
421
 
422
422
  context 'with errors' do
423
- let(:result400) { {status: 400, body: 'Not Found'} }
423
+ let(:err_msg) { 'Not Found' }
424
+ let(:result400) { {status: 400, body: err_msg} }
424
425
  before {
425
426
  allow(client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [result400, result400]}.to_json, {}))
426
427
  }
@@ -430,6 +431,15 @@ describe Maestrano::Connector::Rails::Entity do
430
431
  idmap2.reload
431
432
  expect(idmap2.message).to eq result400[:body]
432
433
  end
434
+
435
+ context 'with a long error message' do
436
+ let(:err_msg) { 'A very long sentence with a lot of error or more likely a badly designed API that return an html 404 page instead of a nice json answer an then the world is sad and the kitten are unhappy. So juste to be safe we are truncating the error message and I am running out of words to write I hope it is long enough' }
437
+ it 'truncates the error message' do
438
+ subject.push_entities_to_connec_to(client, entities_with_idmaps, '', organization)
439
+ idmap2.reload
440
+ expect(idmap2.message).to eq err_msg.truncate(255)
441
+ end
442
+ end
433
443
  end
434
444
  end
435
445
 
@@ -505,6 +515,10 @@ describe Maestrano::Connector::Rails::Entity do
505
515
  end
506
516
  end
507
517
  end
518
+
519
+ describe 'filter_connec_entities' do
520
+ it { expect(subject.filter_connec_entities([{a: 2}], organization)).to eql([{a: 2}]) }
521
+ end
508
522
  end
509
523
 
510
524
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano-connector-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Berard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maestrano-rails