zendesk.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. connection_test
  51. end
  52. end