maybe_fetch.rb 669 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Freshdesk::Contact::MaybeFetch < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Freshdesk::Requester
  4. uses :resource
  5. optional :contact_id
  6. # Fetch contact only, when it's not already present.
  7. def process
  8. return if contact_id.blank?
  9. resource.merge!(fetch_contact)
  10. end
  11. private
  12. def fetch_contact
  13. response = request(
  14. api_path: "contacts/#{contact_id}",
  15. )
  16. JSON.parse(response.body)
  17. rescue => e
  18. logger.error "Error when fetching contact data for contact #{contact_id}"
  19. logger.error e
  20. {}
  21. end
  22. end