Class: ForestLiana::IntercomAttributesGetter

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/intercom_attributes_getter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ IntercomAttributesGetter

Returns a new instance of IntercomAttributesGetter.



5
6
7
8
9
10
# File 'app/services/forest_liana/intercom_attributes_getter.rb', line 5

def initialize(params)
  @params = params
  @intercom = ::Intercom::Client.new(
    app_id: ForestLiana.integrations[:intercom][:app_id],
    api_key: ForestLiana.integrations[:intercom][:api_key])
end

Instance Attribute Details

#recordsObject

Returns the value of attribute records.



3
4
5
# File 'app/services/forest_liana/intercom_attributes_getter.rb', line 3

def records
  @records
end

Instance Method Details

#countObject



12
13
14
# File 'app/services/forest_liana/intercom_attributes_getter.rb', line 12

def count
  @records.count
end

#performObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/forest_liana/intercom_attributes_getter.rb', line 16

def perform
  begin
    resource = collection.find(@params[:id])
    user = @intercom.users.find(email: resource.email)

    user.segments = user.segments.map do |segment|
      @intercom.segments.find(id: segment.id)
    end

    @records = user
  rescue Intercom::ResourceNotFound
  end
end