-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from orbit-love/user-notes
Check notes on people
- Loading branch information
Showing
10 changed files
with
247 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module PipedriveOrbit | ||
module Interactions | ||
class PersonNote | ||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
def construct_name | ||
return @note["person"]["name"] if @note["person"] | ||
|
||
@note["organization"]["name"] | ||
end | ||
|
||
def construct_body | ||
hash = { | ||
activity: { | ||
activity_type: "pipedrive:person_note", | ||
tags: ["channel:pipedrive"], | ||
title: "Added Note to Person in 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 | ||
|
||
def construct_description | ||
note = @note["content"].dup | ||
|
||
note.prepend("Note added for person in connection to #{@note["deal"]["title"]}:<br>") unless @note["deal"] == nil | ||
|
||
note | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal = true | ||
|
||
module PipedriveOrbit | ||
VERSION = "0.0.2" | ||
VERSION = "0.0.3" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "pipedrive_orbit" | ||
require "thor" | ||
|
||
module PipedriveOrbit | ||
module Scripts | ||
class CheckPeopleNotes < Thor | ||
desc "render", "check for new Pipedrive people notes and push them to Orbit" | ||
def render | ||
client = PipedriveOrbit::Client.new | ||
client.people_notes | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
|
||
RSpec.describe PipedriveOrbit::Interactions::PersonNote do | ||
let(:subject) do | ||
PipedriveOrbit::Interactions::PersonNote.new( | ||
note: { | ||
"id" => "82", | ||
"user_id" => "12301519", | ||
"deal_id" => "1234", | ||
"person_id" => "123", | ||
"org_id" => "444", | ||
"content" => "Test note", | ||
"add_time" => "2021-05-18 05:11:52", | ||
"organization" => { | ||
"name" => "Testing Org" | ||
}, | ||
"person" => { | ||
"name" => "Testing Person" | ||
}, | ||
"deal" => { | ||
"title" => "Testing Deal" | ||
} | ||
}, | ||
pipedrive_url: "https://example.com", | ||
orbit_workspace: "1234", | ||
orbit_api_key: "12345", | ||
|
||
) | ||
end | ||
|
||
describe "#call" do | ||
context "when the type is a note" do | ||
it "returns a Note Object" do | ||
stub_request(:post, "https://app.orbit.love/api/v1/1234/activities") | ||
.with( | ||
headers: { 'Authorization' => "Bearer 12345", 'Content-Type' => 'application/json', 'User-Agent'=>"community-ruby-pipedrive-orbit/#{PipedriveOrbit::VERSION}" }, | ||
body: "{\"activity\":{\"activity_type\":\"pipedrive:person_note\",\"tags\":[\"channel:pipedrive\"],\"title\":\"Added Note to Person in Pipedrive\",\"description\":\"Note added for person in connection to Testing Deal:<br>Test note\",\"occurred_at\":\"2021-05-18 05:11:52\",\"key\":\"82\",\"member\":{\"name\":\"Testing Person\",\"company\":\"Testing Org\"},\"link\":\"https://example.com/deal/1234\"},\"identity\":{\"source\":\"pipedrive\",\"name\":\"Testing Person\"}}" | ||
) | ||
.to_return( | ||
status: 200, | ||
body: { | ||
response: { | ||
code: 'SUCCESS' | ||
} | ||
}.to_json.to_s | ||
) | ||
|
||
content = subject.construct_body | ||
|
||
expect(content[:activity][:key]).to eql("82") | ||
end | ||
end | ||
end | ||
end |