clearbit_enrichment.rb 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Transaction::ClearbitEnrichment
  3. =begin
  4. {
  5. object: 'User',
  6. type: 'create',
  7. object_id: 123,
  8. changes: {
  9. 'attribute1' => [before, now],
  10. 'attribute2' => [before, now],
  11. },
  12. created_at: Time.zone.now,
  13. user_id: 123,
  14. },
  15. =end
  16. def initialize(item, params = {})
  17. @item = item
  18. @params = params
  19. end
  20. def perform
  21. # return if we run import mode
  22. return if Setting.get('import_mode')
  23. return if @item[:object] != 'User'
  24. return if @item[:type] != 'create'
  25. return if !Setting.get('clearbit_integration')
  26. config = Setting.get('clearbit_config')
  27. return if !config
  28. return if config['api_key'].blank?
  29. user = User.lookup(id: @item[:object_id])
  30. return if !user
  31. user_enrichment = Enrichment::Clearbit::User.new(user)
  32. return if !user_enrichment.synced?
  33. Observer::Transaction.commit
  34. true
  35. end
  36. end