From 47aa454895791a3eca4676e24116d8c5fc839ac7 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 28 Jul 2016 08:57:28 -0400 Subject: [PATCH 1/2] Webhook --- app/models/customer.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/models/customer.rb b/app/models/customer.rb index 365a841..dbbddd8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -140,6 +140,26 @@ class Customer < ActiveRecord::Base end end + # proforms a bruteforce sync operation + # This needs to be simplified + def self.sync(id) + service = Qbo.get_base(:customer).service + + customer = service.find_by_id(id) + qbo_customer = Customer.find_or_create_by(id: customer.id) + if customer.active? + if not qbo_customer.name.eql? customer.display_name + qbo_customer.name = customer.display_name + qbo_customer.id = customer.id + qbo_customer.save_without_push + end + else + if not qbo_customer.new_record? + qbo_customer.delete + end + end + end + # Push the updates def save_with_push begin From 37d0b2321f768b9244b142d8ed43df2428382dc8 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 28 Jul 2016 08:59:43 -0400 Subject: [PATCH 2/2] Webhook --- app/controllers/qbo_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 18a0ee5..18f8d28 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -75,8 +75,9 @@ class QboController < ApplicationController entities = data['eventNotifications'][0]['dataChangeEvent']['entities'] entities.each do |entity| - puts entity['name'] - puts entity['id'] + if entity['name'].eql? "Customer" + Customer.sync(entity['id'].to_i) + end end # The webhook doesn't require a response but let's make sure