Class: PipedriveOrbit::Interactions::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/pipedrive_orbit/interactions/activity.rb

Instance Method Summary collapse

Constructor Details

#initialize(activity:, pipedrive_url:, orbit_workspace:, orbit_api_key:) ⇒ Activity

Returns a new instance of Activity.



8
9
10
11
12
13
14
15
# File 'lib/pipedrive_orbit/interactions/activity.rb', line 8

def initialize(activity:, pipedrive_url:, orbit_workspace:, orbit_api_key:)
  @activity = activity
  @pipedrive_url = pipedrive_url
  @orbit_workspace = orbit_workspace
  @orbit_api_key = orbit_api_key

  after_initialize!
end

Instance Method Details

#after_initialize!Object



17
18
19
20
21
22
23
24
# File 'lib/pipedrive_orbit/interactions/activity.rb', line 17

def after_initialize!
  OrbitActivities::Request.new(
      api_key: @orbit_api_key,
      workspace_id: @orbit_workspace,
      user_agent: "community-ruby-pipedrive-orbit/#{PipedriveOrbit::VERSION}",
      body: construct_body.to_json
  )
end

#construct_bodyObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pipedrive_orbit/interactions/activity.rb', line 38

def construct_body
  hash = {
    activity: {
      activity_type: "pipedrive:activity",
      tags: ["channel:pipedrive"],
      title: "Added New #{@activity["type"].capitalize} Activity to Pipedrive",
      description: construct_description,
      occurred_at: @activity["add_time"],
      key: @activity["id"],
      member: {}
    },
    identity: {
      source: "pipedrive"
    }
  }

  hash[:activity][:member].merge!(construct_member)
  hash[:activity][:member].merge!(company: @activity["org_name"]) unless @activity["org_name"].nil?
  hash[:identity].merge!(construct_member)

  hash
end

#construct_descriptionObject



61
62
63
64
65
66
67
# File 'lib/pipedrive_orbit/interactions/activity.rb', line 61

def construct_description
  if @activity["note"]
      return @activity["note"]
  end
  
  "#{@activity["subject"]} was added by #{@activity["owner_name"]}"
end

#construct_memberObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pipedrive_orbit/interactions/activity.rb', line 26

def construct_member
  hash = { name: @activity["person_name"] } unless @activity["person_name"].nil?
  
  return hash unless hash.nil?
  
  if !@activity["attendees"].nil?
      hash = { email: @activity["attendees"][0]["email_address"] }
  end

  hash
end