Class: PipedrivePUT::Persons
- Inherits:
-
Object
- Object
- PipedrivePUT::Persons
- Includes:
- PipedrivePUT
- Defined in:
- lib/PipedrivePUT/persons.rb
Overview
Operations from the Persons API
Constant Summary
Constants included from PipedrivePUT
Instance Attribute Summary
Attributes included from PipedrivePUT
Class Method Summary collapse
-
.addPerson(name, options = {}) ⇒ Object
Add an Person.
-
.deletePerson(id) ⇒ Object
Delete a person from Pipedrive.
-
.detailsOfPerson(id) ⇒ Object
Gets details of a signle person with id being passed in at params.
-
.getAllPersons ⇒ Object
Gets all persons in pipedrive.
-
.searchForPerson(term, options = {}) ⇒ Object
term - Search term to look for optional parameters: org_id - ID of the organization person is associated with.
-
.updatePerson(id, options = {}) ⇒ Object
Update a Person.
Methods included from PipedrivePUT
Class Method Details
.addPerson(name, options = {}) ⇒ Object
Add an Person
41 42 43 44 45 46 47 48 49 |
# File 'lib/PipedrivePUT/persons.rb', line 41 def self.addPerson(name, = {}) url = "https://api.pipedrive.com/v1/persons?api_token=#{@@key.to_s}" HTTParty.post( url, body: .merge(name: name).to_json, headers: {'Content-type' => 'application/json'} ) end |
.deletePerson(id) ⇒ Object
Delete a person from Pipedrive
52 53 54 55 |
# File 'lib/PipedrivePUT/persons.rb', line 52 def self.deletePerson(id) url = "https://api.pipedrive.com/v1/persons/#{id}?api_token=#{@@key}" HTTParty.delete(url) end |
.detailsOfPerson(id) ⇒ Object
Gets details of a signle person with id being passed in at params.
34 35 36 37 38 |
# File 'lib/PipedrivePUT/persons.rb', line 34 def self.detailsOfPerson(id) url = "https://api.pipedrive.com/v1/persons/#{id}&api_token=#{@@key.to_s}" content = open(url).read JSON.parse(content) end |
.getAllPersons ⇒ Object
Gets all persons in pipedrive
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/PipedrivePUT/persons.rb', line 7 def self.getAllPersons @start = 0 table = Array.new @more_items = true tablesize = 0 while @more_items == true do count = 0 @base = 'https://api.pipedrive.com/v1/persons?start=' + @start.to_s + '&limit=500&api_token=' + @@key.to_s @content = open(@base.to_s).read @parsed = JSON.parse(@content) while count < @parsed["data"].size table[tablesize] = @parsed["data"][count] count = count +1 tablesize = tablesize + 1 end @pagination = @parsed['additional_data']['pagination'] @more_items = @pagination['more_items_in_collection'] @start = @pagination['next_start'] end return table end |
.searchForPerson(term, options = {}) ⇒ Object
term - Search term to look for optional parameters: org_id - ID of the organization person is associated with. start - Pagination start limit - Items shown per page search_by_email (boolean) - when enabled, term will only be matched against email addresses of people. Default: false
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/PipedrivePUT/persons.rb', line 77 def self.searchForPerson(term, = {}) table = [] more_items = true tablesize = 0 params = {} # optional search parameters params[:term] = term if term && !term.empty? params[:start] = .fetch(:start, 0) params[:org_id] = .fetch(:org_id, nil) if params[:org_id] params[:limit] = .fetch(:limit, 500) params[:search_by_email] = .fetch(:search_by_email, 0) params[:api_token] = @@key.to_s url = "https://api.pipedrive.com/v1/persons/find?#{URI.encode_www_form(params)}" while more_items == true count = 0 parsed = HTTParty.get(url) return table if parsed['data'].nil? while count < parsed['data'].size table[tablesize] = parsed['data'][count] count += 1 tablesize += 1 end pagination = parsed['additional_data']['pagination'] more_items = pagination['more_items_in_collection'] params[:start] = pagination['next_start'] end table end |
.updatePerson(id, options = {}) ⇒ Object
Update a Person
59 60 61 62 63 64 65 66 67 |
# File 'lib/PipedrivePUT/persons.rb', line 59 def self.updatePerson(id, = {}) url = "https://api.pipedrive.com/v1/persons/#{id}?api_token=#{@@key}" HTTParty.put( url, body: .merge(id: id).to_json, headers: {'Content-type' => 'application/json'} ) end |