class PipedriveOrbit::Pipedrive
Public Class Methods
new(params = {})
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 7 def initialize(params = {}) @orbit_api_key = params.fetch(:orbit_api_key) @orbit_workspace = params.fetch(:orbit_workspace) @pipedrive_api_key = params.fetch(:pipedrive_api_key) @pipedrive_url = params.fetch(:pipedrive_url) end
Public Instance Methods
create_end_date()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 130 def create_end_date date = Date.parse(Time.now.utc.to_date.to_s) date.strftime("%Y-%m-%d") end
create_start_date()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 125 def create_start_date date = Date.parse(Time.now.utc.to_date.to_s)-1.day date.strftime("%Y-%m-%d") end
get_activities()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 106 def get_activities url = URI("https://api.pipedrive.com/v1/activities") url.query = "user_id=0&start_date=#{create_start_date}&end_date=#{create_end_date}&api_token=#{@pipedrive_api_key}" https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) response = JSON.parse(response.body) end
get_notes()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 135 def get_notes url = URI("https://api.pipedrive.com/v1/notes") url.query = "sort=add_time DESC&api_token=#{@pipedrive_api_key}" https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) response = JSON.parse(response.body) end
get_people()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 80 def get_people url = URI("https://api.pipedrive.com/v1/persons") url.query = "api_token=#{@pipedrive_api_key}" https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) response = JSON.parse(response.body) end
get_people_notes(person)
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 93 def get_people_notes(person) url = URI("https://api.pipedrive.com/v1/notes") url.query = "person_id=#{person["id"]}&sort=add_time DESC&api_token=#{@pipedrive_api_key}" https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) response = JSON.parse(response.body) end
no_member_info(activity)
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 119 def no_member_info(activity) return true if activity["person_name"].nil? && activity["attendees"].nil? false end
process_activities()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 31 def process_activities activities = get_activities return get_activities["error"] if get_activities["success"] == false return "No new activities in the past day!" if activities.nil? activities["data"].each do |activity| next if no_member_info(activity) PipedriveOrbit::Orbit.call( type: "activity", data: { activity: activity, pipedrive_url: @pipedrive_url }, orbit_workspace: @orbit_workspace, orbit_api_key: @orbit_api_key ) end end
process_notes()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 14 def process_notes notes = get_notes notes["data"].each do |note| next if note["person"] == nil || note["organization"] == nil PipedriveOrbit::Orbit.call( type: "note", data: { note: note, pipedrive_url: @pipedrive_url }, orbit_workspace: @orbit_workspace, orbit_api_key: @orbit_api_key ) end end
process_people_notes()
click to toggle source
# File lib/pipedrive_orbit/pipedrive.rb, line 52 def process_people_notes people = get_people return people["error"] if people["success"] == false return "No people found!" if people.nil? people["data"].each do |person| next if person["notes_count"] <= 0 || person["notes_count"].nil? notes = get_people_notes(person) return notes["error"] if notes["success"] == false return "No notes found!" if notes.nil? notes["data"].each do |note| PipedriveOrbit::Orbit.call( type: "person_note", data: { note: note, pipedrive_url: @pipedrive_url }, orbit_workspace: @orbit_workspace, orbit_api_key: @orbit_api_key ) end end end