Class: PipedriveOrbit::Interactions::Note

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

Instance Method Summary collapse

Constructor Details

#initialize(note:, pipedrive_url:, orbit_workspace:, orbit_api_key:) ⇒ Note

Returns a new instance of Note.



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

def initialize(note:, pipedrive_url:, orbit_workspace:, orbit_api_key:)
  @note = note
  @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/note.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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pipedrive_orbit/interactions/note.rb', line 42

def construct_body
  hash = {
    activity: {
      activity_type: "pipedrive:note",
      tags: ["channel:pipedrive"],
      title: "Added Note to Pipedrive",
      description: construct_description,
      occurred_at: @note["add_time"],
      key: @note["id"],
      member: {
        name: construct_name
      }
    },
    identity: {
      source: "pipedrive",
      name: construct_name
    }
  }

  hash[:activity].merge!(link: construct_url) unless construct_url.nil? || construct_url == "" 
  hash[:activity][:member].merge!(company: @note["organization"]["name"]) if @note["organization"]

  hash
end

#construct_descriptionObject



67
68
69
70
71
72
73
# File 'lib/pipedrive_orbit/interactions/note.rb', line 67

def construct_description
  note = @note["content"].dup

  note.prepend("Note added for deal - #{@note["deal"]["title"]}:<br>") unless @note["deal"] == nil

  note
end

#construct_nameObject



36
37
38
39
40
# File 'lib/pipedrive_orbit/interactions/note.rb', line 36

def construct_name
  return @note["person"]["name"] if @note["person"]

  @note["organization"]["name"]
end

#construct_urlObject



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

def construct_url
  return nil if @note["deal_id"].nil?

  if @pipedrive_url.end_with?("/")
      return "#{pipedrive_url}deal/#{@note["deal_id"]}"
  end

  "#{@pipedrive_url}/deal/#{@note["deal_id"]}"
end