-
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 #3 from orbit-love/activities
Add Activities Check
- Loading branch information
Showing
11 changed files
with
250 additions
and
3 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,70 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module PipedriveOrbit | ||
module Interactions | ||
class Activity | ||
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 | ||
|
||
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_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 | ||
|
||
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 | ||
|
||
def construct_description | ||
if @activity["note"] | ||
return @activity["note"] | ||
end | ||
|
||
"#{@activity["subject"]} was added by #{@activity["owner_name"]}" | ||
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.1" | ||
VERSION = "0.0.2" | ||
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
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 CheckActivities < Thor | ||
desc "render", "check for new Pipedrive activities and push them to Orbit" | ||
def render | ||
client = PipedriveOrbit::Client.new | ||
client.activities | ||
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
|
||
RSpec.describe PipedriveOrbit::Interactions::Activity do | ||
let(:subject) do | ||
PipedriveOrbit::Interactions::Activity.new( | ||
activity: { | ||
"id" => "82", | ||
"user_id" => "12301519", | ||
"deal_id" => "1234", | ||
"person_id" => "123", | ||
"org_id" => "444", | ||
"type" => "email", | ||
"person_name" => "Testing Person", | ||
"add_time" => "2021-05-18 05:11:52", | ||
"note" => "Testing note" | ||
}, | ||
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 Activity 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:activity\",\"tags\":[\"channel:pipedrive\"],\"title\":\"Added New Email Activity to Pipedrive\",\"description\":\"Testing note\",\"occurred_at\":\"2021-05-18 05:11:52\",\"key\":\"82\",\"member\":{\"name\":\"Testing Person\"}},\"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 |