Class: PipedriveOrbit::Pipedrive
- Inherits:
-
Object
- Object
- PipedriveOrbit::Pipedrive
- Defined in:
- lib/pipedrive_orbit/pipedrive.rb
Instance Method Summary collapse
- #create_end_date ⇒ Object
- #create_start_date ⇒ Object
- #get_activities ⇒ Object
- #get_notes ⇒ Object
- #get_people ⇒ Object
- #get_people_notes(person) ⇒ Object
-
#initialize(params = {}) ⇒ Pipedrive
constructor
A new instance of Pipedrive.
- #no_member_info(activity) ⇒ Object
- #process_activities ⇒ Object
- #process_notes ⇒ Object
- #process_people_notes ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Pipedrive
Returns a new instance of Pipedrive.
7 8 9 10 11 12 |
# 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 |
Instance Method Details
#create_end_date ⇒ Object
130 131 132 133 |
# 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 ⇒ Object
125 126 127 128 |
# 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 ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# 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 ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# 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 ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# 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) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# 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) ⇒ Object
119 120 121 122 123 |
# 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 ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 |