Module: Rdgem
- Defined in:
- lib/rdgem.rb,
lib/rdgem/version.rb
Constant Summary collapse
- PIPEDRIVE_API =
Your code goes here…
"https://api.pipedrive.com/v1/"- TOKEN =
"api_token="- HEADERS =
{'Accept'=>'application/json', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby.Pipedrive.Api' }
- VERSION =
"0.1.18"
Class Method Summary collapse
-
.add_field_to_user(app_key, field_name) ⇒ Object
adds a new field to the owner app_key’s account.
-
.assert_fields(fields, app_key) ⇒ Object
checks in the account if the custom fields are created.
-
.create_field(app_key, field_name) ⇒ Object
checks if the key is valid and if the custom fields are created in the acc if any field is missing, create it even if populated the field key will always be replaced.
-
.get_or_create_company(app_key, company) ⇒ Object
queries for a company name.
-
.send_lead(app_key, lead_to_person) ⇒ Object
pushes the lead to pipedrive.
Class Method Details
.add_field_to_user(app_key, field_name) ⇒ Object
adds a new field to the owner app_key’s account
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rdgem.rb', line 57 def self.add_field_to_user(app_key, field_name) field_api_key = false input_query = PIPEDRIVE_API + 'personFields?' + TOKEN + app_key response = HTTParty.post(input_query, :body => {:name =>"#{field_name}", :field_type => "varchar"}, :headers => HEADERS ) unless response["data"] == nil field_api_id = response["data"]["id"] key_query = PIPEDRIVE_API + 'personFields/'\ + field_api_id.to_s + "?" + TOKEN + app_key field_key_response = HTTParty.get(key_query) unless field_key_response["data"] == nil field_api_key = field_key_response["data"]["key"] end end return field_api_key end |
.assert_fields(fields, app_key) ⇒ Object
checks in the account if the custom fields are created.
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 111 112 113 114 115 |
# File 'lib/rdgem.rb', line 82 def self.assert_fields(fields, app_key) @field_key = [] query = PIPEDRIVE_API + 'personFields?' + TOKEN + app_key response = HTTParty.get(query) if response["success"] fields.each_with_index do |assert, index| response["data"].each do |search| if search['name'] == assert @field_key[index] = search['key'] end end end #Hash the info custom_field = Hash[fields.zip(@field_key.map \ {|i| i.include?(',') ? (i.split /, /) : i})] #/ puts "custom_field",custom_field #integrate missing fields custom_field.each do |create| puts "creating",create[1] if create[1].blank? create[1] = create_field(app_key, create[0]) end end else if response["error"] == "You need to be authorized to make this request." return response["error"] end end return @field_key end |
.create_field(app_key, field_name) ⇒ Object
checks if the key is valid and if the custom fields are created in the acc if any field is missing, create it even if populated the field key will always be replaced
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rdgem.rb', line 124 def self.create_field(app_key, field_name) field_api_key = false input_query = PIPEDRIVE_API + 'personFields?' + TOKEN + app_key response = HTTParty.post(input_query, :body => {:name =>"#{field_name}", :field_type => "varchar"}, :headers => HEADERS ) unless response["data"] == nil field_api_id = response["data"]["id"] key_query = PIPEDRIVE_API + 'personFields/'\ + field_api_id.to_s + "?" + TOKEN + app_key field_key_response = HTTParty.get(key_query) unless field_key_response["data"] == nil field_api_key = field_key_response["data"]["key"] end end return field_api_key end |
.get_or_create_company(app_key, company) ⇒ Object
queries for a company name. creates when it doesn’t exist.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rdgem.rb', line 21 def self.get_or_create_company(app_key, company) org_app_id = "" 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 |
.send_lead(app_key, lead_to_person) ⇒ Object
pushes the lead to pipedrive
15 16 17 18 |
# File 'lib/rdgem.rb', line 15 def self.send_lead(app_key, lead_to_person) query = PIPEDRIVE_API + 'persons?' + TOKEN + app_key response = HTTParty.post(query, :body => lead_to_person, :headers => HEADERS) end |