From 789e9c988e2fc3c8eda04a6675048ac26f447eea Mon Sep 17 00:00:00 2001 From: Sai Kumar Kotagiri Date: Wed, 8 Jan 2025 11:16:12 -0500 Subject: [PATCH] adds logging to all the connections made to Sugar CRM --- app/domain/sugar_crm/services/connection.rb | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/domain/sugar_crm/services/connection.rb b/app/domain/sugar_crm/services/connection.rb index 68330b49..7220d968 100644 --- a/app/domain/sugar_crm/services/connection.rb +++ b/app/domain/sugar_crm/services/connection.rb @@ -47,6 +47,7 @@ def find_account_by_hbx_id(hbx_id) def find_contact_by_hbx_id(hbx_id) response = get('/rest/v11_8/Contacts', params: { filter: [{ hbxid_c: hbx_id }] }) + Rails.logger.info "Connected to SugarCRM - find_contact_by_hbx_id - to get contact with HBX ID: #{hbx_id}" if response.parsed['records'].empty? false else @@ -60,6 +61,7 @@ def create_account(payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + Rails.logger.info "Connected to SugarCRM with LEGACY - create_account - to create account" response.parsed end @@ -69,6 +71,9 @@ def create_contact(payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + + Rails.logger.info "Connected to SugarCRM with LEGACY - create_contact - to create contact" + response.parsed end @@ -79,6 +84,9 @@ def update_account(id:, payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + + Rails.logger.info "Connected to SugarCRM with LEGACY - update_account - to update account with ID: #{id}" + response.parsed end @@ -88,6 +96,9 @@ def update_contact(id:, payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + + Rails.logger.info "Connected to SugarCRM with LEGACY - update_contact - to update contact with ID: #{id}" + response.parsed end @@ -97,6 +108,9 @@ def create_contact_for_account(payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + + Rails.logger.info "Connected to SugarCRM with LEGACY - create_contact_for_account - to create contact" + response.parsed end @@ -108,6 +122,9 @@ def update_contact_by_hbx_id(hbx_id:, payload:) body: payload.to_json, headers: { "Content-Type" => "application/json" } ) + + Rails.logger.info "Connected to SugarCRM with LEGACY - update_contact_by_hbx_id - to update contact with HBX ID: #{hbx_id}" + response.parsed end @@ -115,6 +132,7 @@ def update_contact_by_hbx_id(hbx_id:, payload:) # @param account_id [String] the ID of the account for which to fetch contacts # @return [Array] an array of hashes, each representing a contact associated with the account def fetch_contacts_by_account_id(account_id) + Rails.logger.info "Connected to SugarCRM - fetch_contacts_by_account_id - to get contacts for account with ID: #{account_id}" get( '/rest/v11_8/Contacts', params: { filter: [{ account_id: account_id }] } @@ -126,6 +144,7 @@ def fetch_contacts_by_account_id(account_id) # @return [Hash, nil] a hash representing the account if found, or nil if no accounts match the HBX ID def fetch_account_by_hbx_id(hbx_id) response = get('/rest/v11_8/Accounts', params: { filter: [{ hbxid_c: hbx_id }] }) + Rails.logger.info "Connected to SugarCRM - fetch_account_by_hbx_id - to get account with HBX ID: #{hbx_id}" return if response.parsed['records'].empty? response.parsed['records'].first @@ -146,6 +165,7 @@ def fetch_account_including_contacts_by_hbx_id(hbx_id) # @param payload [Hash] The data to be sent as the body of the request. # @return [Hash] Raw response from the API after creating the account. def create_an_account(payload:) + Rails.logger.info "Connected to SugarCRM - create_an_account - to create account" post( '/rest/v11_8/Accounts', body: payload.to_json, @@ -158,6 +178,7 @@ def create_an_account(payload:) # @param payload [Hash] The data to be sent as the body of the request. # @return [Hash] Raw response from the API after updating the account. def update_the_account(id:, payload:) + Rails.logger.info "Connected to SugarCRM - update_the_account - to update account with ID: #{id}" put( "/rest/v11_8/Accounts/#{id}", body: payload.to_json, @@ -169,6 +190,7 @@ def update_the_account(id:, payload:) # @param payload [Hash] The data to be sent as the body of the request. # @return [Hash] Raw response from the API after creating the contact. def create_a_contact(payload:) + Rails.logger.info "Connected to SugarCRM - create_a_contact - to create contact" post( '/rest/v11_8/Contacts', body: payload.to_json, @@ -181,6 +203,7 @@ def create_a_contact(payload:) # @param payload [Hash] The data to be sent as the body of the request. # @return [Hash] Raw response from the API after updating the contact. def update_the_contact(id:, payload:) + Rails.logger.info "Connected to SugarCRM - update_the_contact - to update contact with ID: #{id}" put( "/rest/v11_8/Contacts/#{id}", body: payload.to_json,