require 'highrise' class LeadsController < ApplicationController before_action :set_lead, only: [:show, :edit, :update, :destroy] # GET /leads def index @leads = Lead.all end # GET /leads/1 def show end # GET /leads/new def new @lead = Lead.new end # GET /leads/1/edit def edit end # POST /leads def create @lead = Lead.new(lead_params) if @lead.save redirect_to @lead, notice: 'Lead was successfully created.' else render :new end end # PATCH/PUT /leads/1 def update if @lead.update(lead_params) redirect_to @lead, notice: 'Lead was successfully updated.' else render :edit end end # DELETE /leads/1 def destroy @lead.destroy redirect_to leads_url, notice: 'Lead was successfully destroyed.' end def to_highrise if current_user.highrise_site != nil or current_user.highrise_user != nil @lead = Lead.find(params[:id]) Highrise::Base.site = current_user.highrise_site Highrise::Base.user = current_user.highrise_user Highrise::Base.format = :xml p = Highrise::Person.new( first_name: @lead[:name], last_name: @lead[:last_name], title: @lead[:job_title], company_name: @lead[:company], contact_data: { email_addresses: [ { address: @lead[:emial], location: 'Work'} ], phone: @lead[:phone], website: @lead[:website] }) #p = Highrise::Person.new(first_name: @lead[:name], contact_data: { email_addresses: [ { address: 'test@example.com', location: 'Work' } ] }) #p.save if p.save redirect_to root_path, notice: 'this contact was sent to the highrise successfully' else redirect_to root_path, notice: 'Error.' end else redirect_to root_path, notice: 'Please add your highrise configs.' end end private # Use callbacks to share common setup or constraints between actions. def set_lead @lead = Lead.find(params[:id]) end # Only allow a trusted parameter "white list" through. def lead_params params.require(:lead).permit(:name, :last_name, :email, :company, :job_title, :phone, :website) end end