zendesk.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. require 'base64'
  2. require 'zendesk_api'
  3. module Import
  4. end
  5. module Import::Zendesk
  6. extend Import::Helper
  7. extend Import::Zendesk::Async
  8. extend Import::Zendesk::ImportStats
  9. # rubocop:disable Style/ModuleFunction
  10. extend self
  11. def start
  12. log 'Start import...'
  13. checks
  14. Import::Zendesk::GroupFactory.import(client.groups)
  15. Import::Zendesk::OrganizationFieldFactory.import(client.organization_fields)
  16. Import::Zendesk::OrganizationFactory.import(client.organizations)
  17. Import::Zendesk::UserFieldFactory.import(client.user_fields)
  18. Import::Zendesk::UserFactory.import(client.users)
  19. Import::Zendesk::TicketFieldFactory.import(client.ticket_fields)
  20. Import::Zendesk::TicketFactory.import(all_tickets)
  21. # TODO
  22. Setting.set( 'system_init_done', true )
  23. Setting.set( 'import_mode', false )
  24. true
  25. end
  26. def connection_test
  27. Import::Zendesk::Requester.connection_test
  28. end
  29. private
  30. # this special ticket logic is needed since Zendesk archives tickets
  31. # after 120 days and doesn't return them via the client.tickets
  32. # endpoint as described here:
  33. # https://github.com/zammad/zammad/issues/558#issuecomment-267951351
  34. # the proper way is to use the 'incremental' endpoint which is not available
  35. # via the ruby gem yet but a pull request is pending:
  36. # https://github.com/zendesk/zendesk_api_client_rb/pull/287
  37. # the following workaround is needed to use this functionality
  38. def all_tickets
  39. ZendeskAPI::Collection.new(
  40. client,
  41. ZendeskAPI::Ticket,
  42. path: 'incremental/tickets?start_time=1'
  43. )
  44. end
  45. def client
  46. Import::Zendesk::Requester.client
  47. end
  48. def checks
  49. check_import_mode
  50. check_system_init_done
  51. connection_test
  52. end
  53. end