Sha256: e3a41ff4e3b79c90b99b9aefbe0a4fed1ff628eaa96edad112164524d8844f69
Contents?: true
Size: 1.4 KB
Versions: 109
Compression:
Stored size: 1.4 KB
Contents
module ForestLiana class IntercomConversationsGetter < IntegrationBaseGetter def initialize(params) @params = params @access_token = ForestLiana.integrations[:intercom][:access_token] @intercom = ::Intercom::Client.new(token: @access_token) end def count @records.count end def records @records[pagination].map do |conversation| if conversation.assignee.is_a?(::Intercom::Admin) admins = @intercom.admins.all.detect(id: conversation.assignee.id) conversation.assignee = admins.first end conversation end end def perform begin resource = collection.find(@params[:id]) @records = @intercom.conversations.find_all( email: resource.email, type: 'user', display_as: 'plaintext', ).entries rescue Intercom::ResourceNotFound @records = [] rescue Intercom::UnexpectedError => exception FOREST_REPORTER.report exception FOREST_LOGGER.error "Cannot retrieve the Intercom conversations: #{exception.message}" @records = [] end end private def pagination offset..(offset + limit - 1) end def offset return 0 unless pagination? number = @params[:page][:number] if number && number.to_i > 0 (number.to_i - 1) * limit else 0 end end end end
Version data entries
109 entries across 109 versions & 1 rubygems