Skip to content

Commit

Permalink
adds logging to all the connections made to Sugar CRM
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumar9 committed Jan 8, 2025
1 parent 2cb45f4 commit 789e9c9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/domain/sugar_crm/services/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -108,13 +122,17 @@ 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

# Fetches contacts associated with a given account ID from an external service.
# @param account_id [String] the ID of the account for which to fetch contacts
# @return [Array<Hash>] 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 }] }
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 789e9c9

Please sign in to comment.