Skip to content

Commit

Permalink
👍 last commit of the challenge; just a simple fix and improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes committed Aug 17, 2013
1 parent 71ff5ac commit 4cf3dc3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,22 @@ email | string | email | array
company | string | org_id | number
job_title | string | job_title | Person Field - varchar
phone | string | phone | array
website | string | website | Person Field - varchar
website | string | website | Person Field - varchar


### Pipedrive

#### Setup
Basically for Pipedrive integration work the user have to setup his Pipedrive key first. Without the Pipedrive key the application will just ignore the integration.

When the user setups the Pipedrive key, the application will store his key for all the next requests to Pipedrive API. Also will create at the first setup custom fields (job_title and website), because they doesn't exist in Pipedrive by default. These custom fields have keys which must be passed with the request when creating a person. So we store it in the database for future requests.

#### Integration
If the user has setted up his Pipedrive key, then integration will run every time he create a new Person.

The integration will follow these basic steps bellow:

1. Create a organization in Pipedrive if company field is not blank in person data.
2. Get hash keys of job_title and website custom fields.
3. Join person name and last name, because there is only name field in Pipedrive.
4. Create the person with custom fields and organization association in Pipedrive.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

helper_method :current_user
helper_method :current_user, :current_pipedrive_key

protected

Expand Down
1 change: 1 addition & 0 deletions app/controllers/pipedrive_configs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def app_key
def destroy
@pipedrive_config = PipedriveConfig.where(user_id: current_user.id, key: PipedriveConfig::KEYS[:app_key]).first
@pipedrive_config.destroy
session[:pipedrive_key] = nil
respond_to do |format|
format.html { redirect_to pipedrive_configs_url, notice: 'Pipedrive was successfully disabled.' }
format.json { head :no_content }
Expand Down
4 changes: 2 additions & 2 deletions app/models/pipedrive_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def self.generate_custom_field(user, app_key, label_name, field_key)
end

def self.import_person_to_pipedrive(person, app_key)
org = create_organization(person, app_key)
org_id = person.company.blank? ? "" : create_organization(person, app_key).value
job_field_key = where(key: KEYS[:custom_field_job], user_id: person.user_id).first.value
website_field_key = where(key: KEYS[:custom_field_website], user_id: person.user_id).first.value

person_to_import = {
name: "#{person.name} #{person.last_name}",
org_id: org.value,
org_id: org_id,
email: [person.email],
phone: [person.phone],
job_field_key => person.job_title,
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<%= link_to "Sign up", sign_up_path %> or
<%= link_to "log in", log_in_path %>
<% end %>
<% if current_pipedrive_key %>
<span class="label label-success pull-right">Pipedrive actived</span>
<% else %>
<span class="label label-important pull-right">Pipedrive deactiated</span>
<% end %>
</div>

<div id="content">
Expand Down

0 comments on commit 4cf3dc3

Please sign in to comment.