Class: PipedrivePUT::Persons

Inherits:
Object
  • Object
show all
Includes:
PipedrivePUT
Defined in:
lib/PipedrivePUT/persons.rb

Overview

Operations from the Persons API

Constant Summary

Constants included from PipedrivePUT

VERSION

Instance Attribute Summary

Attributes included from PipedrivePUT

#key

Class Method Summary collapse

Methods included from PipedrivePUT

getKey, key

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, options = {})
	url = "https://api.pipedrive.com/v1/persons?api_token=#{@@key.to_s}"

	HTTParty.post(
      url,
      body: options.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

.getAllPersonsObject

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, options = {})
  table = []
  more_items = true

  tablesize = 0
  params = {}

  # optional search parameters
  params[:term]            = term if term && !term.empty?
  params[:start]           = options.fetch(:start, 0)
  params[:org_id]          = options.fetch(:org_id, nil) if params[:org_id]
  params[:limit]           = options.fetch(:limit, 500)
  params[:search_by_email] = options.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, options = {})
    url = "https://api.pipedrive.com/v1/persons/#{id}?api_token=#{@@key}"

	HTTParty.put(
      url,
      body: options.merge(id: id).to_json,
      headers: {'Content-type' => 'application/json'}
    )
end