Class: ForestLiana::IntercomConversationsGetter
- Inherits:
-
IntegrationBaseGetter
- Object
- IntegrationBaseGetter
- ForestLiana::IntercomConversationsGetter
- Defined in:
- app/services/forest_liana/intercom_conversations_getter.rb
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(params) ⇒ IntercomConversationsGetter
constructor
A new instance of IntercomConversationsGetter.
- #perform ⇒ Object
- #records ⇒ Object
Constructor Details
#initialize(params) ⇒ IntercomConversationsGetter
Returns a new instance of IntercomConversationsGetter.
3 4 5 6 7 |
# File 'app/services/forest_liana/intercom_conversations_getter.rb', line 3 def initialize(params) @params = params @access_token = ForestLiana.integrations[:intercom][:access_token] @intercom = ::Intercom::Client.new(token: @access_token) end |
Instance Method Details
#count ⇒ Object
9 10 11 |
# File 'app/services/forest_liana/intercom_conversations_getter.rb', line 9 def count @records.count end |
#perform ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/forest_liana/intercom_conversations_getter.rb', line 23 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.}" @records = [] end end |
#records ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/services/forest_liana/intercom_conversations_getter.rb', line 13 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 |