pipedrive_orbit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec92b13107123c64ba9576466868b6184909f52b79332d8584565697657243ef
4
- data.tar.gz: a8f816318e4b535c22768740494532f7e41f14023ecdd7501ccee1589f2d61b8
3
+ metadata.gz: 0fc7484c4f8d732271cc8b2ca61cbeb0c19e1212458c09cc41df6d54f7c1d28f
4
+ data.tar.gz: 01ca111b2cdf867b646aef2d450ec74e3bf91ea42467ca075331c92ebf483fd9
5
5
  SHA512:
6
- metadata.gz: 8da38dc495c6563cc5dd02c89bdf420f4b822d8e5c3702a16688d6ea7035e4e768c639c706720bf3d107f8909d28636ab003b1901bda76fba837c902912eb0cd
7
- data.tar.gz: eb6b80ecaf24387087119bf2befef04ea66e2e851f6b232714e7e40a5d37ff305baa91b3383ee6ec3ed157ef5eef0b9adc9f738aade492383318299f2e9c834b
6
+ metadata.gz: f055d026ff2c868c262e3ac949b30cbf24eed07089e223fd615abd2a9b0a026ed27d3c28ab030e58af18d2eff0dda9ccf887aaea35716327e6967f5c8e74abe3
7
+ data.tar.gz: 37947a064abaa95681cfcfbbcca58dd853be5db5c0e4b7307e671ff10397e58fb753da45110866bb8039b8f9416ff98e02385fed5f5de821245fd0ca170a3ead
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pipedrive_orbit (0.0.1)
4
+ pipedrive_orbit (0.0.2)
5
5
  activesupport (~> 6.1)
6
6
  dotenv (~> 2.7)
7
7
  http (~> 4.4)
data/README.md CHANGED
@@ -60,13 +60,20 @@ Once, you have an instantiated client, you can fetch Pipedrive deal notes and se
60
60
  ```ruby
61
61
  client.notes
62
62
  ```
63
- ### Fetching Pipedrive Notes
63
+ ### Fetching Pipedrive Activities
64
64
 
65
- Once, you have an instantiated client, you can fetch Pipedrive activities and send them to Orbit by invoking the `#activities` instance method:
65
+ You can fetch Pipedrive activities and send them to Orbit by invoking the `#activities` instance method:
66
66
 
67
67
  ```ruby
68
68
  client.activities
69
69
  ```
70
+ ### Fetching Pipedrive Notes on People
71
+
72
+ You can fetch Pipedrive notes on people and send them to Orbit by invoking the `#people_notes` instance method:
73
+
74
+ ```ruby
75
+ client.people_notes
76
+ ```
70
77
  ## CLI Usage
71
78
 
72
79
  You can also use this package with the included CLI. To use the CLI pass in the required environment variables on the command line before invoking the CLI.
@@ -83,6 +90,12 @@ To check for new activities:
83
90
  $ ORBIT_API_KEY=... ORBIT_WORKSPACE_ID=... PIPEDRIVE_API_KEY=... PIPEDRIVE_URL=... bundle exec pipedrive_orbit --check_activities
84
91
  ```
85
92
 
93
+ To check for new notes on people:
94
+
95
+ ```bash
96
+ $ ORBIT_API_KEY=... ORBIT_WORKSPACE_ID=... PIPEDRIVE_API_KEY=... PIPEDRIVE_URL=... bundle exec pipedrive_orbit --check_people_notes
97
+ ```
98
+
86
99
  ## GitHub Actions Automation Setup
87
100
 
88
101
  ⚡ You can set up this integration in a matter of minutes using our GitHub Actions template. It will run regularly to add new activities to your Orbit workspace. All you need is a GitHub account.
data/bin/pipedrive_orbit CHANGED
@@ -4,6 +4,7 @@ require 'optparse'
4
4
 
5
5
  check_notes = false
6
6
  check_activities = false
7
+ check_people_notes = false
7
8
 
8
9
  options = {}
9
10
  choices = OptionParser.new do |opts|
@@ -18,6 +19,9 @@ choices = OptionParser.new do |opts|
18
19
  opts.on("--check-check_activities", "Check for new Pipedrive activities") do
19
20
  check_activities = true
20
21
  end
22
+ opts.on("--check-people-notes", "Check for new Pipedrive notes on people") do
23
+ check_people_notes = true
24
+ end
21
25
  end.parse!
22
26
 
23
27
  $LOAD_PATH.unshift(File.expand_path('../lib/pipedrive_orbit', __dir__))
@@ -35,4 +39,10 @@ if check_activities
35
39
  puts "Checking for new Pipedrive activities and posting them to your Orbit workspace..."
36
40
  ARGV[0] = 'render'
37
41
  PipedriveOrbit::Scripts::CheckActivities.start(ARGV)
42
+ end
43
+
44
+ if check_people_notes
45
+ puts "Checking for new Pipedrive people notes and posting them to your Orbit workspace..."
46
+ ARGV[0] = 'render'
47
+ PipedriveOrbit::Scripts::CheckPeopleNotes.start(ARGV)
38
48
  end
@@ -56,5 +56,14 @@ module PipedriveOrbit
56
56
  orbit_workspace: @orbit_workspace
57
57
  ).process_activities
58
58
  end
59
+
60
+ def people_notes
61
+ PipedriveOrbit::Pipedrive.new(
62
+ pipedrive_api_key: @pipedrive_api_key,
63
+ pipedrive_url: @pipedrive_url,
64
+ orbit_api_key: @orbit_api_key,
65
+ orbit_workspace: @orbit_workspace
66
+ ).process_people_notes
67
+ end
59
68
  end
60
69
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module PipedriveOrbit
6
+ module Interactions
7
+ class PersonNote
8
+ def initialize(note:, pipedrive_url:, orbit_workspace:, orbit_api_key:)
9
+ @note = note
10
+ @pipedrive_url = pipedrive_url
11
+ @orbit_workspace = orbit_workspace
12
+ @orbit_api_key = orbit_api_key
13
+
14
+ after_initialize!
15
+ end
16
+
17
+ def after_initialize!
18
+ OrbitActivities::Request.new(
19
+ api_key: @orbit_api_key,
20
+ workspace_id: @orbit_workspace,
21
+ user_agent: "community-ruby-pipedrive-orbit/#{PipedriveOrbit::VERSION}",
22
+ body: construct_body.to_json
23
+ )
24
+ end
25
+
26
+ def construct_url
27
+ return nil if @note["deal_id"].nil?
28
+
29
+ if @pipedrive_url.end_with?("/")
30
+ return "#{pipedrive_url}deal/#{@note["deal_id"]}"
31
+ end
32
+
33
+ "#{@pipedrive_url}/deal/#{@note["deal_id"]}"
34
+ end
35
+
36
+ def construct_name
37
+ return @note["person"]["name"] if @note["person"]
38
+
39
+ @note["organization"]["name"]
40
+ end
41
+
42
+ def construct_body
43
+ hash = {
44
+ activity: {
45
+ activity_type: "pipedrive:person_note",
46
+ tags: ["channel:pipedrive"],
47
+ title: "Added Note to Person in Pipedrive",
48
+ description: construct_description,
49
+ occurred_at: @note["add_time"],
50
+ key: @note["id"],
51
+ member: {
52
+ name: construct_name
53
+ }
54
+ },
55
+ identity: {
56
+ source: "pipedrive",
57
+ name: construct_name
58
+ }
59
+ }
60
+
61
+ hash[:activity].merge!(link: construct_url) unless construct_url.nil? || construct_url == ""
62
+ hash[:activity][:member].merge!(company: @note["organization"]["name"]) if @note["organization"]
63
+
64
+ hash
65
+ end
66
+
67
+ def construct_description
68
+ note = @note["content"].dup
69
+
70
+ note.prepend("Note added for person in connection to #{@note["deal"]["title"]}:<br>") unless @note["deal"] == nil
71
+
72
+ note
73
+ end
74
+ end
75
+ end
76
+ end
@@ -20,6 +20,15 @@ module PipedriveOrbit
20
20
  orbit_api_key: orbit_api_key
21
21
  )
22
22
  end
23
+
24
+ if type == "person_note"
25
+ PipedriveOrbit::Interactions::PersonNote.new(
26
+ note: data[:note],
27
+ pipedrive_url: data[:pipedrive_url],
28
+ orbit_workspace: orbit_workspace,
29
+ orbit_api_key: orbit_api_key
30
+ )
31
+ end
23
32
  end
24
33
  end
25
34
  end
@@ -49,6 +49,60 @@ module PipedriveOrbit
49
49
  end
50
50
  end
51
51
 
52
+ def process_people_notes
53
+ people = get_people
54
+
55
+ return people["error"] if people["success"] == false
56
+ return "No people found!" if people.nil?
57
+
58
+ people["data"].each do |person|
59
+ next if person["notes_count"] <= 0 || person["notes_count"].nil?
60
+
61
+ notes = get_people_notes(person)
62
+
63
+ return notes["error"] if notes["success"] == false
64
+ return "No notes found!" if notes.nil?
65
+
66
+ notes["data"].each do |note|
67
+ PipedriveOrbit::Orbit.call(
68
+ type: "person_note",
69
+ data: {
70
+ note: note,
71
+ pipedrive_url: @pipedrive_url
72
+ },
73
+ orbit_workspace: @orbit_workspace,
74
+ orbit_api_key: @orbit_api_key
75
+ )
76
+ end
77
+ end
78
+ end
79
+
80
+ def get_people
81
+ url = URI("https://api.pipedrive.com/v1/persons")
82
+ url.query = "api_token=#{@pipedrive_api_key}"
83
+ https = Net::HTTP.new(url.host, url.port)
84
+ https.use_ssl = true
85
+
86
+ request = Net::HTTP::Get.new(url)
87
+
88
+ response = https.request(request)
89
+
90
+ response = JSON.parse(response.body)
91
+ end
92
+
93
+ def get_people_notes(person)
94
+ url = URI("https://api.pipedrive.com/v1/notes")
95
+ url.query = "person_id=#{person["id"]}&sort=add_time DESC&api_token=#{@pipedrive_api_key}"
96
+ https = Net::HTTP.new(url.host, url.port)
97
+ https.use_ssl = true
98
+
99
+ request = Net::HTTP::Get.new(url)
100
+
101
+ response = https.request(request)
102
+
103
+ response = JSON.parse(response.body)
104
+ end
105
+
52
106
  def get_activities
53
107
  url = URI("https://api.pipedrive.com/v1/activities")
54
108
  url.query = "user_id=0&start_date=#{create_start_date}&end_date=#{create_end_date}&api_token=#{@pipedrive_api_key}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal = true
2
2
 
3
3
  module PipedriveOrbit
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pipedrive_orbit"
5
+ require "thor"
6
+
7
+ module PipedriveOrbit
8
+ module Scripts
9
+ class CheckPeopleNotes < Thor
10
+ desc "render", "check for new Pipedrive people notes and push them to Orbit"
11
+ def render
12
+ client = PipedriveOrbit::Client.new
13
+ client.people_notes
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedrive_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orbit DevRel
@@ -159,6 +159,7 @@ files:
159
159
  - lib/pipedrive_orbit/client.rb
160
160
  - lib/pipedrive_orbit/interactions/activity.rb
161
161
  - lib/pipedrive_orbit/interactions/note.rb
162
+ - lib/pipedrive_orbit/interactions/person_note.rb
162
163
  - lib/pipedrive_orbit/orbit.rb
163
164
  - lib/pipedrive_orbit/pipedrive.rb
164
165
  - lib/pipedrive_orbit/version.rb
@@ -166,6 +167,7 @@ files:
166
167
  - readme-images/ways-to-use.png
167
168
  - scripts/check_activities.rb
168
169
  - scripts/check_notes.rb
170
+ - scripts/check_people_notes.rb
169
171
  homepage: https://github.com/orbit-love/community-ruby-pipedrive-orbit
170
172
  licenses:
171
173
  - MIT