pipedrive_orbit 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9335362bf049c2d9a22d9178b44a47ebae8dcbb78f8d2758a053dd65311cb4da
4
- data.tar.gz: 61058eee3d43a573e3e64d9728b2fc7f5210a20fe2ee8500c3dda7c52614001e
3
+ metadata.gz: ec92b13107123c64ba9576466868b6184909f52b79332d8584565697657243ef
4
+ data.tar.gz: a8f816318e4b535c22768740494532f7e41f14023ecdd7501ccee1589f2d61b8
5
5
  SHA512:
6
- metadata.gz: 3e8e428d5c715b2b25228dc003d67da8230ea36897096d8d0013d71feb7bcb3088aaf1620807effeb5192b5ff6fec4fec0c6aa7dee7c9607954394277782fdc7
7
- data.tar.gz: 436ae33f3d8b8bef78136cc9ecf5bdc53a01ac87e2c45392f62085a36ea7b52d703379c83a6d52c07d7a96c5500b93ea8104fc82ab93878965d4c37cfc0e6f3c
6
+ metadata.gz: 8da38dc495c6563cc5dd02c89bdf420f4b822d8e5c3702a16688d6ea7035e4e768c639c706720bf3d107f8909d28636ab003b1901bda76fba837c902912eb0cd
7
+ data.tar.gz: eb6b80ecaf24387087119bf2befef04ea66e2e851f6b232714e7e40a5d37ff305baa91b3383ee6ec3ed157ef5eef0b9adc9f738aade492383318299f2e9c834b
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  pipedrive_orbit (0.0.1)
5
+ activesupport (~> 6.1)
5
6
  dotenv (~> 2.7)
6
7
  http (~> 4.4)
7
8
  json (~> 2.5)
@@ -12,10 +13,17 @@ PATH
12
13
  GEM
13
14
  remote: https://rubygems.org/
14
15
  specs:
16
+ activesupport (6.1.3.2)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
15
22
  addressable (2.7.0)
16
23
  public_suffix (>= 2.0.2, < 5.0)
17
24
  ast (2.4.2)
18
25
  byebug (11.1.3)
26
+ concurrent-ruby (1.1.8)
19
27
  crack (0.4.5)
20
28
  rexml
21
29
  diff-lcs (1.4.4)
@@ -37,7 +45,10 @@ GEM
37
45
  http-form_data (2.3.0)
38
46
  http-parser (1.2.3)
39
47
  ffi-compiler (>= 1.0, < 2.0)
48
+ i18n (1.8.10)
49
+ concurrent-ruby (~> 1.0)
40
50
  json (2.5.1)
51
+ minitest (5.14.4)
41
52
  orbit_activities (0.0.2)
42
53
  http (~> 4.4)
43
54
  json (~> 2.5)
@@ -77,6 +88,8 @@ GEM
77
88
  parser (>= 3.0.1.1)
78
89
  ruby-progressbar (1.11.0)
79
90
  thor (1.1.0)
91
+ tzinfo (2.0.4)
92
+ concurrent-ruby (~> 1.0)
80
93
  unf (0.1.4)
81
94
  unf_ext
82
95
  unf_ext (0.0.7.7)
data/README.md CHANGED
@@ -60,13 +60,29 @@ 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
64
+
65
+ Once, you have an instantiated client, you can fetch Pipedrive activities and send them to Orbit by invoking the `#activities` instance method:
66
+
67
+ ```ruby
68
+ client.activities
69
+ ```
63
70
  ## CLI Usage
64
71
 
65
- 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:
72
+ 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.
73
+
74
+ To check for new deal notes:
66
75
 
67
76
  ```bash
68
77
  $ ORBIT_API_KEY=... ORBIT_WORKSPACE_ID=... PIPEDRIVE_API_KEY=... PIPEDRIVE_URL=... bundle exec pipedrive_orbit --check_notes
69
78
  ```
79
+
80
+ To check for new activities:
81
+
82
+ ```bash
83
+ $ ORBIT_API_KEY=... ORBIT_WORKSPACE_ID=... PIPEDRIVE_API_KEY=... PIPEDRIVE_URL=... bundle exec pipedrive_orbit --check_activities
84
+ ```
85
+
70
86
  ## GitHub Actions Automation Setup
71
87
 
72
88
  ⚡ 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
@@ -3,6 +3,7 @@
3
3
  require 'optparse'
4
4
 
5
5
  check_notes = false
6
+ check_activities = false
6
7
 
7
8
  options = {}
8
9
  choices = OptionParser.new do |opts|
@@ -14,6 +15,9 @@ choices = OptionParser.new do |opts|
14
15
  opts.on("--check-notes", "Check for new Pipedrive deal notes") do
15
16
  check_notes = true
16
17
  end
18
+ opts.on("--check-check_activities", "Check for new Pipedrive activities") do
19
+ check_activities = true
20
+ end
17
21
  end.parse!
18
22
 
19
23
  $LOAD_PATH.unshift(File.expand_path('../lib/pipedrive_orbit', __dir__))
@@ -25,4 +29,10 @@ if check_notes
25
29
  puts "Checking for new Pipedrive deal notes and posting them to your Orbit workspace..."
26
30
  ARGV[0] = 'render'
27
31
  PipedriveOrbit::Scripts::CheckNotes.start(ARGV)
32
+ end
33
+
34
+ if check_activities
35
+ puts "Checking for new Pipedrive activities and posting them to your Orbit workspace..."
36
+ ARGV[0] = 'render'
37
+ PipedriveOrbit::Scripts::CheckActivities.start(ARGV)
28
38
  end
@@ -47,5 +47,14 @@ module PipedriveOrbit
47
47
  orbit_workspace: @orbit_workspace
48
48
  ).process_notes
49
49
  end
50
+
51
+ def activities
52
+ PipedriveOrbit::Pipedrive.new(
53
+ pipedrive_api_key: @pipedrive_api_key,
54
+ pipedrive_url: @pipedrive_url,
55
+ orbit_api_key: @orbit_api_key,
56
+ orbit_workspace: @orbit_workspace
57
+ ).process_activities
58
+ end
50
59
  end
51
60
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module PipedriveOrbit
6
+ module Interactions
7
+ class Activity
8
+ def initialize(activity:, pipedrive_url:, orbit_workspace:, orbit_api_key:)
9
+ @activity = activity
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_member
27
+ hash = { name: @activity["person_name"] } unless @activity["person_name"].nil?
28
+
29
+ return hash unless hash.nil?
30
+
31
+ if !@activity["attendees"].nil?
32
+ hash = { email: @activity["attendees"][0]["email_address"] }
33
+ end
34
+
35
+ hash
36
+ end
37
+
38
+ def construct_body
39
+ hash = {
40
+ activity: {
41
+ activity_type: "pipedrive:activity",
42
+ tags: ["channel:pipedrive"],
43
+ title: "Added New #{@activity["type"].capitalize} Activity to Pipedrive",
44
+ description: construct_description,
45
+ occurred_at: @activity["add_time"],
46
+ key: @activity["id"],
47
+ member: {}
48
+ },
49
+ identity: {
50
+ source: "pipedrive"
51
+ }
52
+ }
53
+
54
+ hash[:activity][:member].merge!(construct_member)
55
+ hash[:activity][:member].merge!(company: @activity["org_name"]) unless @activity["org_name"].nil?
56
+ hash[:identity].merge!(construct_member)
57
+
58
+ hash
59
+ end
60
+
61
+ def construct_description
62
+ if @activity["note"]
63
+ return @activity["note"]
64
+ end
65
+
66
+ "#{@activity["subject"]} was added by #{@activity["owner_name"]}"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -11,6 +11,15 @@ module PipedriveOrbit
11
11
  orbit_api_key: orbit_api_key
12
12
  )
13
13
  end
14
+
15
+ if type == "activity"
16
+ PipedriveOrbit::Interactions::Activity.new(
17
+ activity: data[:activity],
18
+ pipedrive_url: data[:pipedrive_url],
19
+ orbit_workspace: orbit_workspace,
20
+ orbit_api_key: orbit_api_key
21
+ )
22
+ end
14
23
  end
15
24
  end
16
25
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/time"
4
+
3
5
  module PipedriveOrbit
4
6
  class Pipedrive
5
7
  def initialize(params = {})
@@ -26,6 +28,56 @@ module PipedriveOrbit
26
28
  end
27
29
  end
28
30
 
31
+ def process_activities
32
+ activities = get_activities
33
+
34
+ return get_activities["error"] if get_activities["success"] == false
35
+ return "No new activities in the past day!" if activities.nil?
36
+
37
+ activities["data"].each do |activity|
38
+ next if no_member_info(activity)
39
+
40
+ PipedriveOrbit::Orbit.call(
41
+ type: "activity",
42
+ data: {
43
+ activity: activity,
44
+ pipedrive_url: @pipedrive_url
45
+ },
46
+ orbit_workspace: @orbit_workspace,
47
+ orbit_api_key: @orbit_api_key
48
+ )
49
+ end
50
+ end
51
+
52
+ def get_activities
53
+ url = URI("https://api.pipedrive.com/v1/activities")
54
+ url.query = "user_id=0&start_date=#{create_start_date}&end_date=#{create_end_date}&api_token=#{@pipedrive_api_key}"
55
+ https = Net::HTTP.new(url.host, url.port)
56
+ https.use_ssl = true
57
+
58
+ request = Net::HTTP::Get.new(url)
59
+
60
+ response = https.request(request)
61
+
62
+ response = JSON.parse(response.body)
63
+ end
64
+
65
+ def no_member_info(activity)
66
+ return true if activity["person_name"].nil? && activity["attendees"].nil?
67
+
68
+ false
69
+ end
70
+
71
+ def create_start_date
72
+ date = Date.parse(Time.now.utc.to_date.to_s)-1.day
73
+ date.strftime("%Y-%m-%d")
74
+ end
75
+
76
+ def create_end_date
77
+ date = Date.parse(Time.now.utc.to_date.to_s)
78
+ date.strftime("%Y-%m-%d")
79
+ end
80
+
29
81
  def get_notes
30
82
  url = URI("https://api.pipedrive.com/v1/notes")
31
83
  url.query = "sort=add_time DESC&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.1"
4
+ VERSION = "0.0.2"
5
5
  end
@@ -25,7 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = "bin"
26
26
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
-
28
+
29
+ spec.add_dependency "activesupport", "~> 6.1"
29
30
  spec.add_dependency "http", "~> 4.4"
30
31
  spec.add_dependency "json", "~> 2.5"
31
32
  spec.add_dependency "zeitwerk", "~> 2.4"
@@ -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 CheckActivities < Thor
10
+ desc "render", "check for new Pipedrive activities and push them to Orbit"
11
+ def render
12
+ client = PipedriveOrbit::Client.new
13
+ client.activities
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orbit DevRel
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-18 00:00:00.000000000 Z
12
+ date: 2021-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '6.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '6.1'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: http
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -143,12 +157,14 @@ files:
143
157
  - bin/pipedrive_orbit
144
158
  - lib/pipedrive_orbit.rb
145
159
  - lib/pipedrive_orbit/client.rb
160
+ - lib/pipedrive_orbit/interactions/activity.rb
146
161
  - lib/pipedrive_orbit/interactions/note.rb
147
162
  - lib/pipedrive_orbit/orbit.rb
148
163
  - lib/pipedrive_orbit/pipedrive.rb
149
164
  - lib/pipedrive_orbit/version.rb
150
165
  - pipedrive_orbit.gemspec
151
166
  - readme-images/ways-to-use.png
167
+ - scripts/check_activities.rb
152
168
  - scripts/check_notes.rb
153
169
  homepage: https://github.com/orbit-love/community-ruby-pipedrive-orbit
154
170
  licenses: