Class: Rdgem::Companies

Inherits:
Object
  • Object
show all
Defined in:
lib/rdgem/companies.rb

Class Method Summary collapse

Class Method Details

.delete_company(app_key, company_id) ⇒ Object

fow now, just used for testing



44
45
46
47
48
49
50
# File 'lib/rdgem/companies.rb', line 44

def self.delete_company(app_key, company_id)
	
	query = "#{PIPEDRIVE_API}organizations/#{company_id}?#{TOKEN}#{app_key}"
       response = HTTParty.delete(query)
	
       return response["success"]
end

.get_or_create_company(app_key, company) ⇒ Object

queries for a company name. creates when it doesn’t exist.



6
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
32
33
34
35
36
37
38
39
40
41
# File 'lib/rdgem/companies.rb', line 6

def self.get_or_create_company(app_key, company)
	org_app_id = false
	
	query = PIPEDRIVE_API + 'organizations/find?term=' \
           + company + '&start=0&' + TOKEN + app_key
	
       response = HTTParty.get(query)
       #if successfull and with content, get the company app_key
       #so as not to create another with the same name
       if response["success"]
         unless response["data"] == nil
           response["data"].each do |search|
             if search['name'] == company
               org_app_id = search['id']
               #not caring about duplicates. 
               #we will ensure we at least won't create any
               break
             end
           end
         else
           #didn't find, create one
		input_query = PIPEDRIVE_API + 'organizations?' + TOKEN + app_key
	
       	org_response = HTTParty.post(input_query, 
         					:body => {:name =>company},
         					:headers => HEADERS )
	
           unless org_response["data"] == nil
           	org_app_id = org_response["data"]["id"]
           end
         end
       else
         #error getting company
       end
       return org_app_id
end