def export(types, from = nil, block_until_completed = false, locale = nil)
      data = {type: [types].flatten.join(',')}
      data[:from] = from unless from.blank?
      data[:locale] = locale unless locale.blank?
      response = post('/export', data)
      if response.valid?
        if response.raw.code.to_s == '204'
          @logger.info { "No changed records for '#{data[:type]}' since #{data[:from]}." }
          return response
        end
        @logger.info { "Export for '#{data[:type]}' successfully queued with token '#{response[:token]}'." }
      end

      if block_until_completed
        raise ::Itrp::UploadFailed.new("Failed to queue '#{data[:type]}' export. #{response.message}") unless response.valid?
        token = response[:token]
        while true
          response = get("/export/#{token}")
          unless response.valid?
            sleep(5)
            response = get("/export/#{token}") # single retry to recover from a network error
            raise ::Itrp::Exception.new("Unable to monitor progress for '#{data[:type]}' export. #{response.message}") unless response.valid?
          end
          # wait 30 seconds while the response is OK and export is still busy
          break unless ['queued', 'processing'].include?(response[:state])
          @logger.debug { "Export of '#{data[:type]}' is #{response[:state]}. Checking again in 30 seconds." }
          sleep(30)
        end
      end

      response
    end
def export(types, from = nil, block_until_completed = false, locale = nil)
      data = {type: [types].flatten.join(',')}
      data[:from] = from unless from.blank?
      data[:locale] = locale unless locale.blank?
      response = post('/export', data)
      if response.valid?
        if response.raw.code.to_s == '204'
          @logger.info { "No changed records for '#{data[:type]}' since #{data[:from]}." }
          return response
        end
        @logger.info { "Export for '#{data[:type]}' successfully queued with token '#{response[:token]}'." }
      end

      if block_until_completed
        raise ::Itrp::UploadFailed.new("Failed to queue '#{data[:type]}' export. #{response.message}") unless response.valid?
        token = response[:token]
        while true
          response = get("/export/#{token}")
          unless response.valid?
            sleep(5)
            response = get("/export/#{token}") # single retry to recover from a network error
            raise ::Itrp::Exception.new("Unable to monitor progress for '#{data[:type]}' export. #{response.message}") unless response.valid?
          end
          # wait 30 seconds while the response is OK and export is still busy
          break unless ['queued', 'processing'].include?(response[:state])
          @logger.debug { "Export of '#{data[:type]}' is #{response[:state]}. Checking again in 30 seconds." }
          sleep(30)
        end
      end

      response
    end
Export CSV files
 @param types: The types to export, e.g. person, organization, people_contact_details
 @param from: Retrieve all files since a given data and time
 @param block_until_completed: Set to true to monitor the export progress
 @param locale: Required for translations export
 @raise Itrp::Exception in case the export progress could not be monitored